Beispiel #1
0
        private void handleToolStripMenuClick(RunType runType)
        {
            this.reset();

            tbElapsedTime.Text = " Running...";
            tbCostOfTour.Text  = " Running...";
            Refresh();

            Solver solver;

            if (runType == RunType.BRANCH_AND_BOUND)
            {
                BranchAndBoundSolver babs = new BranchAndBoundSolver(CityData);
                CityData = babs.solve();
            }
            else if (runType == RunType.GREEDY)
            {
                CityData = GreedySolver.solve(CityData);
            }
            else if (runType == RunType.FANCY)
            {
                solver   = new FancySolver();
                CityData = solver.solve(CityData);
            }
            else  // runType == RunType.DEFAULT
            {
                solver   = new DefaultSolver();
                CityData = solver.solve(CityData);
            }

            tbCostOfTour.Text   = CityData.bssf.costOfRoute.ToString();
            tbElapsedTime.Text  = CityData.timeElasped.ToString();
            tbNumSolutions.Text = CityData.solutions.ToString();
            Invalidate();                          // force a refresh.
        }
Beispiel #2
0
        public static void bbHardBetterThanGreedy()
        {
            Problem cityData            = new Problem(1, 8, 60, HardMode.Modes.Hard);
            BranchAndBoundSolver solver = new BranchAndBoundSolver(cityData);

            cityData = solver.solve();
            if (cityData.bssf.costOfRoute != 3015)
            {
                throw new SystemException("Incorrect cost");
            }
        }
Beispiel #3
0
        // The last city is blocked
        // Ends up using the greedy value
        public static void bBHardLastCityBlocked()
        {
            Problem cityData            = new Problem(1, 5, 60, HardMode.Modes.Hard);
            BranchAndBoundSolver solver = new BranchAndBoundSolver(cityData);

            cityData = solver.solve();
            if (cityData.bssf.costOfRoute != 2123)
            {
                throw new SystemException("Incorrect cost");
            }
        }
Beispiel #4
0
        // There exists a better path than the greedy one
        public static void bBNormal()
        {
            Problem cityData            = new Problem(268, 16, 60, HardMode.Modes.Normal);
            BranchAndBoundSolver solver = new BranchAndBoundSolver(cityData);

            cityData = solver.solve();
            if (cityData.bssf.costOfRoute != 4069)
            {
                throw new SystemException("Incorrect cost");
            }
        }
Beispiel #5
0
        //This case should return the greedy value bc that is best
        public static void bBEasy()
        {
            Problem cityData            = new Problem(1, 5, 60, HardMode.Modes.Easy);
            BranchAndBoundSolver solver = new BranchAndBoundSolver(cityData);

            cityData = solver.solve();
            if (cityData.bssf.costOfRoute != 2060)
            {
                throw new SystemException("Incorrect cost");
            }
        }
Beispiel #6
0
        /// <summary>
        /// performs a Branch and Bound search of the state space of partial tours
        /// stops when time limit expires and uses BSSF as solution
        /// </summary>
        /// <returns>results array for GUI that contains three ints: cost of solution, time spent to find solution, number of solutions found during search (not counting initial BSSF estimate)</returns>
        public string[] bBSolveProblem()
        {
            string[] results = new string[3];

            //Find a smart starting bssf
            GreedySolver greedy = new GreedySolver(Cities, bssf, results);

            bssf = greedy.Solve();

            BranchAndBoundSolver brancher = new BranchAndBoundSolver(Cities, bssf, results, time_limit);

            bssf = brancher.Solve();

            return(results);
        }