Ejemplo n.º 1
0
            private List <NamedGraph> GetGraphSetFromSingleFile(string name, int count)
            {
                var cycleClustersAnalyzer = new CycleClustersAnalyzer <int>();
                var graphs = new List <NamedGraph>();
                var lines  = File.ReadAllLines($"Resources/RandomGraphs/{name}.txt");

                if (File.Exists($"Resources/RandomGraphs/{name}_{maxClusterSize}.txt"))
                {
                    lines = File.ReadAllLines($"Resources/RandomGraphs/{name}_{maxClusterSize}.txt");
                }

                var i           = 0;
                var lineCounter = 0;

                while (graphs.Count < count)
                {
                    if (lineCounter >= lines.Length)
                    {
                        break;
                    }

                    var graph = new UndirectedAdjacencyListGraph <int>();

                    // Add vertices
                    var verticesCount = int.Parse(lines[lineCounter++]);
                    for (var vertex = 0; vertex < verticesCount; vertex++)
                    {
                        graph.AddVertex(vertex);
                    }

                    // Add edges
                    while (true)
                    {
                        var line = lines[lineCounter++];

                        if (string.IsNullOrEmpty(line))
                        {
                            break;
                        }

                        var edge = line.Split(' ').Select(int.Parse).ToList();
                        graph.AddEdge(edge[0], edge[1]);
                    }

                    var clustersReport = cycleClustersAnalyzer.GetReport(graph);

                    if (clustersReport.MaxCyclesInCluster <= this.maxClusterSize)
                    {
                        graphs.Add(new NamedGraph(graph, $"{name} {i}"));
                    }

                    i++;
                }

                return(graphs);
            }
Ejemplo n.º 2
0
            protected override List <NamedGraph> GetGraphSet(string name, int count)
            {
                return(GetGraphSetFromSingleFile(name, count));

                var cycleClustersAnalyzer = new CycleClustersAnalyzer <int>();
                var graphs = new List <NamedGraph>();

                var i = 0;

                while (graphs.Count < count)
                {
                    var filename = $"Resources/RandomGraphs/{name}/{i}.txt";

                    if (!File.Exists(filename))
                    {
                        break;
                    }

                    var lines = File.ReadAllLines(filename);

                    var graph = new UndirectedAdjacencyListGraph <int>();

                    // Add vertices
                    var verticesCount = int.Parse(lines[0]);
                    for (var vertex = 0; vertex < verticesCount; vertex++)
                    {
                        graph.AddVertex(vertex);
                    }

                    // Add edges
                    for (var j = 1; j < lines.Length; j++)
                    {
                        var line = lines[j];
                        var edge = line.Split(' ').Select(int.Parse).ToList();
                        graph.AddEdge(edge[0], edge[1]);
                    }

                    var clustersReport = cycleClustersAnalyzer.GetReport(graph);

                    if (clustersReport.MaxCyclesInCluster <= this.maxClusterSize)
                    {
                        graphs.Add(new NamedGraph(graph, $"{name} {i}"));
                    }

                    i++;
                }

                return(graphs);
            }
 public void SetUp()
 {
     analyzer = new CycleClustersAnalyzer <int>();
 }
Ejemplo n.º 4
0
        protected override void Run()
        {
            var graphs = MapDescriptionLoader.GetGraphs();
            var cycleClustersAnalyzer    = new CycleClustersAnalyzer <int>();
            var nodesInsideCycleAnalyzer = new NodesInsideCycleAnalyzer <int>();

            //var benchmarkText =
            //    File.ReadAllText(
            //        @"D:\ProceduralLevelGenerator-data\Random\1583013308_FixedMaxIterationsEvolution_Time_edges_3_3_NewConfigurations - Copy.json");
            var benchmarkResult = JsonConvert.DeserializeObject <BenchmarkScenarioResult>(File.ReadAllText(
                                                                                              @"D:\ProceduralLevelGenerator-data\Random\1588689334_OldAndNew_edges_3_3\1588689334_OldAndNew_edges_3_3_ChainsAndMaxIterationAndTrees.json"));

            var correct = 0;
            var tp      = 0;
            var fp      = 0;
            var fn      = 0;

            var chainDecomposition = new BreadthFirstChainDecomposition <int>(new ChainDecompositionConfiguration()
            {
                // PreferSmallCycles = false,
            });

            for (var i = 0; i < graphs.Count; i++)
            {
                var namedGraph = graphs[i];
                var result     = benchmarkResult.BenchmarkResults[2 * i];

                var maxCyclesInClusterThreshold = 4;
                var nodesInsideThreshold        = 40;

                var clustersReport  = cycleClustersAnalyzer.GetReport(namedGraph.Graph);
                var maxClusterIndex = clustersReport.Clusters.MaxBy(x => x.Nodes.Count);
                var maxClusterSize  = clustersReport.Clusters[maxClusterIndex].Nodes.Count;

                var nodesInsideCycleReport = nodesInsideCycleAnalyzer.GetReport(namedGraph.Graph);

                Console.Write($"{namedGraph.Name.PadRight(15)}");

                Console.Write($"{clustersReport.MaxDensity,4:F}");

                if (clustersReport.MaxCyclesInCluster >= maxCyclesInClusterThreshold)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }

                Console.Write($"{clustersReport.MaxCyclesInCluster,3}");
                Console.ResetColor();

                Console.Write($"{maxClusterSize,3}");

                if (nodesInsideCycleReport.ProblemsCount >= nodesInsideThreshold)
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                }
                Console.Write($"{nodesInsideCycleReport.ProblemsCount,3}");
                Console.ResetColor();

                Console.Write($"{result.Runs.Average(x => x.Time),12:F}");

                var resultNok = result.Runs.Average(x => x.Time) > 5000;
                var reportNok = (clustersReport.MaxCyclesInCluster >= maxCyclesInClusterThreshold) || nodesInsideCycleReport.ProblemsCount >= nodesInsideThreshold;

                if (reportNok && resultNok)
                {
                    tp++;
                }

                if (reportNok && !resultNok)
                {
                    fp++;
                    Console.Write($"{"fp",3}");
                }

                if (!reportNok && resultNok)
                {
                    fn++;
                    Console.Write($"{"fn",3}");
                }
                else
                {
                    Console.Write("   ");
                }

                if (reportNok == resultNok)
                {
                    correct++;
                }

                if (i == 95)
                {
                    var s = 0;
                }
                var chains = chainDecomposition.GetChains(namedGraph.Graph);
                foreach (var chain in chains)
                {
                    Console.Write($" [{string.Join(",", chain.Nodes)}]");
                }

                Console.WriteLine();
            }

            Console.WriteLine();
            Console.WriteLine($"Total acc: {(correct / (double) graphs.Count * 100):F}%");
            Console.WriteLine($"Precision: {(tp / (double) (tp + fp) * 100):F}%");
            Console.WriteLine($"Recall: {(tp / (double) (tp + fn) * 100):F}%");
        }