Package util.iterators

Examples of util.iterators.DisposableValueIterator


    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    private void onInstantiation0() throws ContradictionException {
        int left, right;
        int value = v0.getValue();
        DisposableValueIterator values = v1.getValueIterator(true);
        left = right = Integer.MIN_VALUE;
        try {
            while (values.hasNext()) {
                int val = values.next();
                if (!relation.isConsistent(value, val)) {
                    if (val == right + 1) {
                        right = val;
                    } else {
                        v1.removeInterval(left, right, this);
                        left = right = val;
                    }
                }
            }
            v1.removeInterval(left, right, this);
        } finally {
            values.dispose();
        }
    }
View Full Code Here


    }

    private void onInstantiation1() throws ContradictionException {
        int left, right;
        int value = v1.getValue();
        DisposableValueIterator values = v0.getValueIterator(true);
        left = right = Integer.MIN_VALUE;
        try {
            while (values.hasNext()) {
                int val = values.next();
                if (!relation.isConsistent(val, value)) {
                    if (val == right + 1) {
                        right = val;
                    } else {
                        v0.removeInterval(left, right, this);
                        left = right = val;
                    }
                }
            }
            v0.removeInterval(left, right, this);
        } finally {
            values.dispose();
        }
    }
View Full Code Here

     */
    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

    }

    @Override
    public void explain(VariableState what, Explanation to) {
        AntiDomain invdom = solver.getExplainer().getRemovedValues(this);
        DisposableValueIterator it = invdom.getValueIterator();
        while (it.hasNext()) {
            int val = it.next();
            if ((what == VariableState.LB && val < this.getLB())
                    || (what == VariableState.UB && val > this.getUB())
                    || (what == VariableState.DOM)) {
//                System.out.println("solver.explainer.explain(this,"+ val +") = " + solver.explainer.explain(this, val));
                to.add(solver.getExplainer().explain(this, val));
            }
        }
        it.dispose();
    }
View Full Code Here

    }

    @Override
    public DisposableValueIterator getValueIterator(boolean bottomUp) {
        if (_viterator == null || !_viterator.isReusable()) {
            _viterator = new DisposableValueIterator() {

                boolean _next;

                @Override
                public void bottomUpInit() {
View Full Code Here

    public void pruningPhase() throws ContradictionException {
        for (int i = 0; i < futureVars.size(); i++) {
            int vIdx = futureVars.get(i);
            IntVar v = vars[vIdx];
            DisposableValueIterator it3 = v.getValueIterator(true);
            int left = Integer.MIN_VALUE;
            int right = left;
            try {
                while (it3.hasNext()) {
                    int val = it3.next();
                    if (!gacValues[vIdx].get(val - offsets[vIdx])) {
                        if (val == right + 1) {
                            right = val;
                        } else {
                            v.removeInterval(left, right, this);
                            left = right = val;
                        }
                        //                        v.removeVal(val, this, false);
                    }
                }
                v.removeInterval(left, right, this);
            } finally {
                it3.dispose();
            }
        }
    }
View Full Code Here

    }

    @Override
    public DisposableValueIterator getValueIterator(boolean bottomUp) {
        if (_viterator == null || !_viterator.isReusable()) {
            _viterator = new DisposableValueIterator() {

                DisposableValueIterator vit;

                @Override
                public void bottomUpInit() {
View Full Code Here

     */
    public void initializeSupports(int indexVar) throws ContradictionException {
        int[] currentSupport;
        int val;
        if (vars[indexVar].hasEnumeratedDomain()) {
            DisposableValueIterator it = vars[indexVar].getValueIterator(true);
            int left = Integer.MIN_VALUE;
            int right = left;
            try {
                while (it.hasNext()) {
                    val = it.next();
                    if (lastSupport(indexVar, val)[0] == Integer.MIN_VALUE) { // no supports initialized yet for this value
                        currentSupport = seekNextSupport(indexVar, val);
                        if (currentSupport != null) {
                            setSupport(currentSupport);
                        } else {
                            if (val == right + 1) {
                                right = val;
                            } else {
                                vars[indexVar].removeInterval(left, right, this);
                                left = right = val;
                            }
                            //                        vars[indexVar].removeVal(val, this, false);
                        }
                    }
                }
                vars[indexVar].removeInterval(left, right, this);
            } finally {
                it.dispose();
            }
        } else {
            for (val = vars[indexVar].getLB(); val <= vars[indexVar].getUB(); val++) {
                currentSupport = seekNextSupport(indexVar, val);
                if (currentSupport != null) {
View Full Code Here

    // and remove unsupported values for variable
    public void reviseVar(int indexVar) throws ContradictionException {
        int[] currentSupport;
        int val;
        if (vars[indexVar].hasEnumeratedDomain()) {
            DisposableValueIterator it = vars[indexVar].getValueIterator(true);
            int left = Integer.MIN_VALUE;
            int right = left;
            try {
                while (it.hasNext()) {
                    val = it.next();
                    if (!isValid(lastSupport(indexVar, val))) {
                        currentSupport = seekNextSupport(indexVar, val);
                        if (currentSupport != null) {
                            setSupport(currentSupport);
                        } else {
                            if (val == right + 1) {
                                right = val;
                            } else {
                                vars[indexVar].removeInterval(left, right, this);
                                left = right = val;
                            }
                            //                            vars[indexVar].removeVal(val, this, false);
                        }
                    }
                }
                vars[indexVar].removeInterval(left, right, this);
            } finally {
                it.dispose();
            }
        } else {
            int[] inf_supports = lastBoundSupport(indexVar, 0);
            if (vars[indexVar].getLB() != inf_supports[indexVar] || !isValid(inf_supports)) {
                for (val = vars[indexVar].getLB(); val <= vars[indexVar].getUB(); val++) {
View Full Code Here

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    public void fastInitNbSupports(int a, int b) {
        DisposableValueIterator itv0 = v0.getValueIterator(true);
        int cpt1 = 0;
        while (itv0.hasNext()) {
            int val0 = itv0.next();
            cpt1++;
            DisposableValueIterator itv1 = v1.getValueIterator(true);
            int cpt2 = 0;
            while (itv1.hasNext()) {
                cpt2++;
                int val1 = itv1.next();
                if (relation.isConsistent(val0, val1)) {
                    initS0[val0 - offset0]++;
                    initS1[val1 - offset1]++;
                }
                if (cpt2 >= a) break;
            }
            itv1.dispose();
            if (cpt1 >= b) break;
        }
        itv0.dispose();
        minS0 = Integer.MAX_VALUE;
        minS1 = Integer.MAX_VALUE;
View Full Code Here

TOP

Related Classes of util.iterators.DisposableValueIterator

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.