|
Algorithms_in_C++ 1.0.0
Set of algorithms implemented in C++.
|
The implementation of Hamilton's cycle dynamic solution for vertices number less than 20. More...
#include <cassert>#include <iostream>#include <vector>Functions | |
| bool | hamilton_cycle (const std::vector< std::vector< bool > > &routes) |
| static void | test1 () |
| static void | test2 () |
| static void | test3 () |
| int | main (int argc, char **argv) |
The implementation of Hamilton's cycle dynamic solution for vertices number less than 20.
I use \(2^n\times n\) matrix and for every \([i, j]\) ( \(i < 2^n\) and \(j < n\)) in the matrix I store true if it is possible to get to all vertices on which position in i's binary representation is 1 so as \(j\) would be the last one.
In the the end if any cell in \((2^n - 1)^{\mbox{th}}\) row is true there exists hamiltonian cycle.
| bool hamilton_cycle | ( | const std::vector< std::vector< bool > > & | routes | ) |
The function determines if there is a hamilton's cycle in the graph
| routes | nxn boolean matrix of \([i, j]\) where \([i, j]\) is true if there is a road from \(i\) to \(j\) |
true if there is Hamiltonian cycle in the graph false if there is no Hamiltonian cycle in the graph | int main | ( | int | argc, |
| char ** | argv | ||
| ) |
|
static |
this test is testing if hamilton_cycle returns true for graph: 1 -> 2 -> 3 -> 4
|
static |
this test is testing if hamilton_cycle returns false for
graph:
1 -> 2 -> 3
|
V
4
|
static |
this test is testing if hamilton_cycle returns true for clique with 4 vertices