concepts.benchmark.algorithm_env.graph.Graph#

class Graph[source]#

Bases: object

Store a graph using adjacency matrix.

Methods

get_connectivity([k, exclude_self])

Return the k-connectivity for each pair of nodes.

get_coordinates()

Get the coordinates of the nodes.

get_edges()

Get the adjacency matrix of the graph.

get_out_degree()

Return the out degree of each node.

get_relations()

Return edges and identity matrix.

get_shortest()

Return the length of shortest path between nodes.

has_edge(x, y)

Return whether there is an edge from node x to node y.

__init__(nr_nodes, edges, coordinates=None)[source]#

Initialize a graph.

Parameters:
  • nr_nodes (int) – The Number of nodes in the graph.

  • edges (ndarray) – The adjacency matrix of the graph.

  • coordinates (ndarray | None)

__new__(**kwargs)#
get_connectivity(k=None, exclude_self=True)[source]#

Return the k-connectivity for each pair of nodes. It will return the full connectivity matrix if k is None or k < 0. When exclude_self is True, the diagonal elements will be 0.

Parameters:
  • k (int | None) – the k-connectivity. Default: None (full connectivity).

  • exclude_self (int) – exclude the diagonal elements. Default: True.

Returns:

The connectivity matrix.

Return type:

conn

get_coordinates()[source]#

Get the coordinates of the nodes.

Return type:

ndarray | None

get_edges()[source]#

Get the adjacency matrix of the graph. This function will return a copy of the adjacency matrix.

get_out_degree()[source]#

Return the out degree of each node.

Return type:

int

get_relations()[source]#

Return edges and identity matrix.

Return type:

ndarray

get_shortest()[source]#

Return the length of shortest path between nodes.

Return type:

ndarray

has_edge(x, y)[source]#

Return whether there is an edge from node x to node y.

Return type:

bool