differt_core.rt.CompleteGraph#
- class CompleteGraph(num_nodes)#
Bases:
objectA 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
The number of nodes.
Methods
all_paths(from_, to, depth, *[, ...])Return an iterator over all paths of length
depthfrom nodefrom_to nodeto.all_paths_array(from_, to, depth, *[, ...])Return an array of all paths of length
depthfrom nodefrom_to nodeto.all_paths_array_chunks(from_, to, depth, *)Return an iterator over all paths of length
depthfrom nodefrom_to nodeto, 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
depthfrom nodefrom_to nodeto.Note
Unlike for
DiGraph’s iterators,from_andtonodes do not need to be part of the graph (i.e.,node_id >= num_nodes). This is especially useful to generate all paths fromfrom_toto, wherefrom_andtowill 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_arrayandall_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_andtonodes in the output paths. If set toFalse, the output paths will includedepth - 2nodes.
- Returns:
An iterator over all paths.
- Return type:
- all_paths_array(from_, to, depth, *, include_from_and_to=True)#
Return an array of all paths of length
depthfrom nodefrom_to nodeto.- 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_andtonodes in the output paths. If set toFalse, the output paths will includedepth - 2nodes.
- 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
depthfrom nodefrom_to nodeto, 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_andtonodes in the output paths. If set toFalse, the output paths will includedepth - 2nodes.chunk_size (int) – The size of each chunk.
- Returns:
An iterator over all paths, as array chunks.
- Return type:
- num_nodes#
The number of nodes.