Agents¶
Agent¶
- class disropt.agents.Agent(in_neighbors=None, out_neighbors=None, communicator=None, in_weights=None, out_weights=None, auto_local=True)[source]¶
Bases:
object
The Agent object represents an agent in a network with communication capabilities
- Parameters
in_neighbors (list) – list of agents from which communication is received
out_neighbors (list) – list of agents to which information is send
communicator (Communicator, optional) – a Communicator object used to perform communications (if none is provided, it is automatically set to MPICommunicator). Defaults to None.
in_weights (list or dict, optional) – list or dict containing weights to assign to information coming from each in-neighbor. If a list is provided, it must have lenght equal to the number of agents in the network. If a dict is provided, it must have a key for each in-neighbor and, associated to it, the correspondig weight. Defaults to None, implies equal in_weights to in-neighbors.
out_weights (list or dict, optional) – list or dict containing weights to assign to out-neighbor. If a list is provided, it must have lenght equal to the number of agents in the network. If a dict is provided, it must have a key for each out-neighbor and, associated to it, the correspondig weight. Defaults to None, implies equal in_weights to out-neighbors.
auto_local (bool, optional) – If False the (in-)weight for the local agent must be provided. Otherwise it is set automatically, provided that the in_weights have sum in [0,1]. Defaults to True.
- in_weights¶
a dict containing weights to assign to information coming from each in-neighbor.
- Type
- communicator¶
Communicator object used to perform communications.
- Type
- neighbors_exchange(obj, dict_neigh=False, event=None)[source]¶
Exchange data with neighbors (synchronously). Send obj to the out-neighbors and receive received_obj from in-neighbors
- neighbors_receive_asynchronous()[source]¶
Receive data from in-neighbors (if any have been sent)
- Returns
a dictionary containing an object for each in-neighbor that has sent one
- Return type
- set_weights(in_weights=None, out_weights=None, auto_local=True)[source]¶
Set in_weights to assign to in-neighbors and the one for agent itself.
- Parameters
in_weights (
Union
[list
,dict
,None
]) – list or dict contatining in_weights to assign to information coming from each in-neighbor. If a list is provided, it must have lenght equal to the number of agents in the network. If a dict is provided, it must have a key for each in-neighbor and, associated to it, the correspondig weight. Defaults to None, implies equal in_weights to in-neighbors.out_weights (
Union
[list
,dict
,None
]) – list or dict contatining in_weights to assign to out-neighbors. If a list is provided, it must have lenght equal to the number of agents in the network. If a dict is provided, it must have a key for each out-neighbor and, associated to it, the correspondig weight. Defaults to None, implies equal in_weights to out neighbors.auto_local (
bool
) – If False the weight for the local agent must be provided. Otherwise it is set automatically, provided that the in_weights have sum in [0,1]. Defaults to True.
- Raises
ValueError – If a dict is provided as argument, it must contain a key for each in-neighbor.
ValueError – Input must be list or dict
ValueError – If auto_local is not False, the provided in_weights must have sum in [0,1]