Exemplo n.º 1
0
def test_satisficer_n_agent_per_level(method, n_agents, n_processes, n_steps):
    from scml.scml2020 import SCML2021World
    from pathlib import Path
    from negmas.situated import save_stats
    from negmas.helpers import force_single_thread

    force_single_thread(True)
    world = SCML2021World(
        **SCML2021World.generate(
            [SatisficerAgent] * n_processes,
            n_agents_per_process=n_agents,
            n_processes=n_processes,
            n_steps=n_steps,
            method=method,
            random_agent_types=False,
            neg_step_time_limit=float("inf"),
            neg_time_limit=float("inf"),
        ),
        compact=True,
        no_logs=True,
        avoid_ultimatum=True,
        end_negotiation_on_refusal_to_propose=True,
        name=f"Satisficer1{method}-a{n_agents}p{n_processes}s{n_steps}",
    )
    world.run()
    world.save_negotiations = True
    save_stats(
        world,
        log_dir=Path.home() / "negmas" / "logs" / "scml" / "scml2021" /
        world.name,
    )
    force_single_thread(False)

    assert True
Exemplo n.º 2
0
def test_production_cost_increase():
    from scml.scml2020 import SCML2021World
    from scml.scml2020.agents import DecentralizingAgent

    NPROCESSES = 5
    costs = [[] for _ in range(NPROCESSES)]
    for _ in range(100):
        world = SCML2021World(
            **SCML2021World.generate(
                DecentralizingAgent,
                n_agents_per_process=10,
                n_processes=NPROCESSES,
            ),
            compact=True,
            no_logs=True,
        )
        for aid in world.agent_profiles.keys():
            if is_system_agent(aid):
                continue
            profile = world.agent_profiles[aid]
            costs[profile.input_products[0]].append(
                profile.costs[:, profile.input_products[0]].mean())
    mean_costs = [sum(_) / len(_) for _ in costs]
    assert all([
        b > (0.5 * (i + 2) / (i + 1)) * a
        for i, (a, b) in enumerate(zip(mean_costs[:-1], mean_costs[1:]))
    ]), f"non-ascending costs {mean_costs}"
Exemplo n.º 3
0
def test_generate():
    world = SCML2021World(**SCML2021World.generate(agent_types=DoNothingAgent,
                                                   n_steps=10,
                                                   n_processes=4,
                                                   initial_balance=None))
    world.run()
    assert True
Exemplo n.º 4
0
def test_adapter(atype):
    world = SCML2021World(
        **SCML2021World.generate(agent_types=atype, n_steps=10),
        construct_graphs=False,
        no_logs=True,
        compact=True,
    )
    world.run()
Exemplo n.º 5
0
def test_generate(n_processes):
    world = SCML2021World(**SCML2021World.generate(
        agent_types=DoNothingAgent,
        n_steps=50,
        n_processes=n_processes,
        initial_balance=None,
    ))
    world.run()
Exemplo n.º 6
0
def test_graphs_lead_to_no_unknown_nodes():
    world = SCML2021World(
        **SCML2021World.generate(
            agent_types=[DecentralizingAgent, BuyCheapSellExpensiveAgent],
            n_steps=10),
        construct_graphs=True,
    )
    world.graph((0, world.n_steps))
Exemplo n.º 7
0
def generate_world(
    agent_types,
    n_processes=3,
    n_steps=10,
    n_agents_per_process=2,
    n_lines=10,
    initial_balance=None,
    buy_missing_products=True,
    **kwargs,
):
    kwargs["no_logs"] = True
    kwargs["compact"] = True
    world = SCML2021World(**SCML2021World.generate(
        agent_types,
        n_processes=n_processes,
        n_steps=n_steps,
        n_lines=n_lines,
        n_agents_per_process=n_agents_per_process,
        initial_balance=initial_balance,
        buy_missing_products=buy_missing_products,
        **kwargs,
    ))
    for s1, s2 in zip(world.suppliers[:-1], world.suppliers[1:]):
        assert len(set(s1).intersection(set(s2))) == 0
    for s1, s2 in zip(world.consumers[:-1], world.consumers[1:]):
        assert len(set(s1).intersection(set(s2))) == 0
    for p in range(n_processes):
        assert len(world.suppliers[p + 1]) == n_agents_per_process
        assert len(world.consumers[p]) == n_agents_per_process
    for a in world.agents.keys():
        if is_system_agent(a):
            continue
        assert len(world.agent_inputs[a]) == 1
        assert len(world.agent_outputs[a]) == 1
        assert len(world.agent_processes[a]) == 1
        assert len(
            world.agent_suppliers[a]) == (n_agents_per_process if
                                          world.agent_inputs[a][0] != 0 else 1)
        assert len(world.agent_consumers[a]) == (
            n_agents_per_process
            if world.agent_outputs[a][0] != n_processes else 1)
    return world
Exemplo n.º 8
0
def test_trading_prices_updated(n_agents, n_processes, n_steps):
    from scml.scml2020 import SCML2021World
    from negmas.helpers import force_single_thread

    eps = 1e-3

    world = SCML2021World(
        **SCML2021World.generate(
            [MyRandomAgent] * n_processes,
            n_agents_per_process=n_agents,
            n_processes=n_processes,
            n_steps=n_steps,
        ),
        compact=True,
        no_logs=True,
    )
    catalog_prices = world.catalog_prices
    diffs = np.zeros_like(catalog_prices)

    # we start at catlaog prices
    for aid, agent in world.agents.items():
        assert np.abs(agent.awi.trading_prices - catalog_prices).max() < eps

    force_single_thread(True)
    for _ in range(n_steps):
        world.step()
        trading_prices = None
        for aid, agent in world.agents.items():
            if is_system_agent(aid):
                continue
            trading_prices = agent.awi.trading_prices.copy()
            break
        diffs = np.maximum(diffs, np.abs(trading_prices - catalog_prices))

    assert diffs.max() > eps
    force_single_thread(False)
Exemplo n.º 9
0
    agent_types,
    n_processes=3,
    n_steps=10,
    n_agents_per_process=2,
    n_lines=10,
    initial_balance=10_000,
    buy_missing_products=True,
    **kwargs,
):
    kwargs["no_logs"] = True
    kwargs["compact"] = True
    world = SCML2021World(**SCML2021World.generate(
        agent_types,
        n_processes=n_processes,
        n_steps=n_steps,
        n_lines=n_lines,
        n_agents_per_process=n_agents_per_process,
        initial_balance=initial_balance,
        buy_missing_products=buy_missing_products,
        **kwargs,
    ))
    for s1, s2 in zip(world.suppliers[:-1], world.suppliers[1:]):
        assert len(set(s1).intersection(set(s2))) == 0
    for s1, s2 in zip(world.consumers[:-1], world.consumers[1:]):
        assert len(set(s1).intersection(set(s2))) == 0
    for p in range(n_processes):
        assert len(world.suppliers[p + 1]) == n_agents_per_process
        assert len(world.consumers[p]) == n_agents_per_process
    for a in world.agents.keys():
        if is_system_agent(a):
            continue
        assert len(world.agent_inputs[a]) == 1