// finds the best tour possible using the branch and bound method of attack // For an example of what to return, see DefaultSolver.solve() method. public Problem solve() { Stopwatch timer = new Stopwatch(); timer.Start(); State beginningState = new State(cityData.size); SolverHelper.initializeState(beginningState, cityData); this.q.Enqueue(beginningState); Problem determineBSSFProblem = SolverHelper.clone(cityData); this.cityData.bssf = GreedySolver.solve(determineBSSFProblem).bssf; while (q.Count > 0) { recur(q.Dequeue()); //Clear out any states that have a BSSF less than //that of the current } timer.Stop(); cityData.timeElasped = timer.Elapsed; return(cityData); }
// finds the greedy tour starting from each city and keeps the best (valid) one // For an example of what to return, see DefaultSolver.solve() method. public static Problem solve(Problem cityData) { Stopwatch timer = new Stopwatch(); timer.Start(); State state = new State(cityData.size); SolverHelper.initializeState(state, cityData); state.currCityIndex = 0; recur(state); timer.Stop(); // Since cityData is static, it is pointing to the cityData object // that was passed in. Setting it's BSSF here will set the BSSF // of the cityData object in the Form1 class. cityData.bssf = new TSPSolution(cityData.cities, state.cityOrder, state.lowerBound); cityData.timeElasped = timer.Elapsed; cityData.solutions = 1; return(cityData); }