MCPcopy
hub / github.com/networkx/networkx / eulerian_path

Function eulerian_path

networkx/algorithms/euler.py:335–386  ·  view source on GitHub ↗

Return an iterator over the edges of an Eulerian path in `G`. Parameters ---------- G : NetworkX Graph The graph in which to look for an eulerian path. source : node or None (default: None) The node at which to start the search. None means search over all sta

(G, source=None, keys=False)

Source from the content-addressed store, hash-verified

333
334@nx._dispatchable
335def eulerian_path(G, source=None, keys=False):
336 """Return an iterator over the edges of an Eulerian path in `G`.
337
338 Parameters
339 ----------
340 G : NetworkX Graph
341 The graph in which to look for an eulerian path.
342 source : node or None (default: None)
343 The node at which to start the search. None means search over all
344 starting nodes.
345 keys : Bool (default: False)
346 Indicates whether to yield edge 3-tuples (u, v, edge_key).
347 The default yields edge 2-tuples
348
349 Yields
350 ------
351 Edge tuples along the eulerian path.
352
353 Warning: If `source` provided is not the start node of an Euler path
354 will raise error even if an Euler Path exists.
355 """
356 if not has_eulerian_path(G, source):
357 raise nx.NetworkXError("Graph has no Eulerian paths.")
358 if G.is_directed():
359 G = G.reverse()
360 if source is None or nx.is_eulerian(G) is False:
361 source = _find_path_start(G)
362 if G.is_multigraph():
363 for u, v, k in _multigraph_eulerian_circuit(G, source):
364 if keys:
365 yield u, v, k
366 else:
367 yield u, v
368 else:
369 yield from _simplegraph_eulerian_circuit(G, source)
370 else:
371 G = G.copy()
372 if source is None:
373 source = _find_path_start(G)
374 if G.is_multigraph():
375 if keys:
376 yield from reversed(
377 [(v, u, k) for u, v, k in _multigraph_eulerian_circuit(G, source)]
378 )
379 else:
380 yield from reversed(
381 [(v, u) for u, v, k in _multigraph_eulerian_circuit(G, source)]
382 )
383 else:
384 yield from reversed(
385 [(v, u) for u, v in _simplegraph_eulerian_circuit(G, source)]
386 )
387
388
389@not_implemented_for("directed")

Callers

nothing calls this directly

Calls 8

has_eulerian_pathFunction · 0.85
_find_path_startFunction · 0.85
is_directedMethod · 0.45
reverseMethod · 0.45
is_multigraphMethod · 0.45
copyMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…