Пример #1
0
def test_acceptable_outcomes():
    p = SAOMechanism(outcomes=6, n_steps=10)
    p.add(
        LimitedOutcomesNegotiator(name="seller", acceptable_outcomes=[(2,), (3,), (5,)])
    )
    p.add(
        LimitedOutcomesNegotiator(name="buyer", acceptable_outcomes=[(1,), (4,), (3,)])
    )
    state = p.run()
    assert state.agreement == (3,)
Пример #2
0
 def test_elicitor_runs(
     self, elicitor: Union[str, "BaseElicitor"], master, true_utilities, **kwargs
 ):
     neg = SAOMechanism(outcomes=n_outcomes, n_steps=10)
     user, strategy = master
     opponent = LimitedOutcomesNegotiator(
         acceptable_outcomes=accepted,
         acceptance_probabilities=[1.0] * len(accepted),
     )
     strategy.on_enter(ami=neg.ami)
     if isinstance(elicitor, str):
         elicitor = f"negmas.elicitation.{elicitor}"
         if "VOI" in elicitor:
             kwargs["dynamic_query_set"] = True
         elicitor = instantiate(elicitor, strategy=strategy, user=user, **kwargs)
     neg.add(opponent)
     neg.add(elicitor)
     assert elicitor.elicitation_cost == 0.0
     neg.run()
     queries = list(elicitor.user.elicited_queries())
     assert len(neg.history) > 0
     assert neg.agreement is None or neg.agreement in accepted
     assert (
         elicitor.elicitation_cost > 0.0
         or cost == 0.0
         or elicitor.strategy is None
         or neg.state.step < 2
     )
     if neg.agreement is not None:
         assert (
             elicitor.user_ufun(neg.agreement)
             == true_utilities[neg.agreement[0]] - elicitor.elicitation_cost
         )
     if hasattr(elicitor, "each_outcome_once") and elicitor.each_outcome_once:
         assert len(set([_[0] for _ in elicitor.offers])) == len(elicitor.offers)
Пример #3
0
 def test_voi_baarslag_example(self):
     outcomes = [(0, ), (1, )]
     alphas = [0.0, 1.0]
     opponent = LimitedOutcomesNegotiator(
         acceptable_outcomes=outcomes,
         acceptance_probabilities=alphas,
     )
Пример #4
0
 def test_elicitor_can_run_from_genius_domain(self, data_folder):
     domain, agents_info, issues = load_genius_domain_from_folder(
         os.path.join(data_folder, "Laptop"),
         force_single_issue=True,
         keep_issue_names=False,
         keep_value_names=False,
     )
     domain.add(LimitedOutcomesNegotiator(), ufun=agents_info[0]["ufun"])
     # domain.n_steps = 10
     user = User(ufun=agents_info[0]["ufun"], cost=0.2)
     strategy = EStrategy(strategy="titration-0.5")
     strategy.on_enter(ami=domain.ami)
     elicitor = PandoraElicitor(strategy=strategy, user=user)
     domain.add(elicitor)
     front, _ = domain.pareto_frontier()
     domain.run()
     assert len(domain.history) > 0
Пример #5
0
 def test_elicitor_can_get_frontier(self, data_folder):
     domain, agents_info, issues = load_genius_domain_from_folder(
         os.path.join(data_folder, "Laptop"),
         force_single_issue=True,
         keep_issue_names=False,
         keep_value_names=False,
         normalize_utilities=True,
     )
     assert len(issues) == 1
     assert len(agents_info) == 2
     domain.add(LimitedOutcomesNegotiator(), ufun=agents_info[0]["ufun"])
     user = User(ufun=agents_info[0]["ufun"], cost=cost)
     strategy = EStrategy(strategy="titration-0.5")
     strategy.on_enter(ami=domain.ami)
     elicitor = FullKnowledgeElicitor(strategy=strategy, user=user)
     domain.add(elicitor)
     front, _ = domain.pareto_frontier()
     assert front == [(1.0, 1.0)]
Пример #6
0
    def test_full_knowledge(self, master):
        user, strategy = master
        neg = SAOMechanism(outcomes=[(_,) for _ in range(n_outcomes)], n_steps=10)
        opponent = LimitedOutcomesNegotiator(
            acceptable_outcomes=accepted,
            acceptance_probabilities=[1.0] * len(accepted),
        )
        elicitor = FullKnowledgeElicitor(user=user)
        neg.add(opponent)
        neg.add(elicitor, ufun=u0(neg))
        neg.run()
        # print(
        #     f'Got {elicitor.ufun(neg.agreement)} with elicitation cost {elicitor.elicitation_cost}'
        #     f' for {elicitor} using 0 elicited_queries')

        assert len(neg.history) > 0
        assert neg.agreement is None or neg.agreement in accepted
        # assert len(set([_[0] for _ in elicitor.offers])) > 1 or len(elicitor.offers) < 2
        assert elicitor.elicitation_cost == 0.0
Пример #7
0
 def test_pareto_frontier_2(self):
     n_outcomes = 10
     strategy = "titration-0.5"
     cost = 0.01
     reserved_value = 0.1
     outcomes = [(_,) for _ in range(n_outcomes)]
     accepted = [(2,), (3,), (4,), (5,)]
     elicitor_utilities = [
         0.5337723805661662,
         0.8532272031479199,
         0.4781281413197942,
         0.7242899747791032,
         0.3461879818432919,
         0.2608677043479706,
         0.9419131964655383,
         0.29368079952747694,
         0.6093201983562316,
         0.7066918086398718,
     ]
     # list(np.random.rand(n_outcomes).tolist())
     opponent_utilities = [
         1.0 if (_,) in accepted else 0.0 for _ in range(n_outcomes)
     ]
     frontier, frontier_locs = pareto_frontier(
         [
             MappingUtilityFunction(
                 lambda o: elicitor_utilities[o[0]],
                 reserved_value=reserved_value,
                 outcome_type=tuple,
             ),
             MappingUtilityFunction(
                 lambda o: opponent_utilities[o[0]],
                 reserved_value=reserved_value,
                 outcome_type=tuple,
             ),
         ],
         outcomes=outcomes,
         sort_by_welfare=True,
     )
     welfare = (
         np.asarray(elicitor_utilities) + np.asarray(opponent_utilities)
     ).tolist()
     # print(f'frontier: {frontier}\nmax. welfare: {max(welfare)} at outcome: ({welfare.index(max(welfare))},)')
     # print(f'frontier_locs: frontier_locs')
     neg = SAOMechanism(outcomes=n_outcomes, n_steps=10, outcome_type=tuple)
     opponent = LimitedOutcomesNegotiator(
         acceptable_outcomes=accepted,
         acceptance_probabilities=[1.0] * len(accepted),
     )
     eufun = MappingUtilityFunction(
         dict(zip(outcomes, elicitor_utilities)),
         reserved_value=reserved_value,
         outcome_type=tuple,
     )
     user = User(ufun=eufun, cost=cost)
     strategy = EStrategy(strategy=strategy)
     strategy.on_enter(ami=neg.ami)
     elicitor = FullKnowledgeElicitor(strategy=strategy, user=user)
     neg.add(opponent)
     neg.add(elicitor)
     neg.run()
     f2, f2_outcomes = neg.pareto_frontier(sort_by_welfare=True)
     assert len(frontier) == len(f2)
     assert all([_1 == _2] for _1, _2 in zip(frontier, f2))
     assert [_[0] for _ in f2_outcomes] == frontier_locs