/// <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 solveProblemBAndB() {//O((2^(8n^2 + 9n + 2log(n)))(2^n)) == O((n^2)(2^n) BranchAndBound branchAndBoundAlgorithm = new BranchAndBound(); Route = branchAndBoundAlgorithm.RunTSP(Cities); bssf = new TSPSolution(Route); Program.MainForm.tbCostOfTour.Text = " " + bssf.costOfRoute(); Program.MainForm.tbElapsedTime.Text = branchAndBoundAlgorithm.bAndBTime.TotalSeconds.ToString(); Program.MainForm.tspOther.Text = "maxQueueCount: " + branchAndBoundAlgorithm.maxQueueCount + ", bssfUpdatesAmt: " + branchAndBoundAlgorithm.bssfUpdatesAmt + ", totalStatesCreated: " + branchAndBoundAlgorithm.totalStatesCreated + ", prunedAmt: " + branchAndBoundAlgorithm.prunedAmt + ", time: " + branchAndBoundAlgorithm.bAndBTime.TotalSeconds.ToString() + ", cost: " + bssf.costOfRoute(); // do a refresh. Program.MainForm.Invalidate(); }
public async Task CalculateBB() { ClearTextBox(); cts[4].Cancel(); cts[4] = new CancellationTokenSource(); progressBB.Visibility = Visibility.Visible; int maxTime; if (!Int32.TryParse(textB_timeBB.Text, out maxTime)) { textB_timeBB.Background = Brushes.Coral; errorTB.Push(textB_timeBB); return; } BranchAndBound algorithm = null; Stopwatch time = null; Location[] solve = null; Task thisTask = (Task.Run(() => { algorithm = new BranchAndBound(maxTime); time = new Stopwatch(); time.Start(); solve = algorithm.Solution(cities); time.Stop(); })); tasks.Enqueue(thisTask); await Task.Run(() => { while (true) { if (cts[4].Token.IsCancellationRequested || thisTask.IsCompleted) { break; } } }); if (solve != null) { DrawLines(solve, graphs[4]); timeBB.Content = time.ElapsedMilliseconds; lengthBB.Content = Math.Round(algorithm.TotalDistance, 2); } progressBB.Visibility = Visibility.Hidden; }
/// <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() { int x; Route = new ArrayList(); // this is the trivial solution. for (x = 0; x < Cities.Length; x++) { Route.Add(Cities[Cities.Length - x - 1]); } bssf = new TSPSolution(Route); double bssfCost = bssf.costOfRoute(); BranchAndBound bBound = new BranchAndBound(Cities, bssfCost); PathCalculation result = bBound.CalculatePath(); City[] path = result.Cities; if (path != null) { bssf = new TSPSolution(new ArrayList(path)); bssfCost = bssf.costOfRoute(); } // PLEASE NOTE: If the program times out, then the "TIMED OUT" flag will appear. Program.MainForm.tbElapsedTime.Text = (path == null && result.ElapsedTime > (30 * 1000) ? "TIMED OUT: " : "") + result.ElapsedTime / 1000; Program.MainForm.tbNumberOfSolutions.Text = (path == null ? 0 : result.NumberOfBSSFUpdates).ToString(); // update the cost of the tour. Program.MainForm.tbCostOfTour.Text = " " + bssfCost; // do a refresh. Program.MainForm.Invalidate(); }
/// <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() { int x; Route = new ArrayList(); // this is the trivial solution. for (x = 0; x < Cities.Length; x++) { Route.Add(Cities[Cities.Length - x -1]); } bssf = new TSPSolution(Route); double bssfCost = bssf.costOfRoute(); BranchAndBound bBound = new BranchAndBound(Cities, bssfCost); PathCalculation result = bBound.CalculatePath(); City[] path = result.Cities; if (path != null) { bssf = new TSPSolution(new ArrayList(path)); bssfCost = bssf.costOfRoute(); } // PLEASE NOTE: If the program times out, then the "TIMED OUT" flag will appear. Program.MainForm.tbElapsedTime.Text = (path == null && result.ElapsedTime > (30*1000) ? "TIMED OUT: " : "") + result.ElapsedTime / 1000; Program.MainForm.tbNumberOfSolutions.Text = (path == null ? 0 : result.NumberOfBSSFUpdates).ToString(); // update the cost of the tour. Program.MainForm.tbCostOfTour.Text = " " + bssfCost; // do a refresh. Program.MainForm.Invalidate(); }
/// <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 solveProblemBAndB() { //O((2^(8n^2 + 9n + 2log(n)))(2^n)) == O((n^2)(2^n) BranchAndBound branchAndBoundAlgorithm = new BranchAndBound(); Route = branchAndBoundAlgorithm.RunTSP(Cities); bssf = new TSPSolution(Route); Program.MainForm.tbCostOfTour.Text = " " + bssf.costOfRoute(); Program.MainForm.tbElapsedTime.Text = branchAndBoundAlgorithm.bAndBTime.TotalSeconds.ToString(); Program.MainForm.tspOther.Text = "maxQueueCount: " + branchAndBoundAlgorithm.maxQueueCount + ", bssfUpdatesAmt: " + branchAndBoundAlgorithm.bssfUpdatesAmt + ", totalStatesCreated: " + branchAndBoundAlgorithm.totalStatesCreated + ", prunedAmt: " + branchAndBoundAlgorithm.prunedAmt + ", time: " + branchAndBoundAlgorithm.bAndBTime.TotalSeconds.ToString() + ", cost: " + bssf.costOfRoute(); // do a refresh. Program.MainForm.Invalidate(); }