# nxalg

## Abstractβ

This module, named **nxalg**, provides a comprehensive set of thin wrappers around most of the algorithms present in the NetworkX package. The wrapper functions now have the capability to create a NetworkX compatible graph-like object that can stream the native database graph directly saving on memory usage significantly.

Trait | Value |
---|---|

Module type | module |

Implementation | Python |

Graph direction | directed/undirected |

Edge weights | weighted/unweighted |

Parallelism | sequential |

## Proceduresβ

If you want to execute this algorithm on graph projections, subgraphs or portions of the graph, be sure to check out the guide on How to run a MAGE module on subgraphs.

`all_shortest_paths(source, target, weight, method)`

β

Compute all shortest simple paths in the graph. A simple path is a path with no repeated nodes.

#### Input:β

`source: Vertex`

β‘ Starting node for the path.`target: Vertex`

β‘ Ending node for the path.`weight: string (default=NULL)`

β‘ If`NULL`

, every edge has weight/distance/cost 1. If a string, use this edge attribute as the edge weight. Any edge attribute not present defaults to 1.`method: string (default="dijkstra")`

β‘ The algorithm to use to compute the path lengths. Supported options: βdijkstraβ, βbellman-fordβ. Other inputs produce a ValueError. If`weight`

is`None`

, unweighted graph methods are used, and this suggestion is ignored.

#### Output:β

`paths: List[Vertex]`

β‘ List of vertices for a certain path.

#### Usage:β

`MATCH (n:Label), (m:Label)`

CALL nxalg.all_shortest_paths(n, m) YIELD *

RETURN paths;

`all_simple_paths(source, target, cutoff)`

β

Returns all simple paths in the graph `G`

from source to target. A simple path is a path with no repeated nodes.

#### Input:β

`source: Vertex`

β‘ Starting node for the path.`target: Vertex`

β‘ Ending node for the path.`cutoff: List[integer] (default=NULL)`

β‘ Depth to stop the search. Only paths of`length <= cutoff`

are returned.

#### Output:β

`paths: List[Vertex]`

β‘ List of vertices for a certain path. If there are no paths between the source and target within the given cutoff there is no output.

#### Usage:β

`MATCH (n:Label), (m:Label)`

CALL nxalg.all_simple_paths(n, m, 5) YIELD *

RETURN paths;

`ancestors(source)`

β

Returns all nodes having a path to `source`

in `G`

.

#### Input:β

`source: Vertex`

β‘ Starting node. Calculates all nodes that have a path to`source`

#### Output:β

`ancestors: List[Vertex]`

β‘ List of vertices that have a path toward source node

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.ancestors(n) YIELD *

RETURN ancestors;

`betweenness_centrality(k, normalized, weight, endpoints, seed)`

β

Compute the shortest-path betweenness centrality for nodes. *Betweenness centrality* is a measure of centrality in a graph based on shortest paths. Centrality identifies the most important nodes within a graph.

#### Input:β

`k: string (default=NULL)`

β‘ If`k`

is not`None`

, use`k`

node samples to estimate betweenness. The value of`k <= n`

where`n`

is the number of nodes in the graph. Higher values give a better approximation.`normalized: boolean (default=True)`

β‘ If`True`

the betweenness values are normalized by`2/((n-1)(n-2))`

for graphs, and`1/((n-1)(n-2))`

for directed graphs where`n`

is the number of nodes in`G`

.`weight: string (default=NULL)`

β‘ If`None`

, all edge weights are considered equal. Otherwise holds the name of the edge attribute used as weight.`endpoints: boolean (default=False)`

β‘ If`True`

, includes the endpoints in the shortest path counts.`seed: integer (default=NULL)`

β‘ Indicator of random number generation state. Note that this is only used if`k`

is not`None`

.

#### Output:β

`node: Vertex`

β‘ Graph vertex for betweenness calculation`betweenness: double`

β‘ Value of betweenness for a given node

#### Usage:β

`CALL nxalg.betweenness_centrality(20, True) YIELD *`

RETURN node, betweenness;

`bfs_edges(source, reverse, depth_limit)`

β

Iterate over edges in a breadth-first-search starting at source.

#### Input:β

`source: Vertex`

β‘ Specify starting node for breadth-first search; this function iterates over only those edges in the component reachable from this node.`reverse: boolean (default=False)`

β‘ If`True`

, traverse a directed graph in the reverse direction.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`edges: List[Edge]`

β‘ List of edges in the breadth-first search.

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.bfs_edges(n, False) YIELD *

RETURN edges;

`bfs_predecessors(source, depth_limit)`

β

Returns an iterator of predecessors in breadth-first-search from source.

#### Input:β

`source: Vertex`

β‘ Specify starting node for breadth-first search.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`node: Vertex`

β‘ Node in a graph`predecessors: List[Vertex]`

β‘ List of predecessors of given node

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.bfs_predecessors(n, 10) YIELD *

RETURN node, predecessors;

`bfs_successors(source, depth_limit)`

β

Returns an iterator of successors in breadth-first-search from source.

#### Input:β

`source: Vertex`

β‘ Specify starting node for breadth-first search.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`node: Vertex`

β‘ Node in a graph`successors: List[Vertex]`

β‘ List of successors of given node

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.bfs_successors(n, 5) YIELD *

RETURN node, successors;

`bfs_tree(source, reverse, depth_limit)`

β

Returns an oriented tree constructed from of a breadth-first-search starting at `source`

.

#### Input:β

`source: Vertex`

β‘ Specify starting node for breadth-first search.`reversed: boolean (default=False)`

β‘ If`True`

, traverse a directed graph in the reverse direction.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`tree: List[Vertex]`

β‘ An oriented tree in a list format.

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.bfs_tree(n, True, 3) YIELD *

RETURN n, tree;

`biconnected_components()`

β

Returns a list of sets of nodes, one set for each biconnected component of the graph

*Biconnected components* are maximal subgraphs such that the removal of a
node (and all edges incident on that node) will not disconnect the
subgraph. Note that nodes may be part of more than one biconnected
component. Those nodes are articulation points or cut vertices. The
removal of articulation points will increase the number of connected
components of the graph.

Notice that by convention a dyad is considered a biconnected component.

#### Output:β

`components: List[List[Vertex]]`

β‘ A list of sets of nodes, one set for each biconnected component.

#### Usage:β

`CALL nxalg.biconnected_components() YIELD *`

RETURN components;

`bridges(root)`

β

Returns all bridges in a graph.

A *bridge* in a graph is an edge whose removal causes the number of
connected components of the graph to increase. Equivalently, a bridge is an
edge that does not belong to any cycle.

#### Input:β

`root: Vertex (default=NULL)`

β‘ A node in the graph`G`

. If specified, only the bridges in the connected components containing this node will be returned.

