networkx 2.8.2 Pypi GitHub Homepage
Other Docs
ParametersReturnsBackRef
has_eulerian_path(G, source=None)

An Eulerian path is a path in a graph which uses each edge of a graph exactly once. If :None:None:`source` is specified, then this function checks whether an Eulerian path that starts at node :None:None:`source` exists.

A directed graph has an Eulerian path iff:

  • 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 belong to a single connected component of the underlying undirected graph.

If :None:None:`source` is not None, an Eulerian path starting at :None:None:`source` exists if no other node has out_degree - in_degree = 1. This is equivalent to either there exists an Eulerian circuit or :None:None:`source` has out_degree - in_degree = 1 and the conditions above hold.

An undirected graph has an Eulerian path iff:

  • exactly zero or two vertices have odd degree,

  • and all of its vertices belong to a single connected component.

If :None:None:`source` is not None, an Eulerian path starting at :None:None:`source` exists if either there exists an Eulerian circuit or :None:None:`source` has an odd degree and the conditions above hold.

Graphs with isolated vertices (i.e. vertices with zero degree) are not considered to have an Eulerian path. Therefore, if the graph is not connected (or not strongly connected, for directed graphs), this function returns False.

Parameters

G : NetworkX Graph

The graph to find an euler path in.

source : node, optional

Starting node for path.

Returns

Bool : True if G has an Eulerian path.

Return True iff G has an Eulerian path.

See Also

eulerian_path
is_eulerian

Examples

If you prefer to allow graphs with isolated vertices to have Eulerian path, you can first remove such vertices and then call has_eulerian_path as below example shows.

>>> G = nx.Graph([(0, 1), (1, 2), (0, 2)])
... G.add_node(3)
... nx.has_eulerian_path(G) False
>>> G.remove_nodes_from(list(nx.isolates(G)))
... nx.has_eulerian_path(G) True
See :

Back References

The following pages refer to to this document either explicitly or contain code examples using this.

networkx.algorithms.euler.has_eulerian_path networkx.algorithms.euler.is_semieulerian

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/algorithms/euler.py#234
type: <class 'function'>
Commit: