Example #1
0
 /**
  * Creates a propagator ensuring that the graph induced by succs has nbCC connected components
  *
  * @param succs a set of integer variables
  * @param nbCC
  */
 public PropNbCC(IntVar<?>[] succs, IntVar<?> nbCC) {
   super(ArrayUtils.append(succs, new IntVar[] {nbCC}), PropagatorPriority.LINEAR, false);
   this.n = succs.length;
   this.succs = succs;
   this.nb = nbCC;
   this.g = new UndirectedGraph(n, SetType.BITSET, true);
   this.ccf = new ConnectivityFinder(g);
 }
Example #2
0
 public PropAbsolute(IntVar X, IntVar Y) {
   super(ArrayUtils.toArray(X, Y), PropagatorPriority.BINARY, false);
   this.X = vars[0];
   this.Y = vars[1];
   bothEnumerated = X.hasEnumeratedDomain() && Y.hasEnumeratedDomain();
   if (bothEnumerated) {
     rem_proc = new RemProc();
     this.idms = new IIntDeltaMonitor[this.vars.length];
     for (int i = 0; i < this.vars.length; i++) {
       idms[i] =
           vars[i].hasEnumeratedDomain()
               ? this.vars[i].monitorDelta(this)
               : IIntDeltaMonitor.Default.NONE;
     }
   }
 }
 /**
  * Links intVars and the graph arc (x,y)=var[x]=y values outside range [0,n-1] are not considered
  *
  * @param intVars
  * @param graph
  */
 public PropIntVarChanneling(IntVar[] intVars, DirectedGraphVar graph) {
   super(ArrayUtils.append(intVars, new Variable[] {graph}), PropagatorPriority.LINEAR, true);
   g = graph;
   gdm = (GraphDeltaMonitor) g.monitorDelta(this);
   this.intVars = intVars;
   this.idms = new IIntDeltaMonitor[intVars.length];
   for (int i = 0; i < intVars.length; i++) {
     idms[i] = intVars[i].monitorDelta(this);
   }
   this.n = g.getEnvelopGraph().getNbNodes();
   valRemoved = new ValRem();
   arcEnforced = new EnfArc();
   if (intVars[0].hasEnumeratedDomain()) {
     arcRemoved = new RemArcAC();
   } else {
     arcRemoved = new RemArcBC();
   }
 }
Example #4
0
 public PropIntersection(SetVar[] sets, SetVar intersection) {
   super(ArrayUtils.append(sets, new SetVar[] {intersection}), PropagatorPriority.LINEAR);
   k = sets.length;
   sdm = new SetDeltaMonitor[k + 1];
   for (int i = 0; i <= k; i++) {
     sdm[i] = this.vars[i].monitorDelta(this);
   }
   interRemToTreat = SetFactory.makeStoredSet(SetType.LINKED_LIST, 0, environment);
   setAddToTreat = SetFactory.makeStoredSet(SetType.LINKED_LIST, 0, environment);
   // PROCEDURES
   intersectionForced =
       new IntProcedure() {
         @Override
         public void execute(int element) throws ContradictionException {
           for (int i = 0; i < k; i++) {
             vars[i].addToKernel(element, aCause);
           }
         }
       };
   intersectionRemoved =
       new IntProcedure() {
         @Override
         public void execute(int element) throws ContradictionException {
           interRemToTreat.add(element);
         }
       };
   setForced =
       new IntProcedure() {
         @Override
         public void execute(int element) throws ContradictionException {
           if (!setAddToTreat.contain(element)) setAddToTreat.add(element);
         }
       };
   setRemoved =
       new IntProcedure() {
         @Override
         public void execute(int element) throws ContradictionException {
           vars[k].removeFromEnvelope(element, aCause);
         }
       };
 }
 /**
  * Global Cardinality Constraint (GCC) for integer variables foreach i, |{v = value[i] | for any v
  * in vars}|=cards[i]
  *
  * @param variables
  * @param value
  * @param cardinalities
  */
 public PropGCC_AC_Cards_AC(IntVar[] variables, int[] value, IntVar[] cardinalities) {
   super(ArrayUtils.append(variables, cardinalities), PropagatorPriority.QUADRATIC, true);
   if (value.length != cards.length) {
     throw new UnsupportedOperationException();
   }
   values = value;
   n = variables.length;
   this.cards = Arrays.copyOfRange(vars, variables.length, vars.length);
   map = new TIntIntHashMap();
   IntVar v;
   int ubtmp;
   int idx = n;
   boundedVariables = new TIntArrayList();
   for (int i = 0; i < n; i++) {
     v = vars[i];
     if (!v.hasEnumeratedDomain()) {
       boundedVariables.add(i);
     }
     ubtmp = v.getUB();
     for (int j = v.getLB(); j <= ubtmp; j = v.nextValue(j)) {
       if (!map.containsKey(j)) {
         map.put(j, idx);
         idx++;
       }
     }
   }
   for (int i = 0; i < value.length; i++) {
     if (!map.containsKey(value[i])) {
       map.put(value[i], idx);
       idx++;
     }
   }
   n2 = idx;
   fifo = new int[n2];
   digraph = new DirectedGraph(n2 + 1, SetType.LINKED_LIST, false);
   father = new int[n2];
   in = new BitSet(n2);
   SCCfinder = new StrongConnectivityFinder(digraph);
   //
   this.lb = new int[n2];
   this.ub = new int[n2];
   this.flow = new int[n2];
   for (int i = 0; i < n; i++) {
     ub[i] = lb[i] = 1; // 1 unit of flow per variable
   }
   for (int i = n; i < n2; i++) {
     ub[i] = n; // [0,n] units of flow per value (default)
   }
   for (int i = 0; i < value.length; i++) {
     idx = map.get(value[i]);
     int low = cards[i].getLB();
     int up = cards[i].getUB();
     if ((lb[idx] != 0 && lb[idx] != low) || (ub[idx] != n && ub[idx] != up)) {
       throw new UnsupportedOperationException(
           "error in the use of GCC: duplication of value " + value[i]);
     }
     lb[idx] = low;
     ub[idx] = up;
     if (low > up) {
       throw new UnsupportedOperationException("GCC error: low[i]>up[i]");
     }
   }
 }
Example #6
0
 public Count(int value, IntVar[] vars, IntVar limit, Solver solver) {
   super(ArrayUtils.append(vars, new IntVar[] {limit}), solver);
   this.occval = value;
   setPropagators(new PropCount_AC(vars, value, limit));
 }