Example #1
0
 /**
  * Creates a propagator for Among: Counts the number of decision variables which take a value in
  * the input value set
  *
  * @param variables {decision variables, cardinality variable}
  * @param values input value set
  */
 public PropAmongGAC(IntVar[] variables, int[] values) {
   super(variables, PropagatorPriority.LINEAR, true);
   nb_vars = variables.length - 1;
   IEnvironment environment = model.getEnvironment();
   this.setValues = new TIntHashSet(values);
   this.values = setValues.toArray();
   Arrays.sort(this.values);
   poss = SetFactory.makeStoredSet(SetType.BIPARTITESET, 0, model);
   nbSure = environment.makeInt(0);
 }
Example #2
0
 @Override
 public String toString() {
   return prob.getClass().getSimpleName()
       + " "
       + Arrays.toString(args)
       + " "
       + environment.getClass().getSimpleName()
       + " ";
 }
 /**
  * Define a way to initialize the propagation engine. Loops over the propagator of the solver,
  * then activate them one by one, if stateless, and call propagate after each propagator.
  *
  * @throws ContradictionException can throw a contradiction
  */
 public void propagate() throws ContradictionException {
   if (sta_propagators.size() > 0) {
     for (int p = 0; p < sta_propagators.size(); p++) {
       execute(sta_propagators.get(p), engine);
     }
     size -= sta_propagators.size();
     sta_propagators.clear();
   }
   if (perm_propagators.size() > 0) {
     int cw = environment.getWorldIndex(); // get current index
     for (int p = 0; p < perm_propagators.size(); p++) {
       if (perm_world.getQuick(p) >= cw) {
         execute(perm_propagators.get(p), engine);
         perm_world.replace(p, cw);
         // TODO: add a test on the root world to clear the list
       }
     }
   }
   /*if (tmp_propagators.size() > 0) {
       for (int p = 0; p < tmp_propagators.size(); p++) {
           Propagator propagator = tmp_propagators.get(p);
           execute(propagator, engine);
           tmp_propagators.remove(p);
           p--;
           size--;
           tmp_cstr.add(propagator.getConstraint());
       }
       for (final Constraint c : tmp_cstr) {
           // the constraint has been added during the resolution.
           // it should be removed on backtrack -> create a new undo operation
           environment.save(new Operation() {
               @Override
               public void undo() {
                   if (LoggerFactory.getLogger("solver").isDebugEnabled()) {
                       LoggerFactory.getLogger("solver").debug("unpost " + c);
                   }
                   solver.unpost(c);
               }
           });
       }
       tmp_cstr.clear();
   }*/
 }