pydcop.distribution¶
A distribution method is used to decide which agent hosts each computation.
Distribution methods are implemented in pydcop.distribution
.
object.py
defines objects that are used by all distribution methods
(Distribution` and `DistributionHints
).
A distribution method computes the allocation
of a set computations to a set of agents.
See DCOP computation distribution for more details on the distribution concept.
pyDCOP currently provides the following distribution methods :
Implementing a distribution method¶
To implement a new distribution method, one must:
create a new module in
pydcop.distribution
, named after the distribution methoddefine the following methods in this file:
distribute
, which returns a Distribution object
distribution_cost
, which return the cost of a distribution. If your distribution algorithm does define a notion of cost, you can simply return 0 (like theoneagent
distribution)additionally, for dynamic distribution, you can also provide these methods:
distribute_remove
distribute_add
Base classes¶
-
class
Distribution
(mapping: Dict[str, List[str]])¶ This object is a convenient representation of a distribution with methods for querying it (has_computation, agent_for, etc.)
- Parameters
mapping (mapping: Dict[str, List[str]]) – A dict agent name: [computation names]. Basic validity checks are performed to ensure that the same computation is not hosted on several agents.
-
agent_for
(computation: str) → str¶ Agent hosting one given computation :param computation: a computation’s name :type computation: str
- Returns
the name of the agent hosting this computation.
- Return type
str
-
property
agents
¶ Agents used in this distribution
- Returns
The list of the names of agents used in this distribution.
- Return type
agents list
-
property
computations
¶ Distributed computations
- Returns
A list containing the names of the computations distributed in this distribution.
- Return type
computations list
-
computations_hosted
(agent: str) → List[str]¶ Computations hosted on an agent.
If the agent is not used in the distribution (its name is not known), returns an empty list.
- Parameters
agent (str) – the name of the agent
- Returns
The list of computations hosted by this agent.
- Return type
List[str]
-
has_computation
(computation: str)¶ - Parameters
computation (str) – computation name
- Returns
True if this computation is part of the distribution
- Return type
Boolean
-
host_on_agent
(agent: str, computations: List[str])¶ Host several computations on an agent.
Modify the distribution by adding computations to be hosted on agent. If this agent name is unknown, it is added, otherwise the list of computations is added to the computations already hosted by this agent.
- Parameters
agent (str) – an agent name
computations (List[str]) – A list of computation names
-
is_hosted
(computations: Union[str, Iterable[str]])¶ Indicates if some computations are hosted.
This methods does not care on which agent the computations are hosted.
- Parameters
computations (List[str]) – A list of computation names
- Returns
True if all computations are hosted.
- Return type
Boolean
-
mapping
() → Dict[str, List[str]]¶ The distribution represented as a dict.
- Returns
A dict associating a list of computation names to each agent name.
- Return type
Dict[str, List[str]]