Miscellaneaous Algorithms

Distributed Logic-And

class disropt.algorithms.misc.LogicAnd(agent, graph_diameter, flag=False, enable_log=False, **kwargs)[source]

Bases: disropt.algorithms.algorithm.Algorithm

Logic-And algorithm. It can be used for checking in a distributed way if a certain condition (corresponding to flag=True in the algorithm) is satisfied by all the agents in the network. Details can be found in [FaGa19a]

Parameters
  • agent (Agent) – Agent

  • graph_diameter (int) – diameter of the graph representing the network

  • flag (bool, optional) – local flag value. Defaults to False.

  • enable_log (bool, optional) – True for enabling log. Defaults to False.

change_flag(new_flag)[source]

Change the local flag

Parameters

new_flag (bool) – new flag

check_stop()[source]

Check the last row of S

Returns

True if last row contains only ones. Meaning that all have the flag True

Return type

bool

force_matrix_update()[source]

Force the matrix S to have all ones in the last row

iterate_run()[source]

Run an iterate

matrix_reset()[source]
matrix_update()[source]

Update the matrix S

run(maximum_iterations=100, verbose=False)[source]

Run the algorithm

Parameters
  • maximum_iterations (int) – Maximum number of iterations. Defaults to 100.

  • verbose (bool) – If True print some information during the evolution of the algorithm. Defaults to False.

Raises

TypeError – maximum iterations must be an int

update_column(neighbor, column)[source]

Update a column of the matrix corresponding to a neighbor

Parameters
  • neighbor (Any) – neighbor

  • column (ndarray) – column value

Raises
  • TypeError – second argument must be a numpy.ndarray with shape (graph_diameter, )

  • ValueError – second argument must be a numpy.ndarray with shape (graph_diameter, )

Asynchronous Distributed Logic-And

class disropt.algorithms.misc.AsynchronousLogicAnd(agent, graph_diameter, flag=False, enable_log=False, **kwargs)[source]

Bases: disropt.algorithms.misc.LogicAnd

Asyncrhonous Logic-And algorithm. It can be used for checking in a distributed way if a certain condition (corresponding to flag=True in the algorithm) is satisfied by all the agents in the network. Details can be found in [FaGa19a]

Parameters
  • agent (Agent) – Agent

  • graph_diameter (int) – diameter of the graph representing the network

  • flag (bool, optional) – local flag value. Defaults to False.

  • enable_log (bool, optional) – True for enabling log. Defaults to False.

iterate_run()[source]

Run an iterate

run(maximum_running_time=1)[source]

Run the algorithm

Parameters

maximum_running_time (float) – Maximum running time. Defaults to 1.

Raises

TypeError – maximum running time must be a float

Distributed Max-Consensus

class disropt.algorithms.misc.MaxConsensus(agent, x0, graph_diameter=None, enable_log=False, **kwargs)[source]

Bases: disropt.algorithms.algorithm.Algorithm

Max-Consensus algorithm. It computes the entry-wise maximum of a numpy array by using only neighboring communication.

Parameters
  • agent (Agent) – Agent

  • x0 (np.ndarray) – local initial condition

  • graph_diameter (int, optional) – diameter of the graph representing the network

  • enable_log (bool, optional) – True to enable log. Defaults to False.

get_result()[source]

Return the value of the solution

iterate_run()[source]

Run an iterate

run(iterations=100, verbose=False)[source]

Run the algorithm

Parameters
  • iterations (int) – Maximum number of iterations. Defaults to 100.

  • verbose (bool) – If True print some information during the evolution of the algorithm. Defaults to False.

Raises

TypeError – maximum iterations must be an int

References

FaGa19a(1,2)

Farina, F., Garulli, A., Giannitrapani, A., & Notarstefano, G. (2019). A distributed asynchronous method of multipliers for constrained nonconvex optimization. Automatica, 103, 243-253.