示例#1
0
def test_genius_agent_same_utility(init_genius):
    from negmas import GeniusNegotiator, load_genius_domain

    dom = dom_folder / "travel_domain.xml"
    util1 = dom_folder / "travel_chox.xml"
    util2 = util1
    a1 = GeniusNegotiator(
        java_class_name="agents.anac.y2015.Atlas3.Atlas3",
        domain_file_name=dom,
        utility_file_name=util1,
    )
    a2 = GeniusNegotiator(
        java_class_name="agents.anac.y2015.AgentX.AgentX",
        domain_file_name=dom,
        utility_file_name=util2,
    )
    p, _, issues = load_genius_domain(dom,
                                      keep_issue_names=True,
                                      keep_value_names=True,
                                      time_limit=30)
    issue_list = [f"{k}:{v}" for k, v in enumerate(issues)]
    assert issue_list == [
        "0:Atmosphere: ['Cultural heritage', 'Local traditions', 'Political stability', 'Security (personal)'"
        ", 'Liveliness', 'Turistic activities', 'Hospitality']",
        "1:Amusement: ['Nightlife and entertainment', 'Nightclubs', 'Excursion', 'Casinos', 'Zoo'"
        ", 'Festivals', 'Amusement park']",
        "2:Culinary: ['Local cuisine', 'Lunch facilities', 'International cuisine', 'Cooking workshops']",
        "3:Shopping: ['Shopping malls', 'Markets', 'Streets', 'Small boutiques']",
        "4:Culture: ['Museum', 'Music hall', 'Theater', 'Art gallery', 'Cinema', 'Congress center']",
        "5:Sport: ['Bike tours', 'Hiking', 'Indoor activities', 'Outdoor activities', 'Adventure']",
        "6:Environment: ['Parks and Gardens', 'Square', 'Historical places', 'See, river, etc.'"
        ", 'Monuments', 'Special streets', 'Palace', 'Landscape and nature']",
    ]
    p.add(a1)
    p.add(a2)
    p.run()
    u1 = np.array(
        [float(a1._utility_function(s.current_offer)) for s in p.history])
    u2 = np.array(
        [float(a2._utility_function(s.current_offer)) for s in p.history])
    welfare = u1 + u2
    assert len(u1) == 1
    assert welfare[0] == 2.0
    assert p.state.agreement is not None
    assert p.state.broken is False
示例#2
0
def test_genius_agent_step_long_session(init_genius):
    a1 = GeniusNegotiator(
        java_class_name="agents.anac.y2015.Atlas3.Atlas3",
        domain_file_name=dom,
        utility_file_name=util1,
    )
    a2 = GeniusNegotiator(
        java_class_name="agents.anac.y2015.Atlas3.Atlas3",
        domain_file_name=dom,
        utility_file_name=util2,
    )
    p, _, issues = load_genius_domain(
        dom,
        keep_issue_names=True,
        keep_value_names=True,
        n_steps=20,
        time_limit=None,
        normalize_utilities=True,
    )
    issue_list = [f"{k}:{v}" for k, v in enumerate(issues)]
    assert issue_list == [
        "0:Atmosphere: ['Cultural heritage', 'Local traditions', 'Political stability', 'Security (personal)', 'Liveliness', 'Turistic activities', 'Hospitality']",
        "1:Amusement: ['Nightlife and entertainment', 'Nightclubs', 'Excursion', 'Casinos', 'Zoo', 'Festivals', 'Amusement park']",
        "2:Culinary: ['Local cuisine', 'Lunch facilities', 'International cuisine', 'Cooking workshops']",
        "3:Shopping: ['Shopping malls', 'Markets', 'Streets', 'Small boutiques']",
        "4:Culture: ['Museum', 'Music hall', 'Theater', 'Art gallery', 'Cinema', 'Congress center']",
        "5:Sport: ['Bike tours', 'Hiking', 'Indoor activities', 'Outdoor activities', 'Adventure']",
        "6:Environment: ['Parks and Gardens', 'Square', 'Historical places', 'See, river, etc.', 'Monuments', 'Special streets', 'Palace', 'Landscape and nature']",
    ]
    p.add(a1)
    p.add(a2)
    p.run()
    # print(f'{len(p.history)} bids exchanged')
    u1 = np.array([float(a1._utility_function(s.current_offer)) for s in p.history])
    u2 = np.array([float(a2._utility_function(s.current_offer)) for s in p.history])
    welfare = u1 + u2
    # print(
    #     f'Negotiator 1: {u1.mean()}({u1.std()})[{u1.min()}, {u1.max()}]\nNegotiator 2: {u2.mean()}({u2.std()})[{u1.min()}, {u1.max()}]'
    #     f'\nWelfare: {welfare.mean()}({welfare.std()})[{welfare.min()}, {welfare.max()}]')
    # print(p.state)
    assert len(u1) > 4