예제 #1
0
 private void ButtonOptimalClick(object sender, EventArgs e)
 {
     if (!backgroundWorker.IsBusy)
     {
         Buttons(false);
         _currentPath.Clear();
         _solver = new OptimalSolver(new object[] { _points, _currentPath, _optimalPath });
         backgroundWorker.RunWorkerAsync(_solver);
     }
 }
예제 #2
0
 private void ButtonAntClick(object sender, EventArgs e)
 {
     if (!backgroundWorker.IsBusy)
     {
         Buttons(false);
         _currentPath.Clear();
         double alfa, beta, ro;
         if (double.TryParse(textBoxAlfa.Text, out alfa) &&
             double.TryParse(textBoxBeta.Text, out beta) &&
             double.TryParse(textBoxRo.Text, out  ro))
         {
             _solver = new AntSystemSolver(new object[] { _points, _currentPath, Ants.Value, Iterations.Value, alfa, beta, ro, 1d });
             backgroundWorker.RunWorkerAsync(_solver);
         }
     }
 }
예제 #3
0
        /// <summary>
        ///  solve the problem.  This is the entry point for the solver when the run button is clicked
        /// right now it just picks a simple solution. 
        /// </summary>
        public void solveProblem(Solver solver)
        {
            Algorithms algo = new Algorithms();
            Stopwatch timer = new Stopwatch();
            timer.Restart();

            switch (solver)
            {
                case Solver.DEFAULT:
                    int x;
                    Route = new ArrayList();

                    // this is the trivial solution.
                    for (x = 0; x < Cities.Length; x++)
                    {
                        Route.Add(Cities[Cities.Length - x - 1]);
                    }
                    break;

                case Solver.RANDOM:
                    Route = algo.RandomSolution(Cities);
                    break;

                case Solver.GREEDY:
                    Route = algo.GreedySolution(Cities);
                    break;

                case Solver.BRANCH_BOUND:
                    double BSSF = double.PositiveInfinity;
                    Route = algo.GreedySolution(Cities);
                    TSPSolution greedyRoute = new TSPSolution(Route);
                    BSSF = greedyRoute.costOfRoute();
                    Route = algo.BranchAndBound(Cities, Route, BSSF);
                    break;

                case Solver.SIMANNEAL:
                    switch (Program.MainForm.saSource)
                    {
                            // Random
                        case 1:
                            //Route = algo.RandomSolution(Cities);
                            solveProblem(Solver.RANDOM);
                            break;

                            // Greedy
                        case 2:
                            //Route = algo.GreedySolution(Cities);
                            solveProblem(Solver.GREEDY);
                            break;

                            // Branch and Bound
                        case 3:
                            solveProblem(Solver.BRANCH_BOUND);
                            break;

                        default:
                            solveProblem(Solver.DEFAULT);
                            break;
                    }

                    Route = algo.SimulatedAnnealingSolution(Cities, Route);
                    break;

                default:
                    break;
            }

            timer.Stop();
            bssf = new TSPSolution(Route);

            Program.MainForm.tbCostOfTour.Text = " " + bssf.costOfRoute();
            Program.MainForm.tbElapsedTime.Text = timer.Elapsed.ToString();
            // do a refresh.
            Program.MainForm.tbElapsedTime.Text = " " + timer.Elapsed.TotalSeconds;
            Program.MainForm.Invalidate();
        }