differt_core.rt.CompleteGraph#

class CompleteGraph(num_nodes)#

Bases: object

A complete graph, i.e., a simple undirected graph in which every pair of distinct nodes is connected by a unique edge.

Parameters:

num_nodes (int) – The number of nodes.

Attributes

num_nodes

The number of nodes.

Methods

all_paths(from_, to, depth, *[, ...])

Return an iterator over all paths of length depth from node from_ to node to.

all_paths_array(from_, to, depth, *[, ...])

Return an array of all paths of length depth from node from_ to node to.

all_paths_array_chunks(from_, to, depth, *)

Return an iterator over all paths of length depth from node from_ to node to, grouped in chunks of size of max.

Detailed documentation

all_paths(from_, to, depth, *, include_from_and_to=True)#

Return an iterator over all paths of length depth from node from_ to node to.

Note

Unlike for DiGraph’s iterators, from_ and to nodes do not need to be part of the graph (i.e., node_id >= num_nodes). This is especially useful to generate all paths from from_ to to, where from_ and to will only ever appear in the first and last position, respectively.

Therefore, those iterators are equivalents:

>>> from differt_core.rt import CompleteGraph, DiGraph
>>>
>>> num_nodes, depth = 100, 5
>>> complete_graph = CompleteGraph(num_nodes)
>>> di_graph = DiGraph.from_complete_graph(complete_graph)
>>> from_, to = (
...     di_graph.insert_from_and_to_nodes(
...         direct_path=True
...     )
... )
>>>
>>> iter1 = complete_graph.all_paths(from_, to, depth)
>>> iter2 = di_graph.all_paths(from_, to, depth)
>>> assert(
...     all(
...         np.array_equal(p1, p2)
...         for p1, p2 in zip(iter1, iter2)
...     )
... )

This note also applies to all_paths_array and all_paths_array_chunks.

Parameters:
  • from_ (int) – The node index to find the paths from.

  • to (int) – The node index to find the paths to.

  • depth (int) – The number of nodes to include in each path.

  • include_from_and_to (bool) – Whether to include or not from_ and to nodes in the output paths. If set to False, the output paths will include depth - 2 nodes.

Returns:

An iterator over all paths.

Return type:

AllPathsFromCompleteGraphIter

all_paths_array(from_, to, depth, *, include_from_and_to=True)#

Return an array of all paths of length depth from node from_ to node to.

Parameters:
  • from_ (int) – The node index to find the paths from.

  • to (int) – The node index to find the paths to.

  • depth (int) – The number of nodes to include in each path.

  • include_from_and_to (bool) – Whether to include or not from_ and to nodes in the output paths. If set to False, the output paths will include depth - 2 nodes.

Returns:

An array of all paths.

Return type:

UInt[ndarray, "num_paths path_depth"]

all_paths_array_chunks(from_, to, depth, *, include_from_and_to=True, chunk_size=1000)#

Return an iterator over all paths of length depth from node from_ to node to, grouped in chunks of size of max. chunk_size.

Parameters:
  • from_ (int) – The node index to find the paths from.

  • to (int) – The node index to find the paths to.

  • depth (int) – The number of nodes to include in each path.

  • include_from_and_to (bool) – Whether to include or not from_ and to nodes in the output paths. If set to False, the output paths will include depth - 2 nodes.

  • chunk_size (int) – The size of each chunk.

Returns:

An iterator over all paths, as array chunks.

Return type:

AllPathsFromCompleteGraphChunksIter

num_nodes#

The number of nodes.