コード例 #1
0
ファイル: MacRevised.java プロジェクト: rapodaca/cpsolver
 /**
  * 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;
 }
コード例 #2
0
 /**
  * With the given probabilty, a problematic student is randomly selected to be unassigned. Null is
  * returned otherwise.
  */
 @Override
 public Neighbour<Request, Enrollment> selectNeighbour(Solution<Request, Enrollment> solution) {
   if (!iProblemStudents.isEmpty() && Math.random() < iRandom) {
     Student student = ToolBox.random(iProblemStudents);
     iProblemStudents.remove(student);
     return new UnassignStudentNeighbour(student);
   }
   Progress.getInstance(solution.getModel()).incProgress();
   return null;
 }
コード例 #3
0
 /** Initialization -- {@link ProblemStudentsProvider#getProblemStudents()} is called */
 @Override
 public void init(Solver<Request, Enrollment> solver) {
   iProblemStudents = iProblemStudentsProvider.getProblemStudents();
   Progress.getInstance(solver.currentSolution().getModel())
       .setPhase("Random unassignment of problematic students...", 1);
 }