Exemple #1
0
    def update_strategy_3(self):
        """
        update_strategy implementation 3:
         - Updates assuming re-negotatiation will all collaborators
         - Takes into account the request made during the round
         - Uses the ask at the time of collaboration, rather than the
           current strategy of the collaborator
        """
        max_payoff = -1
        for strategy in self.strategy_set:
            payoffs = []
            collaborations_to_consider = self.collaborations.copy()
            if self.last_collaboration_attempt:
                collaborations_to_consider.add(self.last_collaboration_attempt)
            for c in collaborations_to_consider:
                them = c.collaborator_for(self)
                their_ask = c.ask_from(them)
                my_ask = self._ask_for(them, strategy)
                payoffs.append(credit_game.get_payoffs(my_ask, their_ask)[0])

            payoffs = sorted(payoffs, reverse=True)[:MAX_COLLABORATORS]

            payoff = sum(payoffs)
            if payoff > max_payoff:
                max_payoff = payoff
                self.cur_strategy = strategy
Exemple #2
0
    def update_strategy_4(self):
        """
        update_strategy implementation 4:
         - Ignores "renegotiation" with current collaborators
         - Takes into account the request made during the round
         - Uses the ask at the time of collaboration, rather than the
           current strategy of the collaborator
        """
        if not self.last_collaboration_attempt: return
        c = self.last_collaboration_attempt

        them = c.collaborator_for(self)
        their_ask, their_min = c.ask_from(them), c.min_for(them)

        max_payoff = -1
        strategies_by_payoff = {}
        #print('-')
        #print(self.group)
        #print(self._collab_str(self.last_collaboration_attempt))
        #print(self.cur_strategy)
        #print(",".join([ self._collab_str(c) for c in self.collaborations ]))
        for strategy in self.strategy_set:
            my_ask = self._ask_for(them, strategy)
            payoff, their_payoff = credit_game.get_payoffs(my_ask, their_ask)
            if their_payoff < their_min: continue
            if payoff not in strategies_by_payoff: strategies_by_payoff[payoff] = []
            strategies_by_payoff[payoff].append(strategy)
            max_payoff = max(max_payoff, payoff)

        best_options = strategies_by_payoff[max_payoff] if max_payoff > -1 else []
        not_better_than_worst = self.minimum_payoff_acceptable() > max_payoff
        if self.cur_strategy in best_options or max_payoff == 0 or not_better_than_worst:
            #print(self.cur_strategy)
            return
        random.shuffle(best_options)

        # If possible, pick one that is similar to the current strategy in some
        # way
        for strategy in best_options:
            if self.cur_strategy.same_group_ask == strategy.same_group_ask or \
                    self.cur_strategy.diff_group_ask == strategy.diff_group_ask:
                self.cur_strategy = strategy
                #print(strategy)
                return
        # Else, pick a random one
        raise ValueError('shouldnt happen with no allies')
        self.cur_strategy = random.sample(best_options, 1)[0]
Exemple #3
0
 def update_strategy_2(self):
     """
     update_strategy implementation 2:
      - Updates assuming re-negotatiation will all collaborators
      - Ignores any request made in the last round
      - Uses the ask at the time of collaboration, rather than the
        current strategy of the collaborator
     """
     if not self.collaborations: return
     max_payoff = -1
     for strategy in self.strategy_set:
         payoff = 0
         for c in self.collaborations:
             them = c.collaborator_for(self)
             their_ask = c.ask_from(them)
             my_ask = self._ask_for(them, strategy)
             payoff += credit_game.get_payoffs(my_ask, their_ask)[0]
         if payoff > max_payoff:
             max_payoff = payoff
             self.cur_strategy = strategy
Exemple #4
0
 def credit_for(self, collaborator):
     a_credit, b_credit = credit_game.get_payoffs(self.a_ask, self.b_ask)
     return self._return_if(collaborator, a_credit, b_credit)