Exemple #1
0
 public void propagate(Constraint<V, T> constraint, T noGoodValue, List<T> queue) {
   for (V aVariable : constraint.variables()) {
     if (aVariable.equals(noGoodValue.variable())) continue;
     for (Iterator<T> j = aVariable.values().iterator(); j.hasNext(); ) {
       T aValue = j.next();
       if (isGood(aValue)
           && constraint.isConsistent(noGoodValue, aValue)
           && !hasSupport(constraint, aValue, noGoodValue.variable())) {
         setNoGood(aValue, explanation(constraint, aValue, noGoodValue.variable()));
         queue.add(aValue);
       }
     }
   }
 }
Exemple #2
0
 public Set<T> supports(Constraint<V, T> constraint, T value, V variable) {
   Set<T> sup = new HashSet<T>();
   for (T aValue : variable.values()) {
     if (!isGood(aValue)) continue;
     if (!constraint.isConsistent(aValue, value)) continue;
     sup.add(aValue);
   }
   return sup;
 }
Exemple #3
0
 public Set<T> explanation(Constraint<V, T> constraint, T value, V variable) {
   Set<T> expl = new HashSet<T>();
   for (T aValue : variable.values()) {
     if (constraint.isConsistent(aValue, value)) {
       expl.addAll(noGood(aValue));
     }
   }
   return expl;
 }
 @Override
 public void unassigned(long iteration, ExamPlacement value) {
   super.unassigned(iteration, value);
   if (!isHard() && iIsSatisfied != isSatisfied()) {
     iIsSatisfied = !iIsSatisfied;
     ((ExamModel) value.variable().getModel())
         .addDistributionPenalty(iIsSatisfied ? -getWeight() : getWeight());
   }
 }
Exemple #5
0
 public boolean revise(Constraint<V, T> constraint, T value) {
   for (V aVariable : constraint.variables()) {
     if (aVariable.equals(value.variable())) continue;
     if (!hasSupport(constraint, value, aVariable)) {
       setNoGood(value, explanation(constraint, value, aVariable));
       return true;
     }
   }
   return false;
 }
Exemple #6
0
 public boolean hasSupport(Constraint<V, T> constraint, T value, V variable) {
   for (T aValue : variable.values()) {
     if (isGood(aValue) && constraint.isConsistent(aValue, value)) {
       // sLogger.debug("    -- "+variable.getName()+" = "+aValue.getName()+" supports "
       // +
       // value.variable().getName()+" = "+value.getName()+"
       // (constraint:"+constraint.getName()+")");
       return true;
     }
   }
   // sLogger.debug("    -- value "+value.variable().getName()+" = " +
   // value.getName()+" has no support from values of variable "+variable.getName()+"
   // (constraint:"+constraint.getName()+")");
   /*
    * for (Enumeration e=variable.values().elements();e.hasMoreElements();)
    * { T aValue = (T)e.nextElement(); if
    * (constraint.isConsistent(aValue,value)) {
    * //sLogger.debug("      -- support "
    * +aValue.getName()+" is not good: "+expl2str(noGood(aValue))); } }
    */
   return false;
 }