def test_tough_asp_negotiator(): a1 = ToughNegotiator() a2 = AspirationNegotiator(aspiration_type="conceder") outcomes = [(_, ) for _ in range(10)] u1 = np.linspace(0.0, 1.0, len(outcomes)) u2 = 1.0 - u1 neg = SAOMechanism(outcomes=outcomes, n_steps=100, outcome_type=tuple) neg.add(a1, ufun=u1) neg.add(a2, ufun=u2) neg.run() a1offers = neg.negotiator_offers(a1.id) a2offers = neg.negotiator_offers(a2.id) assert a1._offerable_outcomes is None if len(a1offers) > 0: assert len(set(a1offers)) == 1 and a1offers[-1] == (9, ) assert len(set(a2offers)) >= 0
def test_best_only_asp_negotiator(): a1 = OnlyBestNegotiator(min_utility=0.9, top_fraction=0.1) a2 = AspirationNegotiator(aspiration_type="conceder") outcomes = [(_, ) for _ in range(20)] u1 = np.linspace(0.0, 1.0, len(outcomes)) u2 = 1.0 - u1 neg = SAOMechanism(outcomes=outcomes, n_steps=200) neg.add(a1, ufun=u1) neg.add(a2, ufun=u2) neg.run() a1offers = neg.negotiator_offers(a1.id) a2offers = neg.negotiator_offers(a2.id) assert a1._offerable_outcomes is None if len(a1offers) > 0: assert (len(set(a1offers)) <= 2 and min([u1[_[0]] for _ in a1offers if _ is not None]) >= 0.9) assert len(set(a2offers)) >= 1
def test_tough_tit_for_tat_negotiator(): a1 = ToughNegotiator() a2 = NaiveTitForTatNegotiator() outcomes = [(_, ) for _ in range(10)] u1 = np.linspace(0.0, 1.0, len(outcomes)) u2 = 1.0 - u1 neg = SAOMechanism(outcomes=outcomes, n_steps=100, outcome_type=tuple) neg.add(a1, ufun=u1) neg.add(a2, ufun=u2) neg.run() a1offers = neg.negotiator_offers(a1.id) a2offers = neg.negotiator_offers(a2.id) # print(a1offers) # print(a2offers) assert a1._offerable_outcomes is None if len(a1offers) > 0: assert len(set(a1offers)) == 1 and a1offers[-1] == (9, ) assert len(set(a2offers)) >= 0
def test_asp_negotaitor(): a1 = AspirationNegotiator(assume_normalized=True, name="a1") a2 = AspirationNegotiator(assume_normalized=False, name="a2") outcomes = [(_, ) for _ in range(10)] u1 = np.linspace(0.0, 1.0, len(outcomes)) u2 = 1.0 - u1 neg = SAOMechanism(outcomes=outcomes, n_steps=100) neg.add(a1, ufun=u1) neg.add(a2, ufun=u2) neg.run() a1offers = neg.negotiator_offers(a1.id) a2offers = neg.negotiator_offers(a2.id) assert a1offers[0] == (9, ) assert a2offers[0] == (0, ) for i, offer in enumerate(_[0] for _ in a1offers): assert i == 0 or offer <= a1offers[i - 1][0] for i, offer in enumerate(_[0] for _ in a2offers): assert i == 0 or offer >= a2offers[i - 1][0] assert neg.state.agreement is not None assert neg.state.agreement in ((4, ), (5, ))
def test_tit_for_tat_negotiators(): a1 = NaiveTitForTatNegotiator(name="a1") a2 = NaiveTitForTatNegotiator(name="a2") outcomes = [(_, ) for _ in range(10)] u1 = np.linspace(0.0, 1.0, len(outcomes)) u2 = 1.0 - u1 neg = SAOMechanism(outcomes=outcomes, n_steps=100, avoid_ultimatum=False) neg.add(a1, ufun=u1) neg.add(a2, ufun=u2) neg.run() a1offers = neg.negotiator_offers(a1.id) a2offers = neg.negotiator_offers(a2.id) # print(a1offers) # print(a2offers) assert a1offers[0] == (9, ) assert a2offers[0] == (0, ) for i, offer in enumerate(_[0] for _ in a1offers): assert i == 0 or offer <= a1offers[i - 1][0] for i, offer in enumerate(_[0] for _ in a2offers): assert i == 0 or offer >= a2offers[i - 1][0] assert neg.state.agreement is not None assert neg.state.agreement in ((4, ), (5, ))