Example #1
0
        public void IsHamiltonianTwoVerticesFalse()
        {
            var g     = constructGraph(new Tuple <int, int>[] { new Tuple <int, int>(1, 1), new Tuple <int, int>(2, 2) });
            var gAlgo = new QuickGraph.Algorithms.IsHamiltonianGraphAlgorithm <int, UndirectedEdge <int> >(g);

            Assert.IsFalse(gAlgo.IsHamiltonian());
        }
Example #2
0
        public void IsHamiltonianOneVertexWithCycle()
        {
            var g     = constructGraph(new Tuple <int, int>[] { new Tuple <int, int>(1, 1) });
            var gAlgo = new QuickGraph.Algorithms.IsHamiltonianGraphAlgorithm <int, UndirectedEdge <int> >(g);

            Assert.IsTrue(gAlgo.IsHamiltonian());
        }
Example #3
0
        public void IsHamiltonianEmpty()
        {
            var g     = constructGraph(new Tuple <int, int>[] { });
            var gAlgo = new QuickGraph.Algorithms.IsHamiltonianGraphAlgorithm <int, UndirectedEdge <int> >(g);

            Assert.IsFalse(gAlgo.IsHamiltonian());
        }
Example #4
0
        public void IsHamiltonianWithParallelEdges()
        {
            var g = constructGraph(new Tuple <int, int>[] { new Tuple <int, int>(1, 2), new Tuple <int, int>(1, 2),
                                                            new Tuple <int, int>(3, 4), new Tuple <int, int>(3, 4) });
            var gAlgo = new QuickGraph.Algorithms.IsHamiltonianGraphAlgorithm <int, UndirectedEdge <int> >(g);

            Assert.IsFalse(gAlgo.IsHamiltonian());
        }
Example #5
0
        public void IsHamiltonian10VerticesDiracsTheorem()
        {
            // This graph is hamiltonian and satisfies Dirac's theorem. This test should work faster
            var g = constructGraph(new Tuple <int, int>[] { new Tuple <int, int>(1, 2),
                                                            new Tuple <int, int>(1, 3), new Tuple <int, int>(1, 4), new Tuple <int, int>(1, 7),
                                                            new Tuple <int, int>(1, 8), new Tuple <int, int>(1, 10), new Tuple <int, int>(2, 6),
                                                            new Tuple <int, int>(2, 9), new Tuple <int, int>(2, 4), new Tuple <int, int>(2, 5),
                                                            new Tuple <int, int>(3, 4), new Tuple <int, int>(3, 6), new Tuple <int, int>(3, 7),
                                                            new Tuple <int, int>(3, 8), new Tuple <int, int>(4, 6), new Tuple <int, int>(4, 5),
                                                            new Tuple <int, int>(4, 7), new Tuple <int, int>(5, 7), new Tuple <int, int>(5, 6),
                                                            new Tuple <int, int>(5, 9), new Tuple <int, int>(5, 10), new Tuple <int, int>(6, 9),
                                                            new Tuple <int, int>(6, 10), new Tuple <int, int>(6, 7), new Tuple <int, int>(7, 8),
                                                            new Tuple <int, int>(8, 9), new Tuple <int, int>(8, 10), new Tuple <int, int>(9, 10) });
            var gAlgo = new QuickGraph.Algorithms.IsHamiltonianGraphAlgorithm <int, UndirectedEdge <int> >(g);

            Assert.IsTrue(gAlgo.IsHamiltonian());
        }
Example #6
0
        public void IsHamiltonianTestCyclesBuilder()
        {
            var g = constructGraph(new Tuple <int, int>[] { new Tuple <int, int>(1, 2),
                                                            new Tuple <int, int>(1, 3), new Tuple <int, int>(1, 4), new Tuple <int, int>(1, 7),
                                                            new Tuple <int, int>(1, 8), new Tuple <int, int>(1, 10), new Tuple <int, int>(2, 6),
                                                            new Tuple <int, int>(2, 9), new Tuple <int, int>(2, 4),
                                                            new Tuple <int, int>(3, 4), new Tuple <int, int>(3, 6), new Tuple <int, int>(3, 7),
                                                            new Tuple <int, int>(3, 8), new Tuple <int, int>(4, 6), new Tuple <int, int>(4, 5),
                                                            new Tuple <int, int>(4, 7), new Tuple <int, int>(5, 7), new Tuple <int, int>(5, 6),
                                                            new Tuple <int, int>(5, 9), new Tuple <int, int>(5, 10), new Tuple <int, int>(6, 9),
                                                            new Tuple <int, int>(6, 10), new Tuple <int, int>(6, 7), new Tuple <int, int>(7, 8),
                                                            new Tuple <int, int>(8, 9), new Tuple <int, int>(8, 10), new Tuple <int, int>(9, 10) });
            var gAlgo = new QuickGraph.Algorithms.IsHamiltonianGraphAlgorithm <int, UndirectedEdge <int> >(g);

            var hashSet = new HashSet <List <int> >(new SequenceComparer <int>());

            hashSet.UnionWith(gAlgo.GetPermutations());

            Assert.AreEqual(hashSet.Count, Factorial(g.VertexCount));
        }