#### Output:β

`bridges: List[Edge]`

β‘ A list of edges in the graph whose removal disconnects the graph (or causes the number of connected components to increase).

#### Usage:β

`CALL nxalg.bridges() YIELD *`

RETURN bridges;

`center()`

β

Returns the center of the graph `G`

.

The *center* is the set of nodes with eccentricity equal to the radius.

#### Output:β

`center: List[Vertex]`

β‘ List of nodes in center.

#### Usage:β

`CALL nxalg.center() YIELD *`

RETURN center;

`chain_decomposition(root)`

β

Returns the chain decomposition of a graph.

The *chain decomposition* of a graph with respect to a depth-first
search tree is a set of cycles or paths derived from the set of
fundamental cycles of the tree in the following manner. Consider
each fundamental cycle with respect to the given tree, represented
as a list of edges beginning with the non tree edge oriented away
from the root of the tree. For each fundamental cycle, if it
overlaps with any previous fundamental cycle, just take the initial
non-overlapping segment, which is a path instead of a cycle. Each
cycle or path is called a *chain*.

#### Input:β

`root: Vertex[NULL]`

β‘ Optional. A node in the graph`G`

. If specified, only the chain decomposition for the connected component containing this node will be returned. This node indicates the root of the depth-first Search tree.

#### Output:β

`chains: List[List[Edge]]`

β‘ A list of edges representing a chain. There is no guarantee on the orientation of the edges in each chain (for example, if a chain includes the edge joining nodes 1 and 2, the chain may include either (1, 2) or (2, 1)).

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.chain_decomposition(n) YIELD *

RETURN chains;

`check_planarity()`

β

Check if a graph is planar.

A graph is planar if it can be drawn in a plane without any edge intersections.

#### Output:β

`is_planar: boolean`

β‘`True`

if the graph is planar.

#### Usage:β

`CALL nxalg.check_planarity() YIELD *`

RETURN is_planar;

`clustering(nodes, weight)`

β

Compute the clustering coefficient for nodes.

A *clustering coefficient* is a measure of the degree to which nodes
in a graph tend to cluster together.

#### Input:β

`nodes: List[Vertex] (default=NULL)`

β‘ Compute clustering for nodes in this container.`weight: string (default=NULL)`

β‘ The edge attribute that holds the numerical value used as a weight. If`None`

, then each edge has weight 1.

#### Output:β

`node: Vertex`

β‘ Node in graph for calculation of clustering`clustering: double`

β‘ Clustering coefficient at specified nodes.

#### Usage:β

`MATCH (n:SpecificLabel)`

WITH COLLECT(n) AS cluster_nodes

CALL nxalg.clustering(cluster_nodes) YIELD *

RETURN node, clustering;

`communicability()`

β

Returns communicability between all pairs of nodes in `G`

.

The *communicability* between pairs of nodes in `G`

is the sum of
closed walks of different lengths starting at node `u`

and ending at node `v`

.

#### Output:β

`node1: Vertex`

β‘ First value in communicability calculation`node2: Vertex`

β‘ Second value in communicability calculation`communicability: double`

β‘ Value of communicability between two values.

#### Usage:β

`CALL nxalg.communicability() YIELD *`

RETURN node1, node2, communicability

ORDER BY communicability DESC;

`core_number()`

β

Returns the core number for each vertex.

A *k-core* is a maximal subgraph that contains nodes of degree `k`

or more.

The core number of a node is the largest value `k`

of a k-core containing
that node.

#### Output:β

`node: Vertex`

β‘ Node to calculate k-core for`core: integer`

β‘ Largest value`k`

of a k-core

#### Usage:β

`CALL nxalg.core_number() YIELD *`

RETURN node, core

ORDER BY core DESC;

`degree_assortativity_coefficient(x, y, weight, nodes)`

β

Compute degree assortativity of a graph.

*Assortativity* measures the similarity of connections
in the graph with respect to the node degree.

#### Input:β

`x: string (default="out")`

β‘ The degree type for source node (directed graphs only). Can be "in" or "out".`y: string (default="in")`

β‘ The degree type for target node (directed graphs only). Can be "in" or "out".`weight: string (default=NULL)`

β‘ The edge attribute that holds the numerical value used as a weight. If`None`

, then each edge has weight 1. The degree is the sum of the edge weights adjacent to the node.`nodes: List[Vertex] (default=NULL)`

β‘ Compute degree assortativity only for nodes in a container. The default is all nodes.

#### Output:β

`assortativity: double`

β‘ Assortativity of graph by degree.

#### Usage:β

`CALL nxalg.degree_assortativity_coefficient('out', 'in') YIELD *`

RETURN assortativity;

`descendants(source)`

β

Returns all nodes reachable from `source`

in `G`

.

#### Input:β

`source: Vertex`

β‘ A node in`G`

.

#### Output:β

`descendants: List[Vertex]`

β‘ The descendants of`source`

in`G`

.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.descendants(source) YIELD *

RETURN descendants;

`dfs_postorder_nodes(source, depth_limit)`

β

Returns nodes in a depth-first-search post-ordering starting at source.

#### Input:β

`source: Vertex`

β‘ Specify the maximum search depth.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`nodes: List[Vertex]`

β‘ A list of nodes in a depth-first-search post-ordering.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dfs_postorder_nodes(source, 10) YIELD *

RETURN source, nodes;

`dfs_predecessors(source, depth_limit)`

β

Returns a dictionary of predecessors in depth-first-search from source.

#### Input:β

`source: Vertex`

β‘ Specify the maximum search depth.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`node: Vertex`

β‘ Node we are looking a predecessor for.`predecessor: Vertex`

β‘ predecessor of a given node.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dfs_predecessors(source, 10) YIELD *

RETURN node, predecessor;

`dfs_preorder_nodes(source, depth_limit)`

β

Returns nodes in a depth-first-search pre-ordering starting at source.

#### Input:β

`source: Vertex`

β‘ Specify starting node for depth-first search and return nodes in the component reachable from this node.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`nodes: List[Vertex]`

β‘ A list of nodes in a depth-first-search pre-ordering.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dfs_preorder_nodes(source, 10) YIELD *

RETURN source, nodes AS preoder_nodes;

`dfs_successors(source, depth_limit)`

β

Returns a dictionary of successors in depth-first-search from source.

#### Input:β

`source: Vertex`

β‘ Specify starting node for depth-first search and return nodes in the component reachable from this node.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`node: Vertex`

β‘ Node to calculate successors`successors: List[Vertex]`

β‘ Successors of a given nodes

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dfs_successors(source, 5) YIELD *

RETURN node, successors;

`dfs_tree(source, depth_limit)`

β

Returns an oriented tree constructed from a depth-first-search from source.

