|
Aleph-w 3.0
A C++ Library for Data Structures and Algorithms
|
Eulerian paths/cycles in Aleph-w (eulerian.H) with classic demos and rich visual explanations.
More...
#include <iostream>#include <iomanip>#include <string>#include <map>#include <vector>#include <tclap/CmdLine.h>#include <tpl_graph.H>#include <eulerian.H>Go to the source code of this file.
Typedefs | |
| using | SNode = Graph_Node< string > |
| using | IArc = Graph_Arc< int > |
| using | UGraph = List_Graph< SNode, IArc > |
| using | DGraph = List_Digraph< SNode, IArc > |
Functions | |
| void | print_section (const string &title) |
| void | print_subsection (const string &title) |
| template<typename G > | |
| void | print_graph (const string &label, G &g) |
| void | demo_eulerian_cycle () |
| void | demo_konigsberg () |
| void | demo_directed () |
| void | demo_practical () |
| void | demo_hierholzer () |
| void | demo_eulerian_type () |
| int | main (int argc, char *argv[]) |
Eulerian paths/cycles in Aleph-w (eulerian.H) with classic demos and rich visual explanations.
This program demonstrates Eulerian paths and cycles.
It contains multiple demo sections (undirected, directed, historical example, algorithm walkthrough), selectable via the command line.
UGraph = List_Graph<Graph_Node<string>, Graph_Arc<int>>DGraph = List_Digraph<Graph_Node<string>, Graph_Arc<int>>string)int) used by the demoThis example uses TCLAP and a section selector:
--section / -s <section>: one of cycle, konigsberg, directed, practical, hierholzer, types, all (default).--help: show help.Why: to traverse every edge exactly once, every time you enter a vertex you must also leave it, except possibly at the start/end.
in-degree == out-degree, and(out-degree - in-degree) == 1 (start)(in-degree - out-degree) == 1 (end)in-degree == out-degreeTest_Eulerian performs a practical reachability check for Eulerian cycles in digraphs (among non-isolated vertices). For Eulerian paths in digraphs, the classification in this demo is based on in/out degree balance.Running time is linear in the number of edges.
The city of Königsberg had 7 bridges connecting 4 land areas:
Euler proved the requested walk is impossible because all 4 vertices have odd degree (more than two odd-degree vertices => no Eulerian path).
Modify (add one edge) to make exactly two vertices odd:
Let V be the number of vertices and E the number of edges.
O(V + E)O(E)Definition in file eulerian_example.C.
| using DGraph = List_Digraph<SNode, IArc> |
Definition at line 169 of file eulerian_example.C.
Definition at line 167 of file eulerian_example.C.
| using SNode = Graph_Node<string> |
Definition at line 166 of file eulerian_example.C.
| using UGraph = List_Graph<SNode, IArc> |
Definition at line 168 of file eulerian_example.C.
| void demo_directed | ( | ) |
Definition at line 350 of file eulerian_example.C.
References Aleph::maps(), print_section(), and print_subsection().
Referenced by main().
| void demo_eulerian_cycle | ( | ) |
Definition at line 221 of file eulerian_example.C.
References Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), Aleph::maps(), print_graph(), print_section(), and print_subsection().
Referenced by main().
| void demo_eulerian_type | ( | ) |
Definition at line 628 of file eulerian_example.C.
References Aleph::maps(), and print_section().
Referenced by main().
| void demo_hierholzer | ( | ) |
Definition at line 504 of file eulerian_example.C.
References Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_arc(), Aleph::List_Graph< _Graph_Node, _Graph_Arc >::insert_node(), Aleph::maps(), print_section(), print_subsection(), and Aleph::HTList::size().
Referenced by main().
| void demo_konigsberg | ( | ) |
Definition at line 291 of file eulerian_example.C.
References Aleph::maps(), print_section(), and test().
Referenced by main().
| void demo_practical | ( | ) |
Definition at line 422 of file eulerian_example.C.
References Aleph::maps(), print_graph(), print_section(), and print_subsection().
Referenced by main().
| int main | ( | int | argc, |
| char * | argv[] | ||
| ) |
Definition at line 691 of file eulerian_example.C.
References demo_directed(), demo_eulerian_cycle(), demo_eulerian_type(), demo_hierholzer(), demo_konigsberg(), demo_practical(), and Aleph::maps().
| void print_graph | ( | const string & | label, |
| G & | g | ||
| ) |
Definition at line 188 of file eulerian_example.C.
References Aleph::maps().
Referenced by demo_eulerian_cycle(), and demo_practical().
| void print_section | ( | const string & | title | ) |
Definition at line 175 of file eulerian_example.C.
References Aleph::maps().
Referenced by demo_directed(), demo_eulerian_cycle(), demo_eulerian_type(), demo_hierholzer(), demo_konigsberg(), and demo_practical().
| void print_subsection | ( | const string & | title | ) |
Definition at line 182 of file eulerian_example.C.
References Aleph::maps().
Referenced by demo_directed(), demo_eulerian_cycle(), demo_hierholzer(), and demo_practical().