An abstract class for constraint solvers. A solver is constructed with a {@linkplain Network constraint network} which is used by the solver to find solutions. Please note that any network can not be simultaneously shared by two different solvers. Solvers can be used in three typical ways. As a subroutine: {@link #FindFirst()}, {@link #FindBest()}, etc.
Solution solution = solver.FindFirst();
As a handler caller: {@link #FindAll(ISolutionHandler handler)}, etc.
solver.FindAll(new ISolutionHandler() { public synchronized void Solved(Solver solver, Solution solution) { ..... } });
As a coroutine: {@link #Start()}, {@link #WaitNext()}, {@link #Resume()}, {@link #Stop()}, etc.
for (solver.Start(); solver.WaitNext(); solver.Resume()) { Solution solution = solver.getSolution(); ..... } solver.Stop();
Inheritance: IThreadRunnable
Example #1
0
 public virtual void Solved(Solver solver, Solution sol)
 {
     lock (this)
     {
         if (Aborted || sol == null)
         {
             return ;
         }
         int oldBestValue = bestValue;
         solution = sol;
         Success();
         if (!(solver is LocalSearch))
             return ;
         if (network.Objective == null)
             return ;
         int objectiveIntValue = sol.ObjectiveIntValue;
         if (!IsBetter(objectiveIntValue, oldBestValue))
         {
             double rate;
             {
                 rate = ((LocalSearch) solver).ExchangeRate;
             }
             if (SupportClass.Random.NextDouble() < rate)
             {
                 //System.out.println(header + "Get " + best);
                 ((LocalSearch) solver).Candidate = bestSolution;
             }
         }
     }
 }
Example #2
0
 public ParallelSolver(Solver[] solvers, String name)
     : base(null, None, name)
 {
     this.solvers = solvers;
     network = solvers[0].network;
     option = solvers[0].option;
 }
Example #3
0
 public ParallelSolver(Solver[] solvers)
     : this(solvers, null)
 {
 }
Example #4
0
 private void InitBlock(Solver encloseInstance)
 {
     _enclosingInstance = encloseInstance;
 }
Example #5
0
 public HandlerInvoker(Solver enclosingInstance, ISolutionHandler handler, long timeout)
 {
     InitBlock(enclosingInstance);
     _handler = handler;
     _timeout = timeout;
 }
Example #6
0
 private void doItOnce()
 {
     Session.Clear();
     net = new Network();
     John = new AllenVariable(net, 0, 40, 30, "John");
     Mary = new AllenVariable(net, 35, 60, 20, "Mary");
     Wendy = new AllenVariable(net, 0, 60, 50, "Wendy");
     Soccer = new AllenVariable(net, 30, 135, 105, "Soccer");
     John.Equals(Mary);
     John.Starts(Mary);
     John.StartedBy(Mary);
     John.Meets(Mary);
     John.Equals(Wendy);
     John.Starts(Wendy);
     John.StartedBy(Wendy);
     John.Meets(Wendy);
     John.Overlaps(Soccer);
     Mary.Finishes(Wendy);
     Mary.FinishedBy(Wendy);
     Mary.During(Soccer);
     Mary.Contains(Soccer);
     AllenDomain ad0 = (AllenDomain)(John.Domain);
     AllenDomain ad1 = (AllenDomain)(Mary.Domain);
     AllenDomain ad2 = (AllenDomain)(Wendy.Domain);
     AllenDomain ad3 = (AllenDomain)(Soccer.Domain);
     solver = new AllenSolver(net);
     for (solver.Start(); solver.WaitNext(); solver.Resume())
     {
         solution = solver.Solution;
         Session["jd"] = ad0.Duration;
         Session["md"] = ad1.Duration;
         Session["wd"] = ad2.Duration;
         Session["sd"] = ad3.Duration;
         Session["js" + Convert.ToInt16(counter)] = solution.GetIntValue(John);
         Session["ms" + Convert.ToInt16(counter)] = solution.GetIntValue(Mary);
         Session["ws" + Convert.ToInt16(counter)] = solution.GetIntValue(Wendy);
         Session["ss" + Convert.ToInt16(counter)] = solution.GetIntValue(Soccer);
         Session["jp" + Convert.ToInt16(counter)] = ad0.Duration;
         Session["mp" + Convert.ToInt16(counter)] = ad1.Duration;
         Session["wp" + Convert.ToInt16(counter)] = ad2.Duration;
         Session["sp" + Convert.ToInt16(counter)] = ad3.Duration;
         Session["jn" + Convert.ToInt16(counter)] = solution.GetIntValue(John).ToString();
         Session["mn" + Convert.ToInt16(counter)] = solution.GetIntValue(Mary).ToString();
         Session["wn" + Convert.ToInt16(counter)] = solution.GetIntValue(Wendy).ToString();
         Session["sn" + Convert.ToInt16(counter)] = solution.GetIntValue(Soccer).ToString();
         counter += 1;
     }
     Session["done"] = true;
     Session["total"] = counter;
     Session["counter"] = 0;
     total.Text = "There are " + counter + " solutions";
     counter = 0;
     Display();
     Button1.Enabled = true;
     Button2.Enabled = true;
     Button3.Enabled = true;
     Button4.Enabled = true;
     if (Convert.ToInt16(Session["counter"]) == 0)
     {
         Button1.Enabled = false;
         Button2.Enabled = false;
     }
     if (Convert.ToInt16(Session["counter"]) == Convert.ToInt16(Session["total"]) - 1)
     {
         Button3.Enabled = false;
         Button4.Enabled = false;
     }
 }