示例#1
0
    def __init__(self, num_attr, true_weights, connect_sock):
        '''
        Send the initial set of 20 samples to M along with scores.
        This method also gets one guess from M and passes it along to P.

        num_attr - The number of attributes of candidates.
        true_weights - The true weights from the person.
        connect_sock - socket used for incoming connections.
        '''
        self.num_attr = num_attr
        self.time_taken = 0

        self.true_weights = true_weights

        self.connect_sock = connect_sock

        info_print('Waiting for Matchmaker (M) to connect')

        self.data_sock, _ = self.connect_sock.accept()

        info_print('Sent number of attributes to M')
        self.data_sock.sendall('%03d\n' % num_attr)

        # Msg sent to M, start clocking them
        start_time = time.time()

        info_print('Sending initial sample to M')
        self.send_initial_sample_set()
        self.weight_guess = self.recv_weights()

        move_print('Received weight guess %r' % self.weight_guess)
        t = time.time()
        self.time_taken += t - start_time
        self.report_time()
示例#2
0
    def send_score_and_get_candidate(self, score):
        msg = '%+1.4f\n' % score
        self.data_sock.sendall(msg)
        move_print('Mathmacker got score %f' % score)
        start_time = time.time()

        self.weight_guess = self.recv_weights()
        move_print('Received weight guess %r' % self.weight_guess)
        t = time.time()
        self.time_taken += t - start_time
        self.report_time()
示例#3
0
    def send_guess_and_get_update(self, weight_guess):
        info_print('Sending Ms guess to P')
        self.data_sock.send(floats_to_msg4(weight_guess))

        # Latest guess is sent. Time the Person to update weights
        start_time = time.time()
        weights = self.recv_weights()
        t = time.time()
        self.time_taken += t - start_time

        delta_wegiths = weights - self.initial_weights
        percent_change = np.abs(delta_wegiths / self.initial_weights)

        if np.any(percent_change > 0.2):
            self.error('Perecentage change cannot be more than 20%')
            self.loose()

        self.weights = weights
        move_print('P updated weights to %r' % self.weights)
        self.report_time()
示例#4
0
    def __init__(self, num_attr, connect_sock):
        """ Initilize Person (P).

        num_attr - The number of attributes of candidates.
        port - port on which to accept connections.
        connect_sock - socket used for incoming connections.
        """

        self.time_taken = 0
        self.num_attr = num_attr

        self.connect_sock = connect_sock

        info_print('Waiting for Person (P) to connect')

        self.data_sock, _ = self.connect_sock.accept()

        info_print('Sent number of attributes to P')
        self.data_sock.sendall('%03d\n' % num_attr)

        # Sent the msg to Person, start clocking them.
        start_time = time.time()

        self.initial_weights = self.recv_weights()
        self.weights = self.initial_weights
        move_print('Inital Weights by P: %r' % self.initial_weights)

        self.ideal_candidate = self.recv_candidate()
        self.anti_ideal_candidate = self.recv_candidate()

        # Person replied, stop clocking them.
        self.time_taken += time.time() - start_time

        self.check_weight_and_candidates()
        move_print('Ideal Candidate %r' % self.ideal_candidate)
        move_print('Anti-Ideal Candidate %r' % self.anti_ideal_candidate)
        self.report_time()
示例#5
0
 def win(self):
     move_print('Matchmacker Wins!')
     exit(0)