Esempio n. 1
0
 /** In case of a EQ, due to the instantion to one variable to val */
 public void filterOnInst(IntVar v, int val) throws ContradictionException {
   if (!v.contains(val + cste)) {
     v.instantiateTo(val - cste, this);
   } else if (!v.contains(val - cste)) {
     v.instantiateTo(val + cste, this);
   } else {
     if (v.hasEnumeratedDomain()) {
       DisposableRangeIterator rit = v.getRangeIterator(true);
       try {
         while (rit.hasNext()) {
           int from = rit.min();
           int to = rit.max();
           for (int value = from; value <= to; value++) {
             if (value != (val - cste) && value != (val + cste)) {
               v.removeValue(value, this);
             }
           }
           rit.next();
         }
       } finally {
         rit.dispose();
       }
     } else {
       v.updateBounds(val - cste, val + cste, this);
     }
   }
 }
Esempio n. 2
0
 /**
  * Set all variables to their respective value in the solution Throws an exception is this empties
  * a domain (i.e. this domain does not contain the solution value)
  *
  * <p>BEWARE: A restart might be required so that domains contain the solution values
  */
 public void restore(Solver solver) throws ContradictionException {
   if (empty) {
     throw new UnsupportedOperationException("Empty solution. No solution found");
   }
   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;
       switch (kind) {
         case Variable.INT:
         case Variable.BOOL:
           IntVar v = (IntVar) vars[i];
           int value = intmap.get(v.getId());
           if (value != NO_ENTRY) {
             v.instantiateTo(value, this);
           } // otherwise, this is not a decision variable
           break;
         case Variable.REAL:
           RealVar r = (RealVar) vars[i];
           double[] bounds = realmap.get(r.getId());
           if (bounds != null) {
             r.updateBounds(bounds[0], bounds[1], this);
           } // otherwise, this is not a decision variable
           break;
         case Variable.SET:
           SetVar s = (SetVar) vars[i];
           int[] values = setmap.get(s.getId());
           if (values != null) {
             s.instantiateTo(values, Cause.Null);
           } // otherwise, this is not a decision variable
           break;
       }
     }
   }
 }
Esempio n. 3
0
 private void filter() throws ContradictionException {
   buildSCC();
   int j, ub;
   IntVar v;
   for (int i = 0; i < n; i++) {
     v = vars[i];
     ub = v.getUB();
     for (int k = v.getLB(); k <= ub; k = v.nextValue(k)) {
       j = map.get(k);
       if (nodeSCC[i] != nodeSCC[j]) {
         if (digraph.getPredOf(i).contains(j)) {
           v.instantiateTo(k, this);
         } else {
           v.removeValue(k, this);
           digraph.removeArc(i, j);
         }
       }
     }
     if (!v.hasEnumeratedDomain()) {
       ub = v.getUB();
       for (int k = v.getLB(); k <= ub; k = v.nextValue(k)) {
         j = map.get(k);
         if (digraph.arcExists(i, j) || digraph.arcExists(j, i)) {
           break;
         } else {
           v.removeValue(k, this);
         }
       }
       int lb = v.getLB();
       for (int k = ub; k >= lb; k = v.previousValue(k)) {
         j = map.get(k);
         if (digraph.arcExists(i, j) || digraph.arcExists(j, i)) {
           break;
         } else {
           v.removeValue(k, this);
         }
       }
     }
   }
 }