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.

id

id of the Agent

Type

int

in_neighbors

list of in-neighbors

Type

list

out_neighbors

list of out-neighbors

Type

list

in_weights

a dict containing weights to assign to information coming from each in-neighbor.

Type

dict

out_weights

a dict containing weights to assign to out-neighbors.

Type

dict

communicator

Communicator object used to perform communications.

Type

Communicator

problem

Local optimization problem.

Type

Problem

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

Parameters
  • obj (Any) – object to send

  • dict_neigh – True if obj contains a dictionary with different objects for each neighbor. Defaults to False.

Returns

a dictionary containing an object for each in-neighbor

Return type

dict

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

dict

neighbors_send(obj)[source]

Send data to out-neighbors

Parameters

obj (Any) – object to send

set_neighbors(in_neighbors, out_neighbors)[source]

Set in and out neighbors

Parameters
  • in_neighbors (list) – list of agents from which communication is received

  • out_neighbors (list) – list of agents to which information is send

set_problem(problem)[source]

set the local optimization problem

Parameters

problem (Problem) – Problem object

Raises

TypeError – Input must be a Problem object

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]