Package solver.search.strategy.decision

Examples of solver.search.strategy.decision.Decision


        // 1. try by relaxing from the cluster
        if (cluster < clusters.size()) {
            int k = cluster++;
            if (k < clusters.size()) {
                for (int i = clusters.get(k - 1); i < clusters.get(k); i++) {
                    Decision dec = valueDecisions.get(i);
                    int idx = path.indexOf(dec);
                    notFrozen.clear(idx);
                }
            }
        } else {
View Full Code Here


    /**
     * Compute the initial fragment, ie set of decisions to keep.
     */
    private void clonePath() {
        Decision dec = mSolver.getSearchLoop().getLastDecision();
        while ((dec != RootDecision.ROOT)) {
            addToPath(dec);
            dec = dec.getPrevious();
        }
        Collections.reverse(path);
        int size = path.size();
        for (int i = 0, mid = size >> 1, j = size - 1; i < mid; i++, j--) {
            boolean bi = related2dom.get(i);
View Full Code Here

     * Add a copy of the current decision to path
     *
     * @param dec a decision of the current decision path
     */
    private void addToPath(Decision dec) {
        Decision clone = dec.duplicate();
        path.add(clone);
        int pos = path.size() - 1;
        if (dec.hasNext()) {
            int idx = valueDecisions.indexOf(dec);
            if (idx > -1) {
View Full Code Here

            super.updateVRExplainUponbacktracking(nworld, expl, cause);
        }
        cobdec.clearDecisionPath();

        // preliminary : compute where to jump back
        Decision dec = mSolver.getSearchLoop().getLastDecision(); // the current decision to undo
        int myworld = nworld;
        while (dec != RootDecision.ROOT && myworld > 1) {
            dec = dec.getPrevious();
            myworld--;
        }
        Decision jmpBck = dec;
        if (Configuration.PRINT_EXPLANATION && LOGGER.isInfoEnabled()) {
            LOGGER.info("::EXPL:: WILL BACKTRACK on " + dec /*+ " (up to " + nworld + " level(s))"*/);
        }

        // now we can explicitly enforce the jump
        dec = mSolver.getSearchLoop().getLastDecision(); // the current decision to undo
        while (dec != RootDecision.ROOT && nworld > 1) {

            if (!dec.hasNext()) {
                // on a right branch, necessarily have an explanation (it is a refutation)

                if (!mExplanationEngine.flatten(dec.getNegativeDeduction()).contain(jmpBck.getPositiveDeduction())) {
                    // everything is fine ... this refutation does not depend on what we are reconsidering
                    // set it as non activated and
                    dec.rewind();
                    dec.buildNext();
                    // add it to the decisions to force
View Full Code Here

    }

    @Override
    public void onSolution() {
        // we need to prepare a "false" backtrack on this decision
        Decision dec = mSolver.getSearchLoop().getLastDecision();
        while ((dec != RootDecision.ROOT) && (!dec.hasNext())) {
            dec = dec.getPrevious();
        }
        if (dec != RootDecision.ROOT) {
            Explanation explanation = new Explanation();
            Decision d = dec.getPrevious();
            while ((d != RootDecision.ROOT)) {
                if (d.hasNext()) {
                    explanation.add(d.getPositiveDeduction());
                }
                d = d.getPrevious();
            }
            mExplanationEngine.store(dec.getNegativeDeduction(), explanation);
        }
        mSolver.getSearchLoop().overridePreviousWorld(1);
    }
View Full Code Here

     * @param nworld index of the world to backtrack to
     * @param expl   explanation of the backtrack
     * @param cause  cause of the failure
     */
    protected void updateVRExplainUponbacktracking(int nworld, Explanation expl, ICause cause) {
        Decision dec = mSolver.getSearchLoop().getLastDecision(); // the current decision to undo
        while (dec != RootDecision.ROOT && nworld > 1) {
            dec = dec.getPrevious();
            nworld--;
        }
        if (dec != RootDecision.ROOT) {
            if (!dec.hasNext())
                throw new UnsupportedOperationException("RecorderExplanationEngine.updateVRExplain should get to a POSITIVE decision:" + dec);
            Deduction left = dec.getPositiveDeduction();
            expl.remove(left);
            assert left.getmType() == Deduction.Type.DecLeft;
            BranchingDecision va = (BranchingDecision) left;
            mExplanationEngine.removeLeftDecisionFrom(va.getDecision(), va.getVar());

            Deduction right = dec.getNegativeDeduction();
            mExplanationEngine.store(right, mExplanationEngine.flatten(expl));
        }
        if (Configuration.PRINT_EXPLANATION && LOGGER.isInfoEnabled()) {
            LOGGER.info("::EXPL:: BACKTRACK on " + dec /*+ " (up to " + nworld + " level(s))"*/);
        }
View Full Code Here

    /**
     * Compute the initial fragment, ie set of decisions to keep.
     */
    private void clonePath() {
        Decision dec = mSolver.getSearchLoop().getLastDecision();
        while ((dec != RootDecision.ROOT)) {
            addToPath(dec);
            dec = dec.getPrevious();
        }
        Collections.reverse(path);
        int size = path.size();
        for (int i = 0, mid = size >> 1, j = size - 1; i < mid; i++, j--) {
            boolean bi = refuted.get(i);
View Full Code Here

     * Add a copy of the current decision to path
     *
     * @param dec a decision of the current decision path
     */
    private void addToPath(Decision dec) {
        Decision clone = dec.duplicate();
        path.add(clone);
        int pos = path.size() - 1;
        if (!dec.hasNext()) {
            refuted.set(pos);
        }
View Full Code Here

        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("explain Cut");
        }
        // 1. make a backup
        mSolver.getEnvironment().worldPush();
        Decision d;
        try {

            Decision previous = mSolver.getSearchLoop().getLastDecision();
            assert previous == RootDecision.ROOT;
            // 2. apply the decisions
            mExplanationEngine.getSolver().getObjectiveManager().postDynamicCut();
            for (int i = 0; i < path.size(); i++) {
                d = path.get(i);
                d.setPrevious(previous);
                d.buildNext();
                if (refuted.get(i)) d.buildNext();
                d.apply();
                mSolver.propagate();
                previous = d;
            }
            //mSolver.propagate();
            assert false : "SHOULD FAIL!";
        } catch (ContradictionException cex) {
            if ((cex.v != null) || (cex.c != null)) { // contradiction on domain wipe out
                tmpDeductions.clear();
                tmpValueDeductions.clear();
                related2cut.clear();
                unrelated.clear();

                // 3. explain the failure
                Explanation expl = new Explanation();
                if (cex.v != null) {
                    cex.v.explain(VariableState.DOM, expl);
                } else {
                    cex.c.explain(null, expl);
                }
                Explanation complete = mExplanationEngine.flatten(expl);
                ExplanationToolbox.extractDecision(complete, tmpValueDeductions);
                tmpDeductions.addAll(tmpValueDeductions);

                if (tmpDeductions.isEmpty()) {
//                    if (LOGGER.isErrorEnabled()) {
//                        LOGGER.error("2 cases: (a) optimality proven or (b) bug in explanation");
//                    }
//                    throw new SolverException("2 cases: (a) optimality proven or (b) bug in explanation");
                    isTerminated = true;
                }

                for (int i = 0; i < tmpDeductions.size(); i++) {
                    int idx = path.indexOf(((BranchingDecision) tmpDeductions.get(i)).getDecision());
                    related2cut.set(idx);
                }

                // 4. need to replace the duplicated decision with the correct one
                for (int i = 0; i < path.size(); i++) {
                    Decision dec = path.get(i);
                    boolean forceNext = !dec.hasNext();
                    dec.rewind();
                    if (forceNext) dec.buildNext();
                    dec.setPrevious(null); // useless .. but ... you know
                }

            } else {
                throw new UnsupportedOperationException(this.getClass().getName() + ".onContradiction incoherent state");
            }
View Full Code Here

        AbstractStrategy asg = IntStrategyFactory.lexico_LB(variables);

        s.set(asg);

        env.worldPush();
        Decision decision = asg.getDecision();
        for (int i = 0; i < n; i++) {
            decision.buildNext();
            try {
                decision.apply();
            } catch (ContradictionException e) {
                e.printStackTrace();
            }
            Assert.assertTrue(variables[i].isInstantiated());
            Assert.assertEquals(variables[i].getValue(), i);
            Decision tmp = decision;
            decision = asg.getDecision();
            if (decision != null) {
                decision.setPrevious(tmp);
            } else {
                decision = tmp;
View Full Code Here

TOP

Related Classes of solver.search.strategy.decision.Decision

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.