コード例 #1
0
        public MainForm()
        {
            InitializeComponent();

            if (!Settings.Default.LastSize.IsEmpty)
            {
                StartPosition = FormStartPosition.Manual;
                Location      = Settings.Default.LastLocation;
                Size          = Settings.Default.LastSize;
                splitContainer1.SplitterDistance = Settings.Default.SplitterPosition;
            }

            this.treeView1.AllowDrop     = true;
            this.graphControl1.AllowDrop = true;
            this.treeView1.MouseDown    += new MouseEventHandler(listBox1_MouseDown);
            this.treeView1.DragOver     += new DragEventHandler(listBox1_DragOver);

            this.graphControl1.DragEnter += new DragEventHandler(treeView1_DragEnter);
            this.graphControl1.DragDrop  += new DragEventHandler(treeView1_DragDrop);

            IDictionary <Guid, Type> filterTypes = FiltersHelper.GetFilterTypes();

            UpdateTreeView(filterTypes);

            if (File.Exists(PathToXml))
            {
                GraphBundle graphBundle = GraphLoader.Load(PathToXml);
                graphControl1.LoadGraph(graphBundle);
            }
            else
            {
                graphControl1.LoadGraph(new GraphBundle());
            }
        }
コード例 #2
0
        public void Load()
        {
            GraphLoader graphLoader = new GraphLoader();
            Graph       graph       = graphLoader.Load("AB200, BC100 ");

            Assert.IsNotNull(graph);
            var nodes = graph.GetNodes();

            CollectionAssert.AreEquivalent(new[] { "A", "B", "C" }.ToList(), nodes.ToList());

            var neighbors = graph.GetNeighbors("A").ToList();

            Assert.AreEqual(1, neighbors.Count);
            Assert.AreEqual("A", neighbors[0].FromNode);
            Assert.AreEqual("B", neighbors[0].ToNode);
            Assert.AreEqual(200, neighbors[0].Weight);
        }
コード例 #3
0
 private void LoadFile()
 {
     try
     {
         gr = GraphLoader.Load(fileName.Text);
         begSelector.Maximum = gr.GetLength(0);
         endSelector.Maximum = gr.GetLength(0);
         begSelector.Enabled = true;
         endSelector.Enabled = true;
         btnStart.Enabled    = true;
     }
     catch (Exception e)
     {
         begSelector.Enabled = false;
         endSelector.Enabled = false;
         btnStart.Enabled    = false;
     }
 }
コード例 #4
0
        public static void Main(string[] args)
        {
            var buildConfig = BuildConfiguration();
            var config      = buildConfig.GetSection(nameof(AppConfiguration));

            var dataPath         = config["data"];
            var resultPath       = config["results"];
            var graphEdges       = System.IO.Path.Combine(dataPath, config["graphEdges"]);
            var graphCoordinates = System.IO.Path.Combine(dataPath, config["graphCoordinates"]);

            var dataLoader = new GraphLoader(graphEdges, 100);
            var graph      = dataLoader.Load();

            var calculationStrategies = new ISimilarityCalculationStrategy[]
            { new EdgeSimillarityStrategy(), new NodeSimilarityStrategy() };

            var simpleSolver      = new TspSolver(graph);
            var localSearchSolver = new TspLocalSearchSolver(graph);
            var edgeFinder        = new GraspEdgeFinder(3);

            var evolutinarySolver = new EvolutionarySolver(graph,
                                                           new Recombinator(new SimilarityFinder(calculationStrategies), Steps, graph),
                                                           new Selector(), 41000);
            var localSearch = new LocalSearchAlgorithm(Steps, edgeFinder);

            var stats = new BasicSolverStatistics();

            var bestCost = int.MaxValue;
            ISolverStatistics bestStatistics = new BasicSolverStatistics();

            for (var i = 0; i < 10; i++)
            {
                var generatedPaths = simpleSolver.Solve(new RandomPathAlgorithm(Steps, edgeFinder));
                generatedPaths = localSearchSolver.Solve(localSearch, generatedPaths);

                evolutinarySolver.Solve(localSearch, generatedPaths);

                if (evolutinarySolver.SolvingStatistics.BestPath.Cost < bestCost)
                {
                    bestCost       = evolutinarySolver.SolvingStatistics.BestPath.Cost;
                    bestStatistics = evolutinarySolver.SolvingStatistics;
                }

                stats.UpdateSolvingResults(evolutinarySolver.SolvingStatistics.BestPath, evolutinarySolver.SolvingStatistics.MeanSolvingTime);
            }

            var statsPrinter = new FilePrinter(resultPath, "evo_stats.res");

            statsPrinter.Print(stats.ToString());

            var output = new StringBuilder();

            output.AppendLine($"{"Id".PadRight(4)}\tCost\tTime");
            for (var i = 0; i < bestStatistics.Costs.Count; i++)
            {
                output.AppendLine($"{i.ToString().PadRight(4)}\t{bestStatistics.Costs[i].ToString().PadRight(4)}\t{bestStatistics.SolvingTimes[i].Milliseconds:D}");
            }

            var evoResultsPrinter = new FilePrinter(resultPath, "evolutionary_results.res");

            evoResultsPrinter.Print(output.ToString());

            Console.WriteLine("Evolutionary solver ended his work!");
            //SimilaritySolver(resultPath, graph, calculationStrategies, edgeFinder);
        }