Utilities

Graph generation

MPIgraph

class disropt.utils.graph_constructor.MPIgraph(graph_type=None, in_weight_matrix_type=None, out_weight_matrix_type=None, **kwargs)[source]

Bases: object

Create a graph on the network

Parameters
  • graph_type (str, optional) – type of graph (‘complete’, ‘random_binomial’). Defaults to None (complete).

  • in_weight_matrix_type (str, optional) – type of matrix describing in-neighbors weights (‘metropolis’, ‘row_stochastic’, ‘column_stochastic’). Defaults to None (metropolis).

  • out_weight_matrix_type (str, optional) – type of matrix describing out-neighbors weights (‘metropolis’, ‘row_stochastic’, ‘column_stochastic’). Defaults to None (metropolis).

get_local_info()[source]

return the local info available at the agent

Returns

local_rank, in_neighbors, out_neighbors, in_weights, out_weights,

Return type

tuple

ring_graph

disropt.utils.graph_constructor.ring_graph(N, link_type='undirected')[source]

construct a ring graph

Parameters
  • N (int) – number of agents

  • link_type (str, optional) – ‘directed’ or ‘undirected’. Defaults to ‘undirected’.

Returns

adjacency matrix

Return type

numpy.ndarray

binomial_random_graph

disropt.utils.graph_constructor.binomial_random_graph(N, p=None, seed=None, link_type='undirected')[source]

construct a random binomial graph

Parameters
  • N (int) – number of agents

  • p (float, optional) – link probability. Defaults to None (=1).

  • seed (int, optional) – [description]. Defaults to None (=1).

  • link_type (str, optional) – ‘directed’ or ‘undirected’. Defaults to ‘undirected’.

Returns

adjacency matrix

Return type

numpy.ndarray

binomial_random_graph_sequence

disropt.utils.graph_constructor.binomial_random_graph_sequence(under_adj, n_graphs, p=0.1, period=None, seed=None, link_type='undirected')[source]

Construct a sequence of random binomial graphs starting from a given underlying graph

Parameters
  • under_adj (2D numpy.ndarray) – Adjacency matrix of underlying graph.

  • n_graphs (int) – number of graphs in the returned sequence.

  • p (float or 2D numpy.ndarray, optional) – link probability. Defaults to None (=0.1).

  • period (int, optional) – T-connectivity period of the returned sequence (obtained artificially with cycles). Defaults to None (no T-connectivity).

  • seed (int, optional) – [description]. Defaults to None (=1).

  • link_type (str, optional) – ‘directed’ or ‘undirected’. Defaults to ‘undirected’.

Returns

sequence of adjacency matrices

Return type

tuple(numpy.ndarray)

Weighted adjacency matrices

metropolis_hastings

disropt.utils.graph_constructor.metropolis_hastings(Adj, link_type='undirected')[source]

Construct a weight matrix using the Metropolis-Hastings method

Parameters

Adj (numpy.ndarray) – Adjacency matrix

Returns

weighted adjacency matrix

Return type

numpy.ndarray

row_stochastic_matrix

disropt.utils.graph_constructor.row_stochastic_matrix(Adj, weights_type='uniform')[source]

Construct a row-stochastic weighted adjacency matrix

Parameters

Adj (numpy.ndarray) – Adjacency matrix

Returns

weighted adjacency matrix

Return type

numpy.ndarray

column_stochastic_matrix

disropt.utils.graph_constructor.column_stochastic_matrix(Adj, weights_type='uniform')[source]

Construct a column-stochastic weighted adjacency matrix

Parameters

Adj (numpy.ndarray) – Adjacency matrix

Returns

weighted adjacency matrix

Return type

numpy.ndarray

Matrix properties

is_pos_def

disropt.utils.utilities.is_pos_def(P)[source]

check if a matrix is positive definite

Parameters

P (numpy.ndarray) – matrix

Return type

bool

is_semi_pos_def

disropt.utils.utilities.is_semi_pos_def(P)[source]

check if a matrix is positive semi-definite

Parameters

P (numpy.ndarray) – matrix

Return type

bool

check_symmetric

disropt.utils.utilities.check_symmetric(A, rtol=1e-05, atol=1e-08)[source]

check if a matrix is symetric

Parameters
Return type

bool

Linear Programming

generate_LP

disropt.utils.LP_utils.generate_LP(n_var, n_constr, radius, direction='min', constr_form='ineq')[source]

Generate a feasible and not unbounded Linear Program and return problem data (cost, constraints, solution) TODO add reference

Parameters
  • n_var (int) – number of optimization variables

  • n_constr (int) – number of constraints

  • radius (float) – size of feasible set (for constr_form = ‘ineq’), size of dual feasible set (for constr_form = ‘eq’)

  • direction (str, optional) – optimization direction - either ‘max’ (for maximization) or ‘min’ (for minimization). Defaults to ‘min’

  • constr_form (str, optional) – form of constraints - either ‘ineq’ (for inequality: \(Ax \le b\)) or ‘eq’ (for standard form: \(Ax = b, x \ge 0\)). Defaults to ‘ineq’

Returns

  • c (numpy.ndarray): cost vector

  • A (numpy.ndarray): constraint matrix

  • b (numpy.ndarray): constraint vector (right-hand side)

  • solution (numpy.ndarray): optimal solution of problem

Return type

tuple