Exemple #1
0
 /**
  * Records the current solution of the solver clears all previous recordings
  *
  * @param solver a solver
  */
 public void record(Solver solver) {
   if (empty) {
     Variable[] _dvars = solver.getStrategy().getVariables();
     for (int i = 0; i < _dvars.length; i++) {
       dvars.add(_dvars[i].getId());
     }
     empty = false;
   }
   boolean warn = false;
   intmap.clear();
   realmap.clear();
   setmap.clear();
   Variable[] vars = solver.getVars();
   for (int i = 0; i < vars.length; i++) {
     if ((vars[i].getTypeAndKind() & Variable.TYPE) != Variable.CSTE) {
       int kind = vars[i].getTypeAndKind() & Variable.KIND;
       if (!vars[i].isInstantiated()) {
         if (dvars.contains(vars[i].getId())) {
           throw new SolverException(vars[i] + " is not instantiated when recording a solution.");
         } else {
           warn = true;
         }
       } else {
         switch (kind) {
           case Variable.INT:
           case Variable.BOOL:
             IntVar v = (IntVar) vars[i];
             intmap.put(v.getId(), v.getValue());
             break;
           case Variable.REAL:
             RealVar r = (RealVar) vars[i];
             realmap.put(r.getId(), new double[] {r.getLB(), r.getUB()});
             break;
           case Variable.SET:
             SetVar s = (SetVar) vars[i];
             setmap.put(s.getId(), s.getValues());
             break;
         }
       }
     }
   }
   if (warn && solver.getSettings().warnUser()) {
     Chatterbox.err.printf(
         "Some non decision variables are not instantiated in the current solution.");
   }
 }
 /**
  * Use the last conflict heuristic as a pluggin to improve a former search heuristic STRAT
  *
  * @param SOLVER the solver
  * @return last conflict strategy
  */
 public static AbstractStrategy lastConflict(Solver SOLVER) {
   return lastConflict(SOLVER, SOLVER.getStrategy());
 }