def test_comm_not_enough_place(self):
        f1 = relation_from_str('f1', 'v1 * 0.5 + v2 + v3', [v1, v2, v3])
        cv1 = VariableComputationNode(v1, ['f1'])
        cv2 = VariableComputationNode(v2, ['f1'])
        cv3 = VariableComputationNode(v3, ['f1'])
        cf1 = FactorComputationNode(f1)
        cg = ComputationsFactorGraph([cv1, cv2, cv3], [cf1])

        a1 = AgentDef("a1",
                      capacity=200,
                      default_hosting_cost=1,
                      hosting_costs={
                          "v1": 0,
                          "v2": 0
                      })

        a2 = AgentDef("a2", capacity=200, default_hosting_cost=1)

        a1.capacity = 15
        agent_mapping = distribute(cg, [a1, a2],
                                   hints=None,
                                   computation_memory=ms.computation_memory,
                                   communication_load=ms.communication_load)

        # As there is enough not capacity on a1, factor f1 and variable v3
        # must go on a2
        self.assertEqual(agent_mapping.agent_for('f1'), 'a2')
        self.assertEqual(agent_mapping.agent_for('v3'), 'a2')
    def test_comm(self):
        f1 = relation_from_str('f1', 'v1 * 0.5 + v2 + v3', [v1, v2, v3])
        cv1 = VariableComputationNode(v1, ['f1'])
        cv2 = VariableComputationNode(v2, ['f1'])
        cv3 = VariableComputationNode(v3, ['f1'])
        cf1 = FactorComputationNode(f1)
        cg = ComputationsFactorGraph([cv1, cv2, cv3], [cf1])

        a1 = AgentDef("a1",
                      capacity=200,
                      default_hosting_cost=1,
                      hosting_costs={
                          "v1": 0,
                          "v2": 0
                      })

        a2 = AgentDef("a2", capacity=200, default_hosting_cost=1)

        a1.capacity = 1000
        agent_mapping = distribute(cg, [a1, a2],
                                   hints=None,
                                   computation_memory=ms.computation_memory,
                                   communication_load=ms.communication_load)

        # As there is enough capacity on a1, factor f1 must go there (where
        # most of its variable are already hosted) while v3 must go on a2 to
        # make sure that all agents are used
        self.assertEqual(agent_mapping.agent_for('f1'), 'a1')
        self.assertEqual(agent_mapping.agent_for('v3'), 'a2')
    def test_respect_must_host_all_computation_fixed(self):

        f1 = relation_from_str('f1', 'v1 * 0.5 + v2', [v1, v2])
        cv1 = VariableComputationNode(v1, ['f1'])
        cv2 = VariableComputationNode(v2, [])
        cf1 = FactorComputationNode(f1)
        cg = ComputationsFactorGraph([cv1, cv2], [cf1])

        a1 = AgentDef("a1",
                      capacity=200,
                      default_hosting_cost=1,
                      hosting_costs={
                          "f1": 0,
                          "v1": 0
                      })

        a2 = AgentDef("a2",
                      capacity=200,
                      default_hosting_cost=1,
                      hosting_costs={"v2": 0})

        agent_mapping = distribute(cg, [a1, a2],
                                   hints=None,
                                   computation_memory=ms.computation_memory,
                                   communication_load=ms.communication_load)

        self.assertEqual(agent_mapping.agent_for('f1'), 'a1')
        self.assertEqual(agent_mapping.agent_for('v1'), 'a1')
        self.assertEqual(agent_mapping.agent_for('v2'), 'a2')
Beispiel #4
0
    def test_respect_must_host_for_var(self):

        f1 = relation_from_str('f1', 'v1 * 0.5', [v1])
        cv1 = VariableComputationNode(v1, ['f1'])
        cf1 = FactorComputationNode(f1)
        cg = ComputationsFactorGraph([cv1], [cf1])

        hints = DistributionHints(must_host={'a1': ['v1']})

        agent_mapping = distribute(cg, [a1, a2],
                                   hints=hints,
                                   computation_memory=ms.computation_memory,
                                   communication_load=ms.communication_load)

        self.assertEqual(agent_mapping.agent_for('v1'), 'a1')
def test_api_distribute_dsa_ilp_fgdp():
    from pydcop.computations_graph import factor_graph
    from pydcop.distribution import ilp_fgdp
    from pydcop.algorithms import dsa

    dcop = dcop_graphcoloring_3()
    agents = create_agents('a', range(1, 4), capacity=100)
    dcop._agents_def = agents

    cg = factor_graph.build_computation_graph(dcop)
    dist = ilp_fgdp.distribute(cg,
                               dcop.agents.values(),
                               computation_memory=dsa.computation_memory,
                               communication_load=dsa.communication_load)

    assert dist.is_hosted(['v1', 'v2', 'v3'])
Beispiel #6
0
    def test_comm_not_enough_place(self):
        f1 = relation_from_str('f1', 'v1 * 0.5 + v2 + v3', [v1, v2, v3])
        cv1 = VariableComputationNode(v1, ['f1'])
        cv2 = VariableComputationNode(v2, ['f1'])
        cv3 = VariableComputationNode(v3, ['f1'])
        cf1 = FactorComputationNode(f1)
        cg = ComputationsFactorGraph([cv1, cv2, cv3], [cf1])
        hints = DistributionHints(must_host={'a1': ['v1', 'v2']})

        a1.capacity = 10
        agent_mapping = distribute(cg, [a1, a2],
                                   hints=hints,
                                   computation_memory=ms.computation_memory,
                                   communication_load=ms.communication_load)

        # As there is enough not capacity on a1, factor f1 and variable v3
        # must go on a2 
        self.assertEqual(agent_mapping.agent_for('f1'), 'a2')
        self.assertEqual(agent_mapping.agent_for('v3'), 'a2')