#### Input:β

`source: Vertex`

β‘ Specify starting node for depth-first search.`depth_limit: integer (default=NULL)`

β‘ Specify the maximum search depth.

#### Output:β

`tree: List[Vertex]`

β‘ An oriented tree in a form of a list.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dfs_tree(source, 7) YIELD *

RETURN tree;

`diameter()`

β

Returns the diameter of the graph `G`

.

The diameter is the maximum eccentricity.

#### Output:β

`diameter: integer`

β‘ Diameter of graph.

#### Usage:β

`CALL nxalg.diameter() YIELD *`

RETURN diameter;

`dominance_frontiers(start)`

β

Returns the dominance frontiers of all nodes of a directed graph.

The *dominance frontier* of a node `d`

is the set of all
nodes such that `d`

dominates an immediate
predecessor of a node, but `d`

does not strictly dominate that node.

#### Input:β

`start: Vertex`

β‘ The start node of dominance computation.

#### Output:β

`node: Vertex`

β‘ Node to calculate frontier.`frontier: List[Vertex]`

β‘ Dominance frontier for a given node.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dominance_frontiers(source) YIELD *

RETURN node, frontier;

`dominating_set(start)`

β

Finds a dominating set for the graph `G`

.

A *dominating set* for a graph with node set `V`

is a subset `D`

of
`V`

such that every node not in `D`

is adjacent to at least one
member of `D`

.

#### Input:β

`start: Vertex`

β‘ Node to use as a starting point for the algorithm.

#### Output:β

`dominating_set: List[Vertex]`

β‘ A dominating set for`G`

.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.dominating_set(source) YIELD *

RETURN dominating_set;

`edge_bfs(source, orientation)`

β

A directed, breadth-first-search of edges in `G`

, beginning at `source`

.

Return the edges of `G`

in a breadth-first-search order continuing until
all edges are generated.

#### Input:β

`source: Vertex`

β‘ The node from which the traversal begins. If`None`

, then a source is chosen arbitrarily and repeatedly until all edges from each node in the graph are searched.`orientation: string (default=NULL)`

β‘ For directed graphs and directed multigraphs, edge traversals need not respect the original orientation of the edges. When set to βreverseβ, every edge is traversed in the reverse direction. When set to βignoreβ, every edge is treated as undirected. When set to βoriginalβ, every edge is treated as directed. In all three cases, the returned edge tuples add a last entry to indicate the direction in which that edge was traversed. If`orientation`

is`None`

, the returned edge has no direction indicated. The direction is respected, but not reported.

#### Output:β

`edges: List[Edges]`

β‘ A directed edge indicating the path taken by the breadth-first-search. For graphs, edge is of the form`(u, v)`

where`u`

and`v`

are the tail and head of the edge as determined by the traversal. For multigraphs, edge is of the form`(u, v, key)`

, where`key`

is the key of the edge. When the graph is directed, then u and`v`

are always in the order of the actual directed edge. If`orientation`

is not`None`

then the edge tuple is extended to include the direction of traversal (βforwardβ or βreverseβ) on that edge.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.edge_bfs(source, 'ignore') YIELD *

RETURN source, edges;

`edge_dfs(source, orientation)`

β

A directed, depth-first-search of edges in `G`

, beginning at `source`

.

Return the edges of `G`

in a depth-first-search order continuing until
all edges are generated.

#### Input:β

`source: Vertex (default=NULL)`

β‘ The node from which the traversal begins. If`None`

, then a source is chosen arbitrarily and repeatedly until all edges from each node in the graph are searched.`orientation: string (default=NULL)`

β‘ For directed graphs and directed multigraphs, edge traversals need not respect the original orientation of the edges. When set to βreverseβ, every edge is traversed in the reverse direction. When set to βignoreβ, every edge is treated as undirected. When set to βoriginalβ, every edge is treated as directed. In all three cases, the returned edge tuples add a last entry to indicate the direction in which that edge was traversed. If`orientation`

is`None`

, the returned edge has no direction indicated. The direction is respected, but not reported.

#### Output:β

`edges: List[Edge]`

β‘ A directed edge indicating the path taken by the depth-first traversal. For graphs, edge is of the form`(u, v)`

where`u`

and`v`

are the tail and head of the edge as determined by the traversal. For multigraphs, edge is of the form`(u, v, key)`

, where`key`

is the key of the edge. When the graph is directed, then`u`

and`v`

are always in the order of the actual directed edge. If`orientation`

is not`None`

then the edge tuple is extended to include the direction of traversal (βforwardβ or βreverseβ) on that edge.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.edge_dfs(source, 'original') YIELD *

RETURN source, edges;

`find_cliques()`

β

Returns all maximal cliques in an undirected graph.

For each node `v`

, a *maximal clique* for `v`

is the largest complete
subgraph containing `v`

. The largest maximal clique is sometimes
called the *maximum clique*.

This function returns an iterator over cliques, each of which is a list of nodes. It is an iterative implementation, so should not suffer from recursion depth issues.

#### Output:β

`cliques: List[List[Vertex]]`

β‘ An iterator over maximal cliques, each of which is a list of nodes in`G`

. The order of cliques is arbitrary.

#### Usage:β

`CALL nxalg.find_cliques() YIELD *`

RETURN cliques;

`find_cycle(source, orientation)`

β

Returns a cycle found via depth-first traversal.

A *cycle* is a closed path in the graph.
The orientation of directed edges is determined by `orientation`

.

#### Input:β

`source: List[Vertex] (default=NULL)`

β‘ The node from which the traversal begins. If`None`

, then a source is chosen arbitrarily and repeatedly until all edges from each node in the graph are searched.`orientation: string (default=NULL)`

β‘ For directed graphs and directed multigraphs, edge traversals need not respect the original orientation of the edges. When set to βreverseβ every edge is traversed in the reverse direction. When set to βignoreβ, every edge is treated as undirected. When set to βoriginalβ, every edge is treated as directed. In all three cases, the yielded edge tuples add a last entry to indicate the direction in which that edge was traversed. If`orientation`

is`None`

, the yielded edge has no direction indicated. The direction is respected, but not reported.

#### Output:β

`(u, v)`

where`u`

and`v`

are the tail and the head of the edge as determined by the traversal. For multigraphs, an edge is of the form`(u, v, key)`

, where`key`

is the key of the edge. When the graph is directed, then`u`

and`v`

are always in the order of the actual directed edge. If`orientation`

is not`None`

then the edge tuple is extended to include the direction of traversal (βforwardβ or βreverseβ) on that edge.

#### Usage:β

`MATCH (source:Label)`

CALL nxalg.find_cycle(source) YIELD *

RETURN source, edges;

`flow_hierarchy(weight)`

β

Returns the flow hierarchy of a directed network.

