Package solver.variables

Examples of solver.variables.IntVar


    } while (again);
  }

  protected void sortIt() {
    int n = vars.length;
    IntVar vt;
    for (int i = 0; i < n; i++) {
      vt = intervals[i].var;
      intervals[i].lb = vt.getLB();
      intervals[i].ub = vt.getUB();
    }
    sorter.sort(minsorted,n,SORT.MIN);
    sorter.sort(maxsorted,n,SORT.MAX);
    int min = minsorted[0].lb;
    int max = maxsorted[0].ub + 1;
View Full Code Here


                return true;
            } else {
                needFilter = false;
                if (IntEventType.isInstantiate(mask)) {
                    if (both.get(varIdx)) {
                        IntVar var = vars[varIdx];
                        int val = var.getValue();
                        if (setValues.contains(val)) {
                            LB.add(1);
                            both.set(varIdx, false);
                            needFilter = true;
                        } else {
View Full Code Here

    public void propagate(int evtmask) throws ContradictionException {
        if (PropagatorEventType.isFullPropagation(evtmask)) {
            int lb = 0;
            int ub = nb_vars;
            for (int i = 0; i < nb_vars; i++) {
                IntVar var = vars[i];
                int nb = 0;
                for (int j = 0; j < values.length; j++) {
                    nb += (var.contains(values[j]) ? 1 : 0);
                }
                occs[i].set(nb);
                if (nb == var.getDomainSize()) {
                    lb++;
                } else if (nb == 0) {
                    ub--;
                } else if (nb > 0) {
                    both.set(i, true);
View Full Code Here

     *
     * @throws ContradictionException if contradiction occurs.
     */
    private void removeOnlyValues() throws ContradictionException {
        for (int i = both.nextSetBit(0); i >= 0; i = both.nextSetBit(i + 1)) {
            IntVar v = vars[i];
            if (v.hasEnumeratedDomain()) {
                for (int value : values) {
                    if (v.removeValue(value, aCause)) {
                        occs[i].add(-1);
                    }
                }
            } else {
                int lb = v.getLB();
                int ub = v.getUB();
                int k1 = 0;
                int k2 = values.length - 1;
                // values is sorted
                // so first, find the first value inside dom(v)
                while (k1 < k2 && values[k1] < lb) {
                    k1++;
                }
                // and bottom-up shaving
                while (k1 <= k2 && v.removeValue(values[k1], aCause)) {
                    occs[i].add(-1);
                    k1++;
                }
                // then find the last value inside dom(v)
                while (k2 > k1 && values[k2] > ub) {
                    k2--;
                }
                // and top bottom shaving
                while (k2 >= k1 && v.removeValue(values[k2], aCause)) {
                    occs[i].add(-1);
                    k2--;
                }
            }
        }
View Full Code Here

    private void checkBounds() throws ContradictionException {
        List<ICounter> counters = pi.getCounters();
        int nbCounters = pi.getNbResources();
        for (int i = 0; i < nbCounters; i++) {
            IntVar z = this.z[i];
            Bounds bounds = counters.get(i).bounds();
            z.updateLowerBound(bounds.min.value, aCause);//, false);
            z.updateUpperBound(bounds.max.value, aCause);//, false);

        }
    }
View Full Code Here

            for (int i = 0; i < size; i++) {
                this.vars[i].duplicate(solver, identitymap);
                bVars[i] = (BoolVar) identitymap.get(this.vars[i]);
            }
            this.vars[size].duplicate(solver, identitymap);
            IntVar aVar = (IntVar) identitymap.get(this.vars[size]);
            identitymap.put(this, new PropEnumDomainChanneling(bVars, aVar, this.offSet));
        }
    }
View Full Code Here

     * @throws ContradictionException if contradiction occurs.
     */
    private void removeButValues() throws ContradictionException {
        int left, right;
        for (int i = both.nextSetBit(0); i >= 0; i = both.nextSetBit(i + 1)) {
            IntVar v = vars[i];
            DisposableValueIterator it = v.getValueIterator(true);
            left = right = Integer.MIN_VALUE;
            while (it.hasNext()) {
                int value = it.next();
                if (!setValues.contains(value)) {
                    if (value == right + 1) {
                        right = value;
                    } else {
                        v.removeInterval(left, right, aCause);
                        left = right = value;
                    }
                }
            }
            v.removeInterval(left, right, aCause);
            it.dispose();
        }
    }
View Full Code Here

        public void execute(int val) {
            if (p.both.get(varIdx)) {
                if (p.setValues.contains(val)) {
                    p.occs[varIdx].add(-1);
                }
                IntVar var = p.vars[varIdx];
                int nb = p.occs[varIdx].get();
                if (nb == var.getDomainSize()) {  //Can only be instantiated to a value in the group
                    p.LB.add(1);
                    p.both.set(varIdx, false);
//                    p.filter();
                    p.needFilter = true;
                } else if (nb == 0) { //No value in the group
View Full Code Here

    final int max_price = 24;

    // FD variables
    final IntVar[] kid_gift = VariableFactory.enumeratedArray("g2k", n_kids, 0, n_gifts, solver);
    final IntVar[] kid_price = VariableFactory.boundedArray("p2k", n_kids, min_price, max_price, solver);
    final IntVar total_cost = VariableFactory.bounded("total cost", min_price*n_kids, max_price * n_kids, solver);

    // CD variable
    double precision = 1.e-4;
    final RealVar average = VariableFactory.real("average", min_price, max_price, precision, solver);
    final RealVar average_deviation = VariableFactory.real("average_deviation", 0, max_price, precision, solver);

    // continuous views of FD variables
    RealVar[] realViews = VariableFactory.real(kid_price, precision);

    // kids must have different gifts
        solver.post(IntConstraintFactory.alldifferent(kid_gift, "AC"));
    // associate each kid with his gift cost
        for (int i = 0; i < n_kids; i++) {
            solver.post(IntConstraintFactory.element(kid_price[i], gift_price, kid_gift[i]));
        }
    // compute total cost
        solver.post(IntConstraintFactory.sum(kid_price, total_cost));

    // compute average cost (i.e. average gift cost per kid)
    RealVar[] allRV = ArrayUtils.append(realViews,new RealVar[]{average,average_deviation});
    solver.post(new RealConstraint(
        "Avg/AvgDev",
        "({0}+{1}+{2})/3={3};(abs({0}-{3})+abs({1}-{3})+abs({2}-{3}))/3={4}",
        allRV)
    );

    // set search strategy (ABS)
    solver.set(IntStrategyFactory.minDom_LB(kid_gift));
    // displays resolution statistics
    SearchMonitorFactory.log(solver,true,false);
    // print each solution
        solver.plugMonitor(new IMonitorSolution() {
            @Override
            public void onSolution() {
                if (LoggerFactory.getLogger("solver").isInfoEnabled()) {
                    LoggerFactory.getLogger("solver").info("*******************");
                    for (int i = 0; i < n_kids; i++) {
                        LoggerFactory.getLogger("solver").info("Kids #{} has received the gift #{} at a cost of {} euros",
                                new Object[]{i, kid_gift[i].getValue(), kid_price[i].getValue()});
                    }
                    LoggerFactory.getLogger("solver").info("Total cost: {} euros", total_cost.getValue());
          LoggerFactory.getLogger("solver").info("Average: {} euros per kid", average.getLB());
          LoggerFactory.getLogger("solver").info("Average deviation: {} ", average_deviation.getLB());
                }
            }
        });
View Full Code Here

        if (!identitymap.containsKey(this)) {
            set.duplicate(solver, identitymap);
            SetVar S = (SetVar) identitymap.get(set);

            iv.duplicate(solver, identitymap);
            IntVar I = (IntVar) identitymap.get(iv);

            identitymap.put(this, new PropIntMemberSet(S,I));
        }
    }
View Full Code Here

TOP

Related Classes of solver.variables.IntVar

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.