def test_dcop_add_agents_from_list(): dcop = DCOP() a1 = AgentDef('a1') a2 = AgentDef('a2') dcop.add_agents([a1, a2]) assert dcop.agent('a1').name == 'a1' assert dcop.agent('a2').name == 'a2'
def test_dcop_add_agents_from_dict(): dcop = DCOP() agts = create_agents('a', [1, 2, 3]) dcop.add_agents(agts) assert dcop.agent('a1').name == 'a1' assert dcop.agent('a2').name == 'a2' assert dcop.agent('a3').name == 'a3'
def test_solve_max(toy_pb): variables, constraints = toy_pb dcop = DCOP(name="toy", variables={v.name: v for v in variables}, constraints={c.name: c for c in constraints}, objective="max") dcop.add_agents(create_agents("a", [1, 2, 3, 4])) assignment = solve(dcop, "syncbb", "oneagent") # Note: this is supposed to be exactly the same pb as bellow assert assignment == {"vA": "G", "vB": "R", "vC": "R", "vD": "G"}
def test_solve_min(toy_pb): variables, constraints = toy_pb dcop = DCOP(name="toy", variables={v.name: v for v in variables}, constraints={c.name: c for c in constraints}, objective="min") dcop.add_agents(create_agents("a", [1, 2, 3, 4])) assignment = solve(dcop, "syncbb", "oneagent") # Note: this is exactly the same pb as in the file bellow # dcop = load_dcop_from_file(["/pyDcop/tests/instances/graph_coloring_tuto.yaml"]) assert assignment == {"vA": "G", "vB": "G", "vC": "G", "vD": "G"}
def test_dcop_add_single_agent(): dcop = DCOP() a1 = AgentDef('a1') dcop.add_agents(a1) assert dcop.agent('a1').name == 'a1'