*Flow hierarchy* is defined as the fraction of edges not participating in cycles in a directed graph.

#### Input:β

`weight: string (default=NULL)`

β‘ Attribute to use for node weights. If`None`

, the weight defaults to 1.

#### Output:β

`flow_hierarchy: double`

β‘ Flow hierarchy value.

#### Usage:β

`CALL nxalg.flow_hierarchy() YIELD *`

RETURN flow_hierarchy;

`global_efficiency()`

β

Returns the average global efficiency of the graph. The *efficiency* of a pair of nodes in a graph is the multiplicative inverse of the shortest path distance between the nodes. The *average global efficiency* of a graph is the average efficiency of all pairs of nodes.

#### Output:β

`global_efficiency: double`

β‘ The average global efficiency of the graph.

#### Usage:β

`CALL nxalg.global_efficiency() YIELD *`

RETURN global_efficiency;

`greedy_color(strategy, interchange)`

β

Color a graph using various strategies of greedy graph coloring. Attempts to color a graph using as few colors as possible, where no neighbors of a node can have the same color as the node itself. The given strategy determines the order in which nodes are colored.

#### Input:β

`strategy`

β‘ The parameter`function(G,colors)`

is a function (or a string representing a function) that provides the coloring strategy, by returning nodes in the order they should be colored.`G`

is the graph, and`colors`

is a dictionary of the currently assigned colors, keyed by nodes. The function must return an iterable over all the nodes in`G`

. If the strategy function is an iterator generator (a function with`yield`

statements), keep in mind that the`colors`

dictionary will be updated after each`yield`

, since this function chooses colors greedily. If`strategy`

is a string, it must be one of the following, each of which represents one of the built-in strategy functions.`'largest_first'`

`'random_sequential'`

`'smallest_last'`

`'independent_set'`

`'connected_sequential_bfs'`

`'connected_sequential_dfs'`

`'connected_sequential'`

(alias for the previous strategy)`'saturation_largest_first'`

`'DSATUR'`

(alias for the previous strategy)`interchange: boolean (default=False)`

β‘ Will use the color interchange algorithm if set to`True`

. Note that`saturation_largest_first`

and`independent_set`

do not work with interchange. Furthermore, if you use interchange with your own strategy function, you cannot rely on the values in the`colors`

argument.

#### Output:β

`node: Vertex`

β‘ Vertex to color.`color: integer`

β‘ Color index of a certain node.

#### Usage:β

`CALL nxalg.greedy_color('connected_sequential_bfs') YIELD *`

RETURN node, color;

`has_eulerian_path()`

β

An *Eulerian path* is a path in a graph that uses each edge of a graph exactly once.
A directed graph has an Eulerian path if:

- at most one vertex has
`out_degree - in_degree = 1`

, - at most one vertex has
`in_degree - out_degree = 1`

, - every other vertex has equal in_degree and out_degree,
- and all of its vertices with nonzero degree belong to a single connected component of the underlying undirected graph. An undirected graph has an Eulerian path if exactly zero or two vertices have an odd degree and all of its vertices with nonzero degrees belong to a single connected component.

#### Output:β

`has_eulerian_path: boolean`

β‘`True`

if`G`

has an eulerian path.

#### Usage:β

`CALL nxalg.has_eulerian_path() YIELD *`

RETURN has_eulerian_path;

`has_path(source, target)`

β

Returns `True`

if `G`

has a path from `source`

to `target`

.

#### Input:β

`source: Vertex`

β‘ Starting node for the path.`target: Vertex`

β‘ Ending node for the path.

#### Output:β

`has_path: boolean`

β‘`True`

if`G`

has a path from`source`

to`target`

.

#### Usage:β

`MATCH (n:Label), (m:Label)`

CALL nxalg.has_path(n, m) YIELD *

RETURN has_path;

`immediate_dominators(start)`

β

Returns the immediate dominators of all nodes of a directed graph. The immediate dominator of a node is the unique node that Strictly dominates a node `n`

but does not strictly dominate any other node That dominates `n`

.

#### Input:β

`start: Vertex`

β‘ The start node of dominance computation.

#### Output:β

`node: Vertex`

β‘ Vertex to calculate dominator for.`dominator: Vertex`

β‘ Dominator node for certain vertex.

#### Usage:β

`MATCH (n:Label)`

CALL nxalg.immediate_dominators(n) YIELD *

RETURN node, dominator;

`is_arborescence()`

β

Returns `True`

if `G`

is an arborescence. An *arborescence* is a directed tree with maximum in-degree equal to 1.

#### Output:β

`is_arborescence: boolean`

β‘ A boolean that is`True`

if`G`

is an arborescence.

#### Usage:β

`CALL nxalg.is_arborescence() YIELD *`

RETURN is_arborescence;

`is_at_free()`

β

Check if a graph is AT-free. The method uses the find_asteroidal_triple method to recognize an AT-free graph. If no asteroidal triple is found, the graph is AT-free and `True`

is returned. If at least one asteroidal triple is found, the graph is not AT-free and `False`

is returned.

#### Output:β

`is_at_free: boolean`

β‘`True`

if`G`

is AT-free and`False`

otherwise.

#### Usage:β

`CALL nxalg.is_at_free() YIELD *`

RETURN is_at_free;

`is_bipartite()`

β

Returns `True`

if graph `G`

is bipartite, `False`

if not. A *bipartite graph* (or bigraph) is a graph whose vertices can be divided into two disjoint and independent sets `u`

and `v`

and such that every edge connects a vertex in `u`

one in `v`

.

#### Output:β

`is_bipartite: boolean`

β‘`True`

if`G`

is bipartite and`False`

otherwise.

#### Usage:β

`CALL nxalg.is_bipartite() YIELD *`

RETURN is_bipartite;

`is_branching()`

β

Returns `True`

if `G`

is a branching. A *branching* is a directed forest with maximum in-degree equal to 1.

#### Output:β

`is_branching: boolean`

β‘ A boolean that is`True`

if`G`

is a branching.

#### Usage:β

`CALL nxalg.is_branching() YIELD *`

RETURN is_branching;

`is_chordal()`

β

Checks whether `G`

is a chordal graph. A graph is *chordal* if every cycle of length at least 4 has a chord (an edge joining two nodes not adjacent in the cycle).

#### Output:β

`is_chordal: boolean`

β‘`True`

if`G`

is a chordal graph and`False`

otherwise.

#### Usage:β

`CALL nxalg.is_chordal() YIELD *`

RETURN is_chordal;

`is_distance_regular()`

β

Returns `True`

if the graph is distance regular, `False`

otherwise. A connected graph `G`

is distance-regular if for any nodes `x,y`

and any integers `i,j=0,1,...,d`

