public static void Main(String[] args) { Network net = new Network(); ft06(net); String solverName = "ibb"; int opt = Solver.Minimize; long timeout = 180000; if (args.Length >= 1) { solverName = args[0]; } Solver solver; if (solverName.Equals("bb")) { solver = new DefaultSolver(net, opt, "bb"); } else if (solverName.Equals("random")) { solver = new LocalSearch(net, opt, "rs"); } else if (solverName.Equals("sa")) { solver = new SimulatedAnneallingSearch(net, opt, "sa"); } else if (solverName.Equals("ibb")) { solver = new IterativeBranchAndBoundSearch(net, opt, "ibb"); } else if (solverName.Equals("taboo")) { solver = new TabooSearch(net, opt, "taboo"); } else { Solver sa = new SimulatedAnneallingSearch((Network)net.Clone(), opt, "sa"); Solver ibb = new IterativeBranchAndBoundSearch((Network)net.Clone(), opt, "ibb"); solver = new ParallelSolver(new Solver[] { sa, ibb }); } solver.SolverStrategy = Solver.StrategyMethod.Bisect; //Cream.Monitor monitor = new Monitor(); //monitor.setX(0, (int)(timeout / 1000)); //solver.setMonitor(monitor); Console.Out.WriteLine("Start " + solver + ", timeout = " + timeout + " msecs"); Solution bestSolution; int c = 0; if (true) { for (solver.Start(timeout); solver.WaitNext(); solver.Resume()) { Solution solution = solver.Solution; Console.Out.WriteLine(++c); Console.Out.WriteLine(solution); int value_Renamed = solution.ObjectiveIntValue; Console.Out.WriteLine(value_Renamed); Console.Out.WriteLine("======================="); } solver.Stop(); bestSolution = solver.BestSolution; } else { bestSolution = solver.FindBest(timeout); } Console.Out.WriteLine("Best = " + bestSolution.ObjectiveIntValue); Console.Out.WriteLine("Best = " + bestSolution); Console.In.ReadLine(); }
public static void Main(String[] args) { String problem = "ft10"; long timeout = 1000 * 60 * 10; String[] solverNames = new String[] { "sa", "ibb", "taboo" }; int i = 0; if (i < args.Length) { problem = args[i++]; } if (i < args.Length) { timeout = Int32.Parse(args[i++]) * 1000; } if (i < args.Length) { solverNames = new String[args.Length - i]; int j = 0; for (; i < args.Length; i++) { solverNames[j++] = args[i]; } } Network network = (new JSSPProblem(problem)).network(); if (network == null) { return; } //int opt = Solver.MINIMIZE | Solver.BETTER; int opt = Solver.Default; Solver[] solvers = new Solver[solverNames.Length]; for (i = 0; i < solvers.Length; i++) { String name = solverNames[i]; if (name.Equals("sa")) { solvers[i] = new SimulatedAnneallingSearch((Network)network.Clone(), opt, name); } else if (name.Equals("ibb")) { solvers[i] = new IterativeBranchAndBoundSearch((Network)network.Clone(), opt, name); } else if (name.Equals("taboo") || name.Equals("tabu")) { solvers[i] = new TabooSearch((Network)network.Clone(), opt, name); } else if (name.Equals("rw")) { solvers[i] = new LocalSearch((Network)network.Clone(), opt, name); } else { Console.Out.WriteLine("Unknown solver name " + name); solvers[i] = null; } } Solver all = new ParallelSolver(solvers); //Monitor monitor = new Monitor(); //monitor.setX(0, (int)(timeout/1000)); //all.setMonitor(monitor); //SolutionHandler sh=null; Solution solution = all.FindBest(timeout); Console.Out.WriteLine(solution); Console.In.ReadLine(); }
/// <summary> /// /// </summary> /// <param name="net"></param> /// <param name="course"></param> /// <param name="noOfCourses"></param> private void Solve(CourseNetwork net, IntVariable[] course, int noOfCourses) { //net.Objective = course[0]; Solver solver; if (radioButton6.Checked) { solver = new IterativeBranchAndBoundSearch(net, Solver.Minimize); } else if (radioButton4.Checked) { solver = new DefaultSolver(net, Solver.Minimize); solver.SolverStrategy = (Solver.StrategyMethod)numericUpDown3.Value; } else if (radioButton3.Checked) { //int opt = Solver.BETTER; solver = new TabooSearch(net, Solver.Minimize); } else { net.Objective = course[0]; solver = new SimulatedAnneallingSearch(net, Solver.Minimize); } long timer = DateTime.Now.Ticks; int count = 1; //StreamWriter sw = new StreamWriter(".\\out.txt"); DBSolution.DeleteAll(); Notes = new IList[(int)numericUpDown1.Value]; Solution bestSolution = null; for (solver.Start((long)numericUpDown2.Value); solver.WaitNext(); solver.Resume()) { Solution sol = solver.Solution; if (count == 1) { bestSolution = sol; } else { if (bestSolution != null) { if (sol.Weight > bestSolution.Weight) { bestSolution = sol; } } } Notes[count - 1] = new ArrayList { "Weight= " + sol.Weight + "\n" }; for (int i = 0; i < net.Professors.Count; i++) { int pcount = 0; for (int j = 0; j < net.Variables.Count; j++) { if (!((Variable)net.Variables[j]).IsValueType) { if (sol.GetIntValue(((Variable)net.Variables[j])) == i) { pcount++; } } } if (pcount < ((Professor)net.Professors[i]).RealNoOfCourses) { Notes[count - 1].Add("Prof. " + ((Professor)net.Professors[i]).ToString() + " not consistent.. needs " + (((Professor)net.Professors[i]).RealNoOfCourses - pcount) + " assignment(s) more!!" + "\n"); // sw.WriteLine("Prof. " + ((Professor)net.Professors[i]).toString() + " not consistent.. needs " + // (((Professor)net.Professors[i]).Courses - pcount) + " assignment(s) more!!"); } } Console.Out.WriteLine(); for (int i = 0; i < noOfCourses; i++) { //if (!((Variable)(net.Variables[i])).IsValueType) //{ //sw.WriteLine(course[i].Name + " = " + ((Professor)net.Professors[sol.getIntValue(course[i])]).Name); var dbSolution = new DBSolution { SolutionID = count, CourseName = course[i].Name, ProfessorName = ((Professor)net.Professors[sol.GetIntValue(course[i])]).Name }; dbSolution.AddSolution(); //} } //sw.WriteLine("================================="); count++; //if (solver is DefaultSolver) //{ if (count == numericUpDown1.Value + 1) { break; } //} //else //{ // break; //} } Console.WriteLine(bestSolution); timer = DateTime.Now.Ticks - timer; //sw.WriteLine("timer: " + timer); //sw.WriteLine("Count=" + count); //sw.Close(); solutionBS = new BindingSource(); if (count > 1) { solutionBS.DataSource = DBSolution.GetByID(1); bindingNavigator1.BindingSource = solutionBS; solutionViewGrid.DataSource = solutionBS; solIndex = 1; firstSol.Enabled = false; prevSol.Enabled = false; SolUpDown.Minimum = 1; SolUpDown.Maximum = count - 1; SolUpDown.Value = 1; SolUpDown.Enabled = true; if (count == 2) { nextSol.Enabled = false; lastSol.Enabled = false; } else { nextSol.Enabled = true; lastSol.Enabled = true; } } else { SolUpDown.Minimum = 0; SolUpDown.Maximum = 0; SolUpDown.Enabled = false; firstSol.Enabled = false; prevSol.Enabled = false; nextSol.Enabled = false; lastSol.Enabled = false; } label2.Text = ""; if (count > 1) { for (int y = 0; y < Notes[solIndex - 1].Count; y++) { label2.Text += Convert.ToString(Notes[solIndex - 1][y]); } } numberOfSolutions = count - 1; solutionViewGrid.Columns[2].Visible = false; if (timer / 10000 / 1000 == 0) { MessageBox.Show((count - 1) + " Solution(s) found in " + timer / 1000.0 + " MS"); } else { MessageBox.Show((count - 1) + " Solution(s) found in " + timer / 10000.0 / 1000 + " second(s)"); } }