Ejemplo n.º 1
0
        public static void CreateReportFromFile()
        {
            int[][] matrix = File.ReadAllLines("a.txt")
                             .Select(l => l.Split(' ').Select(i => int.Parse(i)).ToArray())
                             .ToArray();
            var graph = new EulerGraph(matrix.Length);

            for (int i = 0; i < matrix.Length; i++)
            {
                for (int j = 0; j < i; j++)
                {
                    if (matrix[i][j] != 0)
                    {
                        graph.AddEdge(i, j);
                    }
                }
            }
            var cycle = new int[graph._numberOfVertices];

            for (int i = 0; i < cycle.Length; i++)
            {
                cycle[i] = -1;
            }

            Console.WriteLine($"All Hamilton cycles");
            HamiltonCycle.FindAllHamiltonCycles(graph, cycle, true);

            Console.WriteLine($"Euler cycle: ");
            var eulerCycle = EulerCycle.FindEulerCycle(graph, 0);

            foreach (var item in eulerCycle)
            {
                Console.Write(item + " ");
            }
        }
Ejemplo n.º 2
0
        public int MeasureTime(string algorithm)
        {
            int[] visitedVertices = new int[_numberOfVertices];
            var   stopwatch       = new Stopwatch();

            stopwatch.Start();
            switch (algorithm)
            {
            case EulerGraph.EULER_CYCLE:
                EulerCycle.FindEulerCycle(this, 1);
                break;

            case EulerGraph.HAMILTON_CYCLE:
                visitedVertices.Select(vertice => vertice = -1);
                HamiltonCycle.FindHamiltonCycle(this, visitedVertices);
                break;

            case EulerGraph.ALL_HAMILTON_CYCLES:
                visitedVertices.Select(vertice => vertice = -1);
                HamiltonCycle.FindAllHamiltonCycles(this, visitedVertices);
                break;
            }
            stopwatch.Stop();
            return((int)stopwatch.ElapsedMilliseconds);
        }