![Page 1: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/1.jpg)
Constructing Hamiltonian
CircuitsWhen all nodes have degree of at least n/2
(Also: an implementation in C++ using Boost)Presented by Alan Hogan @ SUnMaRC, February
2008
![Page 2: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/2.jpg)
Graphs
•A graph is a collection of vertices (or points) and edges (which connect the vertices).
![Page 3: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/3.jpg)
Example Graph
Vertex
Edge
![Page 4: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/4.jpg)
Paths and Circuits
•Paths are series of vertices connected by edges
•A circuit is a closed path (starts & ends at the same vertex)
![Page 5: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/5.jpg)
Path Circuit
Start
End
Start
End
![Page 6: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/6.jpg)
Hamiltonian Circuits
•A Hamiltonian circuit is a closed path which visits every vertex in the graph exactly one time
•Also called “Hamiltonian Cycles”
![Page 7: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/7.jpg)
Plain Circuit Hamiltonian
![Page 8: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/8.jpg)
Problem
•General algorithms to find Hamiltonian circuits are slow, running in non-polynomial time — it is an NP-complete problem
•We can use an efficient algorithm, however, in some cases, thanks to Dirac and Ore...
![Page 9: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/9.jpg)
Dirac’s Theorem (1952)
•A simple graph with n vertices (n > 2) is Hamiltonian if each vertex has degree n/2 or greater.
•(sufficient but not necessary)
![Page 10: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/10.jpg)
Ore’s Theorem (1960)
•Generalization of Dirac’s Theorem
•If G is a simple graph with n vertices, where n ≥ 3, and if for each pair of non-adjacent vertices v and w, deg(v) + deg(w) ≥ n, then G is Hamiltonian
![Page 11: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/11.jpg)
Also in Ore’s paper...
•Ore’s restatement of Dirac’s principle lends itself to an interesting & useful principle
•For graphs satisfying the pre-requisite condition, an existing almost-complete Hamiltonian circuit with a gap between vertices A and B where there “should” be the final edge can be “repaired.”
![Page 12: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/12.jpg)
Using Ore’s Algorinthm
A
B
C
D
Missing edgeRepaired: Full circuit
1. Find a two vertices C & D s.t. edges (A,C) and (B,D) exist; (C,D) is in our almost-complete circuit; and D lies between C and A on the partial circuit.
2. Connect vertex A to vertex C
3. Connect vertex B to a vertex D
4. Remove the edge between those two earlier vertices.
![Page 13: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/13.jpg)
Why does that work?
•We know that at least one pair of such desirable contiguous earlier vertices C and D exist because each vertex has at least half as many edges as there are vertices
•Proof by the pigeonhole principle
•Boxes = potential pairs of vertices C & D = n−3
•Pigeons = edges from A or B = 2(n/2−1) = n−2
![Page 14: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/14.jpg)
AA BB
Worst case(Edges not connected to A or B and not
on the circuit are not depicted)
DD CC
![Page 15: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/15.jpg)
Repeated Use
•Repeated use of the algorithm suggested by Ore’s paper allows us to find a Hamiltonian circuit for any graph in our scope (all vertices have at least n/2 edges)
![Page 16: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/16.jpg)
Repeating the Algorithm
AA
BB
DD
CC
1.Pretend we have a circuit
2.Acknowledge one pretend edge does not really exist
3.Fix that edge. We have a pretend circuit again, but it’s closer to true
4.Go back to step 2. Repeat until all edges really exist
![Page 17: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/17.jpg)
Repeating the Algorithm
AA
BB
DD
CC1.Pretend we have a
circuit2.Acknowledge one
pretend edge does not really exist
3.Fix that edge. We have a pretend circuit again, but it’s closer to true
4.Go back to step 2. Repeat until all edges really exist
![Page 18: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/18.jpg)
Implementation
•The algorithm as discussed was slightly modified to use two graphs – the pretend circuit, and the true graph
•Implemented in C++ using the Boost graph library and Xcode
•Command-line only (but a GUI frontend could be constructed)
![Page 19: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/19.jpg)
Thank you.––––––
alanhogan.com/asu/hamiltonian-circuit
Read more about this project,download this presentation, or get a copy of the source code
online.
Made on a Mac
![Page 20: Constructing Hamiltonian Circuits When all nodes have degree of at least n/2 (Also: an implementation in C++ using Boost) Presented by Alan Hogan @ SUnMaRC,](https://reader035.vdocuments.us/reader035/viewer/2022062314/56649ec75503460f94bd2f27/html5/thumbnails/20.jpg)