(where `d`

is the graph diameter), the number of vertices at distance `i`

from `x`

and distance `j`

from `y`

depends only on `i,j`

and the graph distance between `x`

and `y`

, independently of the choice of `x`

and `y`

.

#### Output:β

`is_distance_regular: boolean`

β‘`True`

if the graph is Distance Regular,`False`

otherwise.

#### Usage:β

`CALL nxalg.is_distance_regular() YIELD *`

RETURN is_distance_regular;

`is_edge_cover(cover)`

β

Decides whether a set of edges is a valid edge cover of the graph. Given a set of edges, it can be decided whether the set is an *edge covering* if checked whether all nodes of the graph have an edge from the set incident on it.

#### Input:β

`cover: List[Edge]`

β‘ A list of edges to be checked.

#### Output:β

`is_edge_cover: boolean`

β‘ Whether the set of edges is a valid edge cover of the graph.

#### Usage:β

`MATCH (n)-[e]-(m)`

WITH COLLECT(e) AS cover

CALL nxalg.is_edge_cover(cover) YIELD *

RETURN is_edge_cover;

`is_eulerian()`

β

Returns `True`

if and only if `G`

is Eulerian. A graph is *Eulerian* if it has an Eulerian circuit. An *Eulerian circuit* is a closed walk that includes each edge of a graph exactly once.

#### Output:β

`is_eulerian: boolean`

β‘`True`

if`G`

is Eulerian.

#### Usage:β

`CALL nxalg.is_eulerian() YIELD *`

RETURN is_eulerian;

`is_forest()`

β

Returns `True`

if `G`

is a forest. A *forest* is a graph with no undirected cycles.
For directed graphs, `G`

is a forest if the underlying graph is a forest. The underlying graph is obtained by treating each directed edge as a single undirected edge in a multigraph.

#### Output:β

`is_forest: boolean`

β‘ A boolean that is`True`

if`G`

is a forest.

#### Usage:β

`CALL nxalg.is_forest() YIELD *`

RETURN is_forest;

`is_isolate(n)`

β

Determines whether a node is an isolate.
An *isolate* is a node with no neighbors (that is, with degree zero). For directed graphs, this means no in-neighbors and no out-neighbors.

#### Input:β

`n: Vertex`

β‘ A node in`G`

.

#### Output:β

`is_isolate: boolean`

β‘`True`

if and only if`n`

has no neighbors.

#### Usage:β

`MATCH (n)`

CALL nxalg.is_isolate(n) YIELD *

RETURN is_isolate;

`is_isomorphic(nodes1, edges1, nodes2, edges2)`

β

Returns `True`

if the graphs `G1`

and `G2`

are isomorphic and `False`

otherwise. The two graphs `G1`

and `G2`

must be the same type.

#### Input:β

`nodes1: List[Vertex]`

β‘ Nodes in`G1`

.`edges1: List[Edge]`

β‘ Edges in`G1`

.`nodes2: List[Vertex]`

β‘ Nodes in`G2`

.`edges2: List[Edge]`

β‘ Edges in`G2`

.

#### Output:β

`is_isomorphic: boolean`

β‘`True`

if the graphs`G1`

and`G2`

are isomorphic and`False`

otherwise.

#### Usage:β

`MATCH (n:Label1)-[e]-(), (r:Label2)-[f]-()`

WITH

COLLECT(n) AS nodes1

COLLECT(e) AS edges1

COLLECT(r) AS nodes2

COLLECT(f) AS edges2

CALL nxalg.is_isomorphic(nodes1, edges1, nodes2, edges2) YIELD *

RETURN is_isomorphic;

`is_semieulerian()`

β

Returns `True`

if `G`

is semi-Eulerian.

`G`

is semi-Eulerian if it has an Eulerian path but no Eulerian circuit.

#### Output:β

`is_semieulerian: boolean`

β‘`True`

if`G`

is semi-Eulerian.

#### Usage:β

`CALL nxalg.is_semieulerian() YIELD *`

RETURN is_semieulerian;

`is_simple_path(nodes)`

β

Returns `True`

if and only if the given nodes form a simple path in
`G`

.
A *simple path* in a graph is a nonempty sequence of nodes in which no node appears more than once in the sequence and each adjacent pair of nodes in the sequence is adjacent in the graph.

#### Input:β

`nodes: List[Vertex]`

β‘ A list of one or more nodes in the graph`G`

.

#### Output:β

`is_simple_path: boolean`

β‘ Whether the given list of nodes represents a simple path in`G`

.

#### Usage:β

`MATCH (n:Label)`

WITH COLLECT(n) AS nodes

CALL nxalg.is_simple_path(nodes) YIELD *

RETURN is_simple_path;

`is_strongly_regular()`

β

Returns `True`

if and only if the given graph is strongly regular.
An undirected graph is *strongly regular* if:

- it is regular,

- each pair of adjacent vertices has the same number of neighbors in common,

- each pair of nonadjacent vertices has the same number of neighbors in common. Each strongly regular graph is a distance-regular graph. Conversely, if a distance-regular graph has a diameter of two, then it is a strongly regular graph.

#### Output:β

`is_strongly_regular: boolean`

β‘ Whether`G`

is strongly regular.

#### Usage:β

`CALL nxalg.is_strongly_regular() YIELD *`

RETURN is_strongly_regular;

`is_tournament()`

β

Returns `True`

if and only if `G`

is a tournament.
A *tournament* is a directed graph, with neither self-loops nor multi-edges, in which there is exactly one directed edge joining each pair of distinct nodes.

#### Output:β

`is_tournament: boolean`

β‘ Whether the given graph is a tournament graph.

#### Usage:β

`CALL nxalg.is_tournament() YIELD *`

RETURN is_tournament;

`is_tree()`

β

Returns `True`

if `G`

is a tree.
A *tree* is a connected graph with no undirected cycles.
For directed graphs, `G`

is a tree if the underlying graph is a tree. The underlying graph is obtained by treating each directed edge as a single undirected edge in a multigraph.

#### Output:β

`is_tree: boolean`

β‘ A boolean that is`True`

if`G`

is a tree.

#### Usage:β

`CALL nxalg.is_tree() YIELD *`

RETURN is_tree;

`isolates()`

β

Returns a list of isolates in the graph.
An *isolate* is a node with no neighbors (that is, with degree zero). For directed graphs, this means no in-neighbors and no out-neighbors.

#### Output:β

`isolates: List[Vertex]`

β‘ A list of isolates in`G`

.

#### Usage:β

`CALL nxalg.isolates() YIELD *`

RETURN isolates;

`jaccard_coefficient(ebunch)`

β

Compute the Jaccard coefficient of all node pairs in `ebunch`

.

*Jaccard coefficient* compares members of two sets to see which members are shared and which are distinct.

#### Input:β

`ebunch: List[List[Vertex]] (default=NULL)`

β‘ Jaccard coefficient will be computed for each pair of nodes given in the iterable. The pairs must be given as 2-tuples`(u, v)`

where`u`

and`v`

are nodes in the graph. If`ebunch`

is`None`

then all non-existent edges in the graph will be used.

#### Output:β

`u: Vertex`

β‘ First node in pair.`v: Vertex`

β‘ Second node in pair.`coef: Vertex`

β‘ Jaccard coefficient.

#### Usage:β

`CALL nxalg.jaccard_coefficient() YIELD *`

RETURN u, v, coef;

`k_clique_communities(k, cliques)`

β

Find k-clique communities in a graph using the percolation method.
A *k-clique community* is the union of all cliques of size `k`

that can be reached through adjacent (sharing `k-1`

nodes) k-cliques.

#### Input:β

`k: integer`

β‘ Size of the smallest clique.`cliques: List[List[Vertex]] (default=NULL)`

β‘ Precomputed cliques (use networkx.find_cliques(G)).

#### Output:β

`communities: List[List[Vertex]]`

β‘ Sets of nodes, one for each k-clique community.

#### Usage:β

`CALL nxalg.k_clique_communities(3) YIELD *`

RETURN communities;

`k_components(density)`

β

Returns the approximate k-component structure of a graph `G`

.
A *k-component* is a maximal subgraph of a graph `G`

that has, at least, node connectivity `k`

: we need to remove at least `k`

nodes to break it into more components. k-components have an inherent hierarchical structure because they are nested in terms of connectivity: a connected graph can contain several 2-components, each of which can contain one or more 3-components, and so forth.
This implementation is based on the fast heuristics to approximate the k-component structure of a graph. This, in turn, is based on a fast approximation algorithm for finding good lower bounds of the number of node independent paths between two nodes.

#### Input:β

`min_density: double (default=0.95)`

β‘ Density relaxation threshold.

#### Output:β

`k: integer`

β‘ Connectivity level k`components: List[List[Vertex]]`

β‘ List of sets of nodes that form a k-component of level`k`

as values.

#### Usage:β

`CALL nxalg.k_components(0.8) YIELD *`

RETURN k, components;

`k_edge_components(k)`

β

Returns nodes in each maximal k-edge-connected component in `G`

.
A connected graph is *k-edge-connected* if it remains connected whenever fewer than k edges are removed. The edge-connectivity of a graph is the largest k for which the graph is k-edge-connected.

#### Input:β

`k: integer`

β‘ Desired edge connectivity.

#### Output:β

`components: List[List[Vertex]]`

β‘ A list of k-edge-ccs. Each set of returned nodes will have k-edge-connectivity in the graph`G`

.

#### Usage:β

`CALL nxalg.k_edge_components(3) YIELD *`

RETURN components;

`local_efficiency()`

β

Returns the average local efficiency of the graph.
The *efficiency* of a pair of nodes in a graph is the multiplicative inverse of the shortest path distance between the nodes. The *local efficiency* of a node in the graph is the average global efficiency of the subgraph induced by the neighbors of the node. The *average local efficiency* is the average of the local efficiencies of each node.

#### Output:β

`local_efficiency: double`

β‘ The average local efficiency of the graph.

#### Usage:β

`CALL nxalg.local_efficiency() YIELD *`

RETURN local_efficiency;

`lowest_common_ancestor(node1, node2)`

β

Compute the lowest common ancestor of the given pair of nodes.

#### Input:β

`node1: Vertex`

β‘ A node in the graph.`node2: Vertex`

β‘ A node in the graph.

#### Output:β

`ancestor: Vertex`

β‘ The lowest common ancestor of`node1`

and`node2`

, or default if they have no common ancestors.

#### Usage:β

`MATCH (n), (m)`

WHERE n != m

CALL nxalg.local_efficiency(n, m) YIELD *

RETURN n, m, ancestor;

`maximal_matching()`

β

A *matching* is a subset of edges in which no node occurs more than once. A *maximal matching* cannot add more edges and still be a matching.

#### Output:β

`edges: List[Edge]`

β‘ A maximal matching of the graph.

#### Usage:β

`CALL nxalg.maximal_matching() YIELD *`

RETURN edges;

`minimum_spanning_tree(weight, algorithm, ignore_nan)`

β

Returns a minimum spanning tree or forest on an undirected graph `G`

.
A *minimum spanning tree* is a subset of the edges of a connected, undirected graph that connects all of the vertices together without any cycles.

#### Input:β

`weight: string (default="weight")`

β‘ Data key to use for edge weights.`algorithm: string (default="kruskal")`

β‘ The algorithm to use when finding a minimum spanning tree. Valid choices are βkruskalβ, βprimβ, or βboruvkaβ.`ignore_nan: boolean (default=False)`

β‘ If`NaN`

is found as an edge weight normally an exception is raised. If`ignore_nan`

is`True`

then that edge is ignored.

#### Output:β

`node: List[Vertex]`

β‘ A minimum spanning tree or forest.`edges: List[Edge]`

β‘ A minimum spanning tree or forest.

#### Usage:β

`CALL nxalg.minimum_spanning_tree("weight", "prim", TRUE) YIELD *`

RETURN node, edges;

`multi_source_dijkstra_path(sources, cutoff, weight)`

β

Find shortest weighted paths in G from a given set of source nodes.

Compute shortest path between any of the source nodes and all other reachable nodes for a weighted graph.

#### Input:β

`sources: List[Vertex]`

β‘ Starting nodes for paths. If this is a set containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in the set, the computed paths may begin from any one of the start nodes.`cutoff: integer (default=NULL)`

β‘ Depth to stop the search. Only return paths with`length <= cutoff`

.`weight: string`

β‘ If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining`u`

to`v`

will be`G.edges[u, v][weight]`

). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number.

#### Output:β

`target: Vertex`

β‘ Target key for shortest path`path: List[Vertex]`

β‘ Shortest path in a list

#### Usage:β

`MATCH (n:Label)`

COLLECT (n) AS sources

CALL nxalg.multi_source_dijkstra_path(sources, 7) YIELD *

RETURN target, path;

`multi_source_dijkstra_path_length(sources, cutoff, weight)`

β

Find shortest weighted path lengths in `G`

from a given set of source nodes.

Compute the shortest path length between any of the source nodes and all other reachable nodes for a weighted graph.

#### Input:β

`sources: List[Vertex]`

β‘ Starting nodes for paths. If this is a set containing a single node, then all paths computed by this function will start from that node. If there are two or more nodes in the set, the computed paths may begin from any one of the start nodes.`cutoff: integer (default=NULL)`

β‘ Depth to stop the search. Only return paths with`length <= cutoff`

.`weight: string`

β‘ If this is a string, then edge weights will be accessed via the edge attribute with this key (that is, the weight of the edge joining`u`

to`v`

will be`G.edges[u, v][weight]`

). If no such edge attribute exists, the weight of the edge is assumed to be one. If this is a function, the weight of an edge is the value returned by the function. The function must accept exactly three positional arguments: the two endpoints of an edge and the dictionary of edge attributes for that edge. The function must return a number.

#### Output:β

`target: Vertex`

β‘ Target key for shortest path`length: double`

β‘ Shortest path length

#### Usage:β

`MATCH (n:Label)`

COLLECT (n) AS sources

CALL nxalg.multi_source_dijkstra_path_length(sources, 5) YIELD *

RETURN target, length;

`node_boundary(nbunch1, bunch2)`

β

Returns the node boundary of `nbunch1`

.
The *node boundary* of a set `S`

with respect to a set `T`

is the set of nodes `v`

in `T`

such that for some `u`

in `S`

, there is an edge joining `u`

to `v`

. If `T`

is not specified, it is assumed to be the set of all nodes not in `S`

.

#### Input:β

`nbunch1: List[Vertex]`

β‘ List of nodes in the graph representing the set of nodes whose node boundary will be returned. (This is the set`S`

from the definition above.)`nbunch2: List[Vertex] (default=NULL)`

β‘ List of nodes representing the target (or βexteriorβ) set of nodes. (This is the set`T`

from the definition above.) If not specified, this is assumed to be the set of all nodes in`G`

not in`nbunch1`

.

#### Output:β

`boundary: List[Vertex]`

β‘ The node boundary of`nbunch1`

with respect to`nbunch2`

.

#### Usage:β

`MATCH (n:Label)`

COLLECT (n) AS sources1

CALL nxalg.node_boundary(sources1) YIELD *

RETURN boundary;

`node_connectivity(source, target)`

β

Returns an approximation for node connectivity for a graph or digraph `G`

.

*Node connectivity* is equal to the minimum number of nodes that must be removed to disconnect `G`

or render it trivial. By Mengerβs theorem, this is equal to the number of node independent paths (paths that share no nodes other than `source`

and `target`

).
If `source`

and `target`

nodes are provided, this function returns the local node connectivity: the minimum number of nodes that must be removed to break all paths from source to `target`

in `G`

.
This algorithm is based on a fast approximation that gives a strict lower bound on the actual number of node independent paths between two nodes. It works for both directed and undirected graphs.

#### Input:β

`source: Vertex (default=NULL)`

β‘ Source node.`target: Vertex (default=NULL)`

β‘ Target node.

#### Output:β

`connectivity: integer`

β‘ Node connectivity of`G`

, or local node connectivity if`source`

and`target`

are provided.

#### Usage:β

`MATCH (n:Label), (m:Label)`

CALL nxalg.node_connectivity(n, m) YIELD *

RETURN connectivity;

`node_expansion(s)`

β

Returns the node expansion of the set `S`

.
The *node expansion* is the quotient of the size of the node boundary of `S`

and the cardinality of `S`

.

#### Input:β

`s: List[Vertex]`

β‘ A sequence of nodes in`G`

.

#### Output:β

`node_expansion: double`

β‘ The node expansion of the set`S`

.

#### Usage:β

`MATCH (n:Label)`

WITH COLLECT(n) AS s

CALL nxalg.node_expansion(s) YIELD *

RETURN node_expansion;

`non_randomness(k)`

β

Compute the non-randomness of graph `G`

.
The first returned value `non_randomness`

is the sum of non-randomness values of all edges within the graph (where the non-randomness of an edge tends to be small when the two nodes linked by that edge are from two different communities).
The second computed value `relative_non_randomness`

is a relative measure that indicates to what extent graph `G`

is different from random graphs in terms of probability. When it is close to 0, the graph tends to be more likely generated by an Erdos Renyi model.

#### Input:β

`k: integer (default=NULL)`

β‘ The number of communities in`G`

. If`k`

is not set, the function will use a default community detection algorithm to set it.

#### Output:β

`non_randomness: double`

β‘ Non-randomness of a graph`relative_non_randomness: double`

β‘ Relative non-randomness of a graph

#### Usage:β

`CALL nxalg.non_randomness() YIELD *`

RETURN non_randomness, relative_non_randomness;

`pagerank(alpha, personalization, max_iter, tol, nstart, weight, dangling)`

β

Returns the PageRank of the nodes in the graph.

PageRank computes a ranking of the nodes in the graph G based on the structure of the incoming links. It was originally designed as an algorithm to rank web pages.

#### Input:β

`alpha: double (default=0.85)`

β‘ Damping parameter for PageRank.`personalization: string (default=NULL)`

β‘ The βpersonalization vectorβ consisting of a dictionary with a subset of graph nodes as a key and maps personalization value for each subset. At least one personalization value must be non-zero. If not specified, a nodes personalization value will be zero. By default, a uniform distribution is used.`max_iter: integer (default=100)`

β‘ Maximum number of iterations in power method eigenvalue solver.`tol: double (default=1e-06)`

β‘ Error tolerance used to check convergence in power method solver.`nstart: string (default=NULL)`

β‘ Starting value of PageRank iteration for each node.`weight: string (default="weight")`

β‘ Edge data key to use as weight. If`None`

, weights are set to 1.`dangling: string (default=NULL)`

β‘ The outedges to be assigned to any βdanglingβ nodes, i.e., nodes without any outedges. The dict key is the node the outedge points to and the dict value is the weight of that outedge. By default, dangling nodes are given outedges according to the personalization vector (uniform if not specified). This must be selected to result in an irreducible transition matrix. It may be common to have the dangling dict to be the same as the personalization dict.

#### Output:β

`node: Vertex`

β‘ Vertex to calculate PageRank for.`rank: double`

β‘ Node PageRank.

#### Usage:β

`CALL nxalg.pagerank() YIELD *`

RETURN node, rank;

`reciprocity(nodes)`

β

Compute the reciprocity in a directed graph.
The *reciprocity* of a directed graph is defined as the ratio of the number of edges pointing in both directions to the total number of edges in the graph.
The reciprocity of a single node `u`

is defined similarly, it is the ratio of the number of edges in both directions to the total number of edges attached to node `u`

.

#### Input:β

`nodes: List[Vertex]`

β‘ Compute reciprocity for nodes in this container.

#### Output:β

`node: Vertex`

β‘ Node to calculate reciprocity.`reciprocity: double`

β‘ Reciprocity value

#### Usage:β

`MATCH(n:Label)`

WITH COLLECT(n) AS nodes

CALL nxalg.reciprocity(nodes) YIELD *

RETURN node, reciprocity;

`shortest_path(source, target, weight, method)`

β

Compute shortest paths in the graph.

#### Input:β

`source: Vertex (default=NULL)`

β‘ Starting node for the path. If not specified, compute shortest path lengths using all nodes as source nodes.`target: Vertex (default=NULL)`

β‘ Ending node for the path. If not specified, compute shortest path lengths using all nodes as target nodes.`weight: string (default=NULL)`

β‘ If`None`

, every edge has weight/distance/cost 1. If a string, use this edge attribute as the edge weight. Any edge attribute not present defaults to 1.`method: string (default="dijkstra")`

β‘ The algorithm to use to compute the path length. Supported options: βdijkstraβ, βbellman-fordβ. Other inputs produce a ValueError. If`weight`

is`None`

, unweighted graph methods are used and this suggestion is ignored.

#### Output:β

`source: Vertex`

β‘ Source node.`target: Vertex`

β‘ Target node.`path: List[Vertex]`

β‘ All returned paths include both the`source`

and`target`

in the path. If the`source`

and`target`

are both specified, return a single list of nodes in a shortest path from the`source`

to the`target`

. If only the`source`

is specified, return a dictionary keyed by targets with a list of nodes in a shortest path from the`source`

to one of the targets. If only the`target`

is specified, return a dictionary keyed by sources with a list of nodes in a shortest path from one of the sources to the`target`

. If neither the`source`

nor`target`

are specified return a dictionary of dictionaries with`path[source][target]=[list of nodes in path]`

.

#### Usage:β

`MATCH (n:Label), (m:Label)`

CALL nxalg.shortest_path(n, m) YIELD *

RETURN source, target, path;

`shortest_path_length(source, target, weight, method)`

β

Compute shortest path lengths in the graph.

#### Input:β

`source: Vertex (default=NULL)`

β‘ Starting node for the path. If not specified, compute shortest path lengths using all nodes as source nodes.`target: Vertex (default=NULL)`

β‘ Ending node for the path. If not specified, compute shortest path lengths using all nodes as target nodes.`weight: string (default=NULL)`

β‘ If`None`

, every edge has weight/distance/cost 1. If a string, use this edge attribute as the edge weight. Any edge attribute not present defaults to 1.`method: string (default="dijkstra")`

β‘ The algorithm to use to compute the path length. Supported options: βdijkstraβ, βbellman-fordβ. Other inputs produce a ValueError. If`weight`

is`None`

, unweighted graph methods are used and this suggestion is ignored.

#### Output:β

`source: Vertex`

β‘ Source node.`target: Vertex`

β‘ Target node.`length: double`

β‘ If the`source`

and`target`

are both specified, return the length of the shortest path from the`source`

to the`target`

. If only the`source`

is specified, return a dict keyed by`target`

to the shortest path length from the`source`

to that`target`

. If only the`target`

is specified, return a dict keyed by`source`

to the shortest path length from that`source`

to the`target`

. If neither the`source`

nor`target`

are specified, return an iterator over (source, dictionary) where dictionary is keyed by`target`

to shortest path length from`source`

to that`target`

.

#### Usage:β

`MATCH (n:Label), (m:Label)`

CALL nxalg.shortest_path_length(n, m) YIELD *

RETURN source, target, length;

`simple_cycles()`

β

Find simple cycles (elementary circuits) of a directed graph.
A *simple cycle*, or *elementary circuit*, is a closed path where no node appears twice. Two elementary circuits are distinct if they are not cyclic permutations of each other.
This is a nonrecursive, iterator/generator version of Johnsonβs algorithm. There may be better algorithms for some cases.

#### Output:β

`cycles: List[List[Vertex]]`

β‘ A list of elementary cycles in the graph. Each cycle is represented by a list of nodes in the cycle.

#### Usage:β

`CALL nxalg.simple_cycles() YIELD *`

RETURN cycles;

`strongly_connected_components()`

β

Returns nodes in strongly connected components of a graph.

#### Output:β

`components: List[List[Vertex]]`

β‘ A list of lists of nodes, one for each strongly connected component of`G`

.

#### Usage:β

`CALL nxalg.strongly_connected_components() YIELD *`

RETURN components;

`topological_sort()`

β

Returns nodes in topologically sorted order.
A *topological sort* is a non unique permutation of the nodes such that an edge from `u`

to `v`

implies that `u`

appears before `v`

in the topological sort order.

#### Output:β

`nodes: List[Vertex]`

β‘ A list of nodes in topological sorted order.

#### Usage:β

`CALL nxalg.topological_sort() YIELD *`

RETURN nodes;

`triadic_census()`

β

Determines the triadic census of a directed graph. The *triadic census* is a count of how many of the 16 possible types of triads are present in a directed graph.

#### Output:β

`triad: string`

β‘ Triad name.`count: integer`

β‘ Number of occurrences as value.

#### Usage:β

`CALL nxalg.triadic_census() YIELD *`

RETURN triad, count;

`voronoi_cells(center_nodes, weight)`

β

Returns the Voronoi cells centered at center_nodes with respect to the shortest-path distance metric.
If `C`

is a set of nodes in the graph and `c`

is an element of `C`

, the *Voronoi cell* centered at a node `c`

is the set of all nodes
`v`

that are closer to `c`

than to any other center node in `C`

with respect to the shortest-path distance metric.
For directed graphs, this will compute the βoutwardβ Voronoi cells in which distance is measured from the center nodes to the target node.

#### Input:β

`center_nodes: List[Vertex]`

β‘ A nonempty set of nodes in the graph`G`

that represent the centers of the Voronoi cells.`weight: string (default=NULL)`

β‘ The edge attribute (or an arbitrary function) representing the weight of an edge. This keyword argument is as described in the documentation for`networkx.multi_source_dijkstra_path`

, for example.

#### Output:β

`center: Vertex`

β‘ Vertex value of center_nodes.`cell: List[Vertex]`

β‘ Partition of`G`

closer to that center node.

#### Usage:β

`MATCH (n)`

WITH COLLECT(n) AS center_nodes

CALL nxalg.voronoi_cells(center_nodes) YIELD *

RETURN center, cell;

`wiener_index(weight)`

β

Returns the Wiener index of the given graph.
The *Wiener index* of a graph is the sum of the shortest-path distances between each pair of reachable nodes. For pairs of nodes in undirected graphs, only one orientation of the pair is counted.

#### Input:β

`weight: string (default=NULL)`

β‘ The edge attribute to use as distance when computing shortest-path distances. This is passed directly to the`networkx.shortest_path_length`

function.

#### Output:β

`wiener_index: double`

β‘ The Wiener index of the graph`G`

.

#### Usage:β

`CALL nxalg.voronoi_cells() YIELD *`

RETURN wiener_index;