@Override
 public void propagate(int evtmask) throws ContradictionException {
   int min = 0;
   int max = 0;
   ISet nodes = g.getPotentialNodes();
   for (int i = nodes.getFirstElement(); i >= 0; i = nodes.getNextElement()) {
     if (g.getMandSuccOrNeighOf(i).contain(i)) {
       min++;
       max++;
     } else if (g.getPotSuccOrNeighOf(i).contain(i)) {
       max++;
     }
   }
   k.updateLowerBound(min, aCause);
   k.updateUpperBound(max, aCause);
   if (min == max) {
     setPassive();
   } else if (k.isInstantiated()) {
     if (k.getValue() == max) {
       for (int i = nodes.getFirstElement(); i >= 0; i = nodes.getNextElement()) {
         if (g.getPotSuccOrNeighOf(i).contain(i)) {
           g.enforceArc(i, i, aCause);
         }
       }
       setPassive();
     } else if (k.getValue() == min) {
       for (int i = nodes.getFirstElement(); i >= 0; i = nodes.getNextElement()) {
         if (!g.getMandSuccOrNeighOf(i).contain(i)) {
           g.removeArc(i, i, aCause);
         }
       }
       setPassive();
     }
   }
 }
Beispiel #2
0
 @Override
 public ESat isEntailed() {
   if ((x.getUB() < y.getLB() + cste)
       || (x.getLB() > y.getUB() + cste)
       || x.hasEnumeratedDomain() && y.hasEnumeratedDomain() && !match()) return ESat.FALSE;
   else if (x.isInstantiated() && y.isInstantiated() && (x.getValue() == y.getValue() + cste))
     return ESat.TRUE;
   else return ESat.UNDEFINED;
 }
  @Test(groups = "1s", timeOut = 60000)
  public void testNominal() {
    Model model = new Model();

    IntVar var = model.intVar(10);
    SetVar setVar = model.setVar(new int[] {}, new int[] {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
    model.member(var, setVar).post();

    assertEquals(model.getSolver().isSatisfied(), ESat.UNDEFINED);
    checkSolutions(model, setVar, var.getValue());
  }
Beispiel #4
0
 /**
  * Get the value of variable v in this solution
  *
  * @param v IntVar (or BoolVar)
  * @return the value of variable v in this solution, or null if the variable is not instantiated
  *     in the solution
  */
 public Integer getIntVal(IntVar v) {
   if (empty) {
     throw new UnsupportedOperationException("Empty solution. No solution found");
   }
   if (intmap.containsKey(v.getId())) {
     return intmap.get(v.getId());
   } else {
     if ((v.getTypeAndKind() & Variable.TYPE) == Variable.CSTE) {
       return v.getValue();
     } else {
       return null;
     }
   }
 }
Beispiel #5
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.");
   }
 }
Beispiel #6
0
 @Override
 public ESat isEntailed() {
   double camax = capacity.getUB();
   double pomin = 0;
   for (int i = 0; i < n; i++) {
     camax -= weigth[i] * vars[i].getLB();
     pomin += energy[i] * vars[i].getLB();
   }
   if (camax < 0 || pomin > power.getUB()) {
     return ESat.FALSE;
   }
   if (isCompletelyInstantiated()) {
     if (pomin == power.getValue()) {
       return ESat.TRUE;
     }
   }
   return ESat.UNDEFINED;
 }
Beispiel #7
0
 @Override
 public ESat isEntailed() {
   int min = 0;
   int max = 0;
   int nbInst = vars[nb_vars].isInstantiated() ? 1 : 0;
   for (int i = 0; i < nb_vars; i++) {
     IntVar var = vars[i];
     if (var.isInstantiated()) {
       nbInst++;
       if (setValues.contains(var.getValue())) {
         min++;
         max++;
       }
     } else {
       int nb = 0;
       for (int j : values) {
         if (var.contains(j)) {
           nb++;
         }
       }
       if (nb == var.getDomainSize()) {
         min++;
         max++;
       } else if (nb > 0) {
         max++;
       }
     }
   }
   if (min > vars[nb_vars].getUB() || max < vars[nb_vars].getLB()) {
     return ESat.FALSE;
   }
   if (nbInst == nb_vars + 1) {
     return ESat.TRUE;
   }
   return ESat.UNDEFINED;
 }