示例#1
0
def checkNewG(newG, g):
    localMaxima = bruteForceLocalMaxCut(g).findLocalMinima()
    verifier = Verifier(newG)
    for partition in localMaxima:
        result, nodeSet = verifier.partitionCheck(partition)
        if result == False:
            return False
    return True
    def findLocalMinima(self):
        n = self.g.order()
        verifier = Verifier(self.g)
        localMaxList = []

        pset = powerset(n)
        print(powerset)

        for subset in pset:
            result, nodeSet = verifier.partitionCheck(list(subset))
            if result == True:
                localMaxList.append(subset)
        return(localMaxList) #return list of subsets that are local max
示例#3
0
class Voter():
    __v_server = Verifier()
    __c_server = Counter()

    def cast_vote(self, vote):
        yes, no = self.__v_server.genrate_vote()

        print("User input {0}").format(vote)
        if vote == 1:
            self.__c_server.add_vote(yes, 1, self.__v_server)
        elif vote == 0:
            self.__c_server.add_vote(no, 0, self.__v_server)
        else:
            print "Invalid Input"
示例#4
0
class Master:
    io = IO()
    combinator = Combinator()
    verifier = Verifier()

    bs = None
    interesting = None
    interactive = None
    query = os.getcwd().replace("\\", "/")+"/tmp/TWES.q"    # Todo: make this adjustable

    def open_file(self, file):
        success, self.bs, self.interesting = self.io.open_file(file)
        if success:
            self.interactive = self.retrieve_interactive()
        else:
            self.interactive = None
        return success

    def close_file(self):
        self.io.close_file()

    def get_parameters(self):
        return self.interesting

    def retrieve_interactive(self):
        interactive = []
        for interest in self.interesting:
            interactive.append(interest)
        return interactive

    def get_interactive(self):
        return self.interactive

    def get_bs(self):
        return self.bs

    def add_sweep(self, i, begin, end, step):
        self.combinator.add_sweep(i, begin, end, step)

    def execute(self):
        result = {}
        combinations = self.combinator.get_combinations()
        # print(combinations)
        file = None
        for comb in combinations:
            # print('interactive = ' + str(self.interactive))
            i, val = comb[0], comb[1]
            param = self.interactive[i]
            # print('interesting[param] = ' + self.interesting[param])
            print('val = ' + str(val))
            # print('index = ' + str(i))
            # print('param = ' + param)
            if self.interesting[param] == 'declaration':
                changer = param[:].split('=')
                changer[-1] = "= " + str(val)
                changer = ''.join(changer)
                # print('changer = ' + changer)
                file = self.io.create_combination(param, changer)
            with open(self.query, 'r') as f:
                print(f.read())
            mean = self.verifier.verify(file, self.query)
            result[str(val)] = mean
        return result

    def get_sweeps(self):
        return self.combinator.get_sweeps()

    def simulate(self, query):
        print('simulating!!')
        result = {}
        combinations = self.combinator.get_combinations()
        # print(combinations)
        file = None
        for comb in combinations:
            # print('interactive = ' + str(self.interactive))
            i, val = comb[0], comb[1]
            param = self.interactive[i]
            # print('interesting[param] = ' + self.interesting[param])
            print('val = ' + str(val))
            # print('index = ' + str(i))
            # print('param = ' + param)
            if self.interesting[param] == 'declaration':
                changer = param[:].split('=')
                changer[-1] = "= " + str(val)
                changer = ''.join(changer)
                # print('changer = ' + changer)
                file = self.io.create_combination(param, changer)
            # with open(self.query, 'r') as f:
            #     print(f.read())

            # q = 'simulate %s [<=50] {%s}' % (str(amount), query)   #Todo: Fix hardcode final time
            res = self.verifier.simulate(file, query)
            # print('\n\n')
            # print(res)
            # print('\n')
            # print(val)
            result[val] = res
        return result
示例#5
0
blockchain = blockchain.Blockchain()  # the blockchain used in this test

# create a test record for a patient
patient_test_vc = [
    "Administration Date: MAY-01-2021 10:00 AM", "Patient ID: 10132",
    "Patient Name: John Doe", "Patient Address: 10 Example St. NE",
    "Administered by: Dr. Jill Fakeington"
]
# additional info is non-personally identifying info stored with transaction
additional_data = ["Vaccine Type: Pfizer", "Vaccine ID: 1234"]

# create the provider
provider = Provider.Provider(provider_key)
# create the patient
patient = Patient.Patient(patient_key)
# create the third party verifier
verifier = Verifier.Verifier(verifier_key, blockchain)
# generate patient vaccine card
provider.generate_card(patient_test_vc)
# provider posts the transaction to the blockchain
provider.post_transaction(blockchain, patient_key.public_key(),
                          additional_data)
# a new block is created
blockchain.new_block()
# provider sends encrypted vaccine care to the patient
provider.send_patient_info(patient)
# Patient sends encrypted record to the verifier to prove his vaccination
patient.send_records(verifier, verifier.get_pub_key())
# verifier verifies the record is in the blockchain
verifier.verify_record(blockchain)