Search in sources :

Example 1 with IVec

use of org.sat4j.specs.IVec in project opt4j by felixreimann.

the class SAT4JSolver method addConstraintToSolver.

protected void addConstraintToSolver(Constraint constraint) {
    VecInt lits = toVecInt(constraint.getLiterals());
    IVec<BigInteger> coeffs = new Vec<BigInteger>();
    for (Integer value : constraint.getCoefficients()) {
        coeffs.push(BigInteger.valueOf(value));
    }
    BigInteger d = BigInteger.valueOf(constraint.getRhs());
    Operator operator = constraint.getOperator();
    try {
        if (operator == LE || operator == EQ) {
            solver.addPseudoBoolean(lits, coeffs, false, d);
        }
        if (operator == GE || operator == EQ) {
            solver.addPseudoBoolean(lits, coeffs, true, d);
        }
    } catch (org.sat4j.specs.ContradictionException e) {
        solverValid = false;
        throw new ContradictionException(e);
    }
}
Also used : BigInteger(java.math.BigInteger) Operator(org.opt4j.satdecoding.Constraint.Operator) VecInt(org.sat4j.core.VecInt) Vec(org.sat4j.core.Vec) IVec(org.sat4j.specs.IVec) ContradictionException(org.opt4j.satdecoding.ContradictionException) BigInteger(java.math.BigInteger)

Example 2 with IVec

use of org.sat4j.specs.IVec in project spoon by INRIA.

the class Solver method fixedSize.

public final LearnedConstraintsDeletionStrategy fixedSize(final int maxsize) {
    return new LearnedConstraintsDeletionStrategy() {

        private static final long serialVersionUID = 1L;

        private final ConflictTimer aTimer = new ConflictTimerAdapter(maxsize) {

            private static final long serialVersionUID = 1L;

            @Override
            public void run() {
                Solver.this.needToReduceDB = true;
            }
        };

        public void reduce(IVec<Constr> learnedConstrs) {
            int i, j, k;
            for (i = j = k = 0; i < Solver.this.learnts.size() && Solver.this.learnts.size() - k > maxsize; i++) {
                Constr c = Solver.this.learnts.get(i);
                if (c.locked() || c.size() == 2) {
                    Solver.this.learnts.set(j++, Solver.this.learnts.get(i));
                } else {
                    c.remove(Solver.this);
                    k++;
                }
            }
            for (; i < Solver.this.learnts.size(); i++) {
                Solver.this.learnts.set(j++, Solver.this.learnts.get(i));
            }
            if (Solver.this.verbose) {
                Solver.this.out.log(getLogPrefix() + "cleaning " + // $NON-NLS-1$
                (Solver.this.learnts.size() - j) + " clauses out of " + // $NON-NLS-1$
                Solver.this.learnts.size());
            // out.flush();
            }
            Solver.this.learnts.shrinkTo(j);
        }

        public void onConflictAnalysis(Constr reason) {
        // TODO Auto-generated method stub
        }

        public void onClauseLearning(Constr outLearnt) {
        // TODO Auto-generated method stub
        }

        @Override
        public String toString() {
            return "Fixed size (" + maxsize + ") learned constraints deletion strategy";
        }

        public void init() {
        }

        public ConflictTimer getTimer() {
            return this.aTimer;
        }

        public void onPropagation(Constr from) {
        // TODO Auto-generated method stub
        }
    };
}
Also used : IVec(org.sat4j.specs.IVec) IConstr(org.sat4j.specs.IConstr)

Example 3 with IVec

use of org.sat4j.specs.IVec in project spoon by INRIA.

the class Solver method activityBased.

private LearnedConstraintsDeletionStrategy activityBased(final ConflictTimer timer) {
    return new LearnedConstraintsDeletionStrategy() {

        private static final long serialVersionUID = 1L;

        private final ConflictTimer freeMem = timer;

        public void reduce(IVec<Constr> learnedConstrs) {
            sortOnActivity();
            int i, j;
            for (i = j = 0; i < Solver.this.learnts.size() / 2; i++) {
                Constr c = Solver.this.learnts.get(i);
                if (c.locked() || c.size() == 2) {
                    Solver.this.learnts.set(j++, Solver.this.learnts.get(i));
                } else {
                    c.remove(Solver.this);
                }
            }
            for (; i < Solver.this.learnts.size(); i++) {
                Solver.this.learnts.set(j++, Solver.this.learnts.get(i));
            }
            if (Solver.this.verbose) {
                Solver.this.out.log(getLogPrefix() + "cleaning " + // $NON-NLS-1$
                (Solver.this.learnts.size() - j) + " clauses out of " + // $NON-NLS-1$
                Solver.this.learnts.size());
            // out.flush();
            }
            Solver.this.learnts.shrinkTo(j);
        }

        public ConflictTimer getTimer() {
            return this.freeMem;
        }

        @Override
        public String toString() {
            return "Memory based learned constraints deletion strategy";
        }

        public void init() {
        // do nothing
        }

        public void onClauseLearning(Constr constr) {
        // do nothing
        }

        public void onConflictAnalysis(Constr reason) {
            if (reason.learnt()) {
                claBumpActivity(reason);
            }
        }

        public void onPropagation(Constr from) {
        // do nothing
        }
    };
}
Also used : IVec(org.sat4j.specs.IVec) IConstr(org.sat4j.specs.IConstr)

Aggregations

IVec (org.sat4j.specs.IVec)3 IConstr (org.sat4j.specs.IConstr)2 BigInteger (java.math.BigInteger)1 Operator (org.opt4j.satdecoding.Constraint.Operator)1 ContradictionException (org.opt4j.satdecoding.ContradictionException)1 Vec (org.sat4j.core.Vec)1 VecInt (org.sat4j.core.VecInt)1