コード例 #1
0
ファイル: TimeTest.cs プロジェクト: kosmag/InterCol
        public void Test()
        {
            var columns = new string[5] {
                "Algorithm", "Vertices Count", "Edges Percent", "Calls Limit", "Time"
            };
            var separator = ",";
            var filePath  = "./times.csv";

            File.WriteAllText(filePath, string.Join(separator, columns) + Environment.NewLine);

            Stopwatch       stopwatch;
            UndirectedGraph graph, result;

            for (int i = 3; i < 8; i++)
            {
                for (double j = 0.2d; j < 0.8d; j += 0.2d)
                {
                    graph = GraphGenerator.Generate(i, j);
                    for (int k = 1; k <= 4; k++)
                    {
                        stopwatch = Stopwatch.StartNew();
                        result    = new EdgeAlgorithm(k).ColorGraph(graph);
                        stopwatch.Stop();
                        File.AppendAllText(filePath, string.Join(separator, "Edge", i, j.ToString(CultureInfo.InvariantCulture), k, stopwatch.ElapsedMilliseconds) + Environment.NewLine);

                        stopwatch = Stopwatch.StartNew();
                        result    = new MatchingAlgorithm(k).ColorGraph(graph);
                        stopwatch.Stop();
                        File.AppendAllText(filePath, string.Join(separator, "Matching", i, j.ToString(CultureInfo.InvariantCulture), k, stopwatch.ElapsedMilliseconds) + Environment.NewLine);
                    }
                }
            }
        }
コード例 #2
0
        public void EdgeAlgorithmColoringTests()
        {
            List <List <int> > handCheckedResults =
                new List <List <int> >()
            {
                new List <int>()
                {
                    5, 4, 4, 5, 3
                },
                new List <int>()
                {
                    7, 6, 8, 7, 6, 8, 7
                },
                new List <int>()
                {
                    6, 5, 4, 4, 5, 6
                },
                new List <int>()
                {
                    5, 4, 3, 2, 1
                },
                null,
                new List <int>()
                {
                    8, 6, 7, 5, 8, 6, 8, 7
                }
            };

            for (int ii = 1; ii <= handCheckedResults.Count; ii++)
            {
                var graph  = UndirectedGraph.Load(_graphPathCommon + "ColorTest" + ii.ToString() + ".txt");
                var result = new EdgeAlgorithm().ColorGraph(graph);
                if (handCheckedResults[ii - 1] == null)
                {
                    Assert.IsNull(result);
                    continue;
                }
                int colorIndex = 0;
                for (int i = 0; i < result.AdjacencyMatrix.GetLength(0); i++)
                {
                    for (int j = i + 1; j < result.AdjacencyMatrix.GetLength(0); j++)
                    {
                        if (result[i, j] == 1)
                        {
                            Assert.IsTrue(result.ColorMatrix[i, j] == handCheckedResults[ii - 1][colorIndex]);
                            colorIndex++;
                        }
                    }
                }
            }
        }