Exemple #1
0
def generate(args):
    logger.info("loading dcop from {}".format(args.dcop_files))

    if args.dcop_files:
        dcop_files = args.dcop_files
    elif args.dcop_files_end:
        dcop_files = args.dcop_files_end

    dcop = load_dcop_from_file(dcop_files)
    agents = list(dcop.agents)

    scenario = generate_scenario(
        args.evts_count,
        args.actions_count,
        args.delay,
        args.initial_delay,
        args.end_delay,
        agents,
    )

    serialized = yaml_scenario(scenario)

    if args.output:
        output_file = args.output
        with open(output_file, encoding="utf-8", mode="w") as fo:
            fo.write(serialized)
    else:
        print(serialized)
def test_yaml_scenario_one_event():
    events = [
        DcopEvent("1", actions=[EventAction("remove_agent", agent="a01")])
    ]
    scenario = Scenario(events)

    scenario_str = yaml_scenario(scenario)

    obtained = load_scenario(scenario_str)

    assert len(obtained.events) == 1
    assert len(obtained.events[0].actions) == 1
def test_yaml_scenario_one_event_two_actions():
    events = [
        DcopEvent(
            "1",
            actions=[
                EventAction("remove_agent", agent="a01"),
                EventAction("remove_agent", agent="a05"),
            ],
        )
    ]
    scenario = Scenario(events)

    scenario_str = yaml_scenario(scenario)

    obtained = load_scenario(scenario_str)

    assert len(obtained.events) == 1
    assert len(obtained.events[0].actions) == 2
    assert obtained.events[0].actions[1].type == "remove_agent"
    assert obtained.events[0].actions[1].args["agent"] == "a05"
def test_yaml_scenario_two_events():
    events = [
        DcopEvent(
            "1",
            actions=[
                EventAction("remove_agent", agent="a01"),
                EventAction("remove_agent", agent="a05"),
            ],
        ),
        DcopEvent("2", delay=30),
    ]
    scenario = Scenario(events)

    scenario_str = yaml_scenario(scenario)

    obtained = load_scenario(scenario_str)

    assert len(obtained.events) == 2
    assert obtained.events[1].is_delay
    assert not obtained.events[0].is_delay