MCPcopy
hub / github.com/networkx/networkx / is_eulerian

Function is_eulerian

networkx/algorithms/euler.py:22–70  ·  view source on GitHub ↗

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. Graphs with isolated vertices (i.e. vertices with zero degree) are not considered to have Eu

(G)

Source from the content-addressed store, hash-verified

20
21@nx._dispatchable
22def is_eulerian(G):
23 """Returns True if and only if `G` is Eulerian.
24
25 A graph is *Eulerian* if it has an Eulerian circuit. An *Eulerian
26 circuit* is a closed walk that includes each edge of a graph exactly
27 once.
28
29 Graphs with isolated vertices (i.e. vertices with zero degree) are not
30 considered to have Eulerian circuits. Therefore, if the graph is not
31 connected (or not strongly connected, for directed graphs), this function
32 returns False.
33
34 Parameters
35 ----------
36 G : NetworkX graph
37 A graph, either directed or undirected.
38
39 Examples
40 --------
41 >>> nx.is_eulerian(nx.DiGraph({0: [3], 1: [2], 2: [3], 3: [0, 1]}))
42 True
43 >>> nx.is_eulerian(nx.complete_graph(5))
44 True
45 >>> nx.is_eulerian(nx.petersen_graph())
46 False
47
48 If you prefer to allow graphs with isolated vertices to have Eulerian circuits,
49 you can first remove such vertices and then call `is_eulerian` as below example shows.
50
51 >>> G = nx.Graph([(0, 1), (1, 2), (0, 2)])
52 >>> G.add_node(3)
53 >>> nx.is_eulerian(G)
54 False
55
56 >>> G.remove_nodes_from(list(nx.isolates(G)))
57 >>> nx.is_eulerian(G)
58 True
59
60
61 """
62 if G.is_directed():
63 # Every node must have equal in degree and out degree and the
64 # graph must be strongly connected
65 return all(
66 G.in_degree(n) == G.out_degree(n) for n in G
67 ) and nx.is_strongly_connected(G)
68 # An undirected Eulerian graph has no vertices of odd degree and
69 # must be connected.
70 return all(d % 2 == 0 for v, d in G.degree()) and nx.is_connected(G)
71
72
73@nx._dispatchable

Callers 3

is_semieulerianFunction · 0.85
_find_path_startFunction · 0.85
eulerian_circuitFunction · 0.85

Calls 4

is_directedMethod · 0.45
in_degreeMethod · 0.45
out_degreeMethod · 0.45
degreeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…