Ejemplo n.º 1
0
        /// <summary> Construct the edge short cycles for the
        ///  given initial cycles. </summary>
        public EdgeShortCycles(InitialCycles initialCycles)
        {
            int[][] graph  = initialCycles.Graph;
            int[]   sizeOf = new int[initialCycles.GetNumberOfEdges()];

            this.paths = new List <int[]>(initialCycles.GetNumberOfCycles());

            // cycles are returned ordered by length
            foreach (var cycle in initialCycles.GetCycles())
            {
                int   length = cycle.Length;
                int[] path   = cycle.Path;

                bool found = false;

                // check if any vertex is the shortest through a vertex in the path
                for (int i = 1; i < path.Length; i++)
                {
                    int idx = initialCycles.IndexOfEdge(path[i - 1], path[i]);
                    if (sizeOf[idx] < 1 || length <= sizeOf[idx])
                    {
                        found       = true;
                        sizeOf[idx] = length;
                    }
                }

                if (found)
                {
                    foreach (var p in cycle.GetFamily())
                    {
                        paths.Add(p);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        public virtual void IndexOfEdge_K4()
        {
            InitialCycles initial = new InitialCycles(K4);

            Assert.AreEqual(0, initial.IndexOfEdge(0, 1));
            Assert.AreEqual(0, initial.IndexOfEdge(1, 0));
            Assert.AreEqual(1, initial.IndexOfEdge(0, 2));
            Assert.AreEqual(1, initial.IndexOfEdge(2, 0));;
            Assert.AreEqual(2, initial.IndexOfEdge(0, 3));
            Assert.AreEqual(2, initial.IndexOfEdge(3, 0));
            Assert.AreEqual(3, initial.IndexOfEdge(1, 2));
            Assert.AreEqual(3, initial.IndexOfEdge(1, 2));
            Assert.AreEqual(4, initial.IndexOfEdge(1, 3));
            Assert.AreEqual(4, initial.IndexOfEdge(1, 3));
            Assert.AreEqual(5, initial.IndexOfEdge(2, 3));
            Assert.AreEqual(5, initial.IndexOfEdge(2, 3));
        }