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. }
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"); } }
// 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"); } }
// 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"); } }
//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"); } }