Пример #1
0
 /**
  * Initialization. Enforce arc-consistency over the current (initial) solution. AC3 algorithm is
  * used.
  */
 @Override
 public boolean init(Solver<V, T> solver) {
   boolean isOk = true;
   iProgress = Progress.getInstance(getModel());
   iProgress.save();
   iProgress.setPhase("Initializing propagation:", getModel().variables().size());
   for (Iterator<V> i = getModel().variables().iterator(); i.hasNext(); ) {
     V aVariable = i.next();
     supportValues(aVariable).clear();
     goodValues(aVariable).clear();
   }
   List<T> queue = new ArrayList<T>();
   for (Iterator<V> i = getModel().variables().iterator(); i.hasNext(); ) {
     V aVariable = i.next();
     for (Iterator<T> j = aVariable.values().iterator(); j.hasNext(); ) {
       T aValue = j.next();
       initNoGood(aValue, null);
       goodValues(aVariable).add(aValue);
       if (revise(aValue)) {
         queue.add(aValue);
       } else if (aVariable.getAssignment() != null && !aValue.equals(aVariable.getAssignment())) {
         Set<T> noGood = new HashSet<T>();
         noGood.add(aVariable.getAssignment());
         setNoGood(aValue, noGood);
         queue.add(aValue);
       }
     }
     iProgress.incProgress();
   }
   propagate(queue);
   iProgress.restore();
   return isOk;
 }