MCPcopy
hub / github.com/networkx/networkx / eulerian_circuit

Function eulerian_circuit

networkx/algorithms/euler.py:159–236  ·  view source on GitHub ↗

Returns an iterator over the edges of an Eulerian circuit in `G`. An *Eulerian circuit* is a closed walk that includes each edge of a graph exactly once. Parameters ---------- G : NetworkX graph A graph, either directed or undirected. source : node, optional

(G, source=None, keys=False)

Source from the content-addressed store, hash-verified

157
158@nx._dispatchable
159def eulerian_circuit(G, source=None, keys=False):
160 """Returns an iterator over the edges of an Eulerian circuit in `G`.
161
162 An *Eulerian circuit* is a closed walk that includes each edge of a
163 graph exactly once.
164
165 Parameters
166 ----------
167 G : NetworkX graph
168 A graph, either directed or undirected.
169
170 source : node, optional
171 Starting node for circuit.
172
173 keys : bool
174 If False, edges generated by this function will be of the form
175 ``(u, v)``. Otherwise, edges will be of the form ``(u, v, k)``.
176 This option is ignored unless `G` is a multigraph.
177
178 Returns
179 -------
180 edges : iterator
181 An iterator over edges in the Eulerian circuit.
182
183 Raises
184 ------
185 NetworkXError
186 If the graph is not Eulerian.
187
188 See Also
189 --------
190 is_eulerian
191
192 Notes
193 -----
194 This is a linear time implementation of an algorithm adapted from [1]_.
195
196 For general information about Euler tours, see [2]_.
197
198 References
199 ----------
200 .. [1] J. Edmonds, E. L. Johnson.
201 Matching, Euler tours and the Chinese postman.
202 Mathematical programming, Volume 5, Issue 1 (1973), 111-114.
203 .. [2] https://en.wikipedia.org/wiki/Eulerian_path
204
205 Examples
206 --------
207 To get an Eulerian circuit in an undirected graph::
208
209 >>> G = nx.complete_graph(3)
210 >>> list(nx.eulerian_circuit(G))
211 [(0, 2), (2, 1), (1, 0)]
212 >>> list(nx.eulerian_circuit(G, source=1))
213 [(1, 2), (2, 0), (0, 1)]
214
215 To get the sequence of vertices in an Eulerian circuit::
216

Callers

nothing calls this directly

Calls 8

is_eulerianFunction · 0.85
arbitrary_elementFunction · 0.85
is_directedMethod · 0.45
reverseMethod · 0.45
copyMethod · 0.45
is_multigraphMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…