Search in sources :

Example 1 with LNGBooleanVector

use of org.logicng.collections.LNGBooleanVector in project LogicNG by logic-ng.

the class GlucoseSyrup method solve.

@Override
public Tristate solve(final SATHandler handler) {
    if (this.config.incremental && this.config.proofGeneration) {
        throw new IllegalStateException("Cannot use incremental and proof generation at the same time");
    }
    this.handler = handler;
    start(handler);
    this.model.clear();
    this.conflict.clear();
    if (!this.ok) {
        return Tristate.FALSE;
    }
    for (int i = 0; i < this.assumptions.size(); i++) {
        this.assump.set(var(this.assumptions.get(i)), !sign(this.assumptions.get(i)));
    }
    Tristate status = Tristate.UNDEF;
    while (status == Tristate.UNDEF && !this.canceledByHandler) {
        status = search();
    }
    if (this.config.proofGeneration && this.assumptions.empty()) {
        if (status == Tristate.FALSE) {
            this.pgProof.push(new LNGIntVector(1, 0));
        }
    }
    if (status == Tristate.TRUE) {
        this.model = new LNGBooleanVector(this.vars.size());
        for (final MSVariable v : this.vars) {
            this.model.push(v.assignment() == Tristate.TRUE);
        }
    } else if (status == Tristate.FALSE && this.conflict.size() == 0) {
        this.ok = false;
    }
    finishSolving(handler);
    cancelUntil(0);
    this.handler = null;
    this.canceledByHandler = false;
    for (int i = 0; i < this.assumptions.size(); i++) {
        this.assump.set(var(this.assumptions.get(i)), false);
    }
    return status;
}
Also used : MSVariable(org.logicng.solvers.datastructures.MSVariable) Tristate(org.logicng.datastructures.Tristate) LNGBooleanVector(org.logicng.collections.LNGBooleanVector) LNGIntVector(org.logicng.collections.LNGIntVector)

Example 2 with LNGBooleanVector

use of org.logicng.collections.LNGBooleanVector in project LogicNG by logic-ng.

the class MiniCard method solve.

@Override
public Tristate solve(final SATHandler handler) {
    this.handler = handler;
    start(handler);
    this.model.clear();
    this.conflict.clear();
    if (!this.ok) {
        return Tristate.FALSE;
    }
    this.learntsizeAdjustConfl = this.learntsizeAdjustStartConfl;
    this.learntsizeAdjustCnt = (int) this.learntsizeAdjustConfl;
    this.maxLearnts = this.clauses.size() * this.learntsizeFactor;
    Tristate status = Tristate.UNDEF;
    int currRestarts = 0;
    while (status == Tristate.UNDEF && !this.canceledByHandler) {
        final double restBase = luby(this.restartInc, currRestarts);
        status = search((int) (restBase * this.restartFirst));
        currRestarts++;
    }
    if (status == Tristate.TRUE) {
        this.model = new LNGBooleanVector(this.vars.size());
        for (final MSVariable v : this.vars) {
            this.model.push(v.assignment() == Tristate.TRUE);
        }
    } else if (status == Tristate.FALSE && this.conflict.empty()) {
        this.ok = false;
    }
    finishSolving(handler);
    cancelUntil(0);
    this.handler = null;
    this.canceledByHandler = false;
    return status;
}
Also used : MSVariable(org.logicng.solvers.datastructures.MSVariable) Tristate(org.logicng.datastructures.Tristate) LNGBooleanVector(org.logicng.collections.LNGBooleanVector)

Example 3 with LNGBooleanVector

use of org.logicng.collections.LNGBooleanVector in project LogicNG by logic-ng.

the class MiniSatStyleSolver method initialize.

/**
 * Initializes the internal solver state.
 */
protected void initialize() {
    this.initializeConfig();
    this.ok = true;
    this.qhead = 0;
    this.clauses = new LNGVector<>();
    this.learnts = new LNGVector<>();
    this.watches = new LNGVector<>();
    this.vars = new LNGVector<>();
    this.orderHeap = new LNGHeap(this);
    this.trail = new LNGIntVector();
    this.trailLim = new LNGIntVector();
    this.model = new LNGBooleanVector();
    this.conflict = new LNGIntVector();
    this.assumptions = new LNGIntVector();
    this.seen = new LNGBooleanVector();
    this.analyzeStack = new LNGIntVector();
    this.analyzeToClear = new LNGIntVector();
    this.analyzeBtLevel = 0;
    this.claInc = 1;
    this.simpDBAssigns = -1;
    this.simpDBProps = 0;
    this.clausesLiterals = 0;
    this.learntsLiterals = 0;
    this.name2idx = new TreeMap<>();
    this.idx2name = new TreeMap<>();
    this.canceledByHandler = false;
    if (this.config.proofGeneration) {
        this.pgOriginalClauses = new LNGVector<>();
        this.pgProof = new LNGVector<>();
    }
    this.computingBackbone = false;
    this.selectionOrder = new LNGIntVector();
    this.selectionOrderIdx = 0;
}
Also used : LNGBooleanVector(org.logicng.collections.LNGBooleanVector) LNGIntVector(org.logicng.collections.LNGIntVector) LNGHeap(org.logicng.solvers.datastructures.LNGHeap)

Example 4 with LNGBooleanVector

use of org.logicng.collections.LNGBooleanVector in project LogicNG by logic-ng.

the class ModelEnumerationFunction method apply.

@Override
public List<Assignment> apply(final MiniSat solver, final Consumer<Tristate> resultSetter) {
    start(this.handler);
    final List<Assignment> models = new ArrayList<>();
    SolverState stateBeforeEnumeration = null;
    if (solver.getStyle() == MiniSat.SolverStyle.MINISAT && solver.isIncremental()) {
        stateBeforeEnumeration = solver.saveState();
    }
    boolean proceed = true;
    final LNGIntVector relevantIndices;
    if (this.variables == null) {
        if (!solver.getConfig().isAuxiliaryVariablesInModels()) {
            relevantIndices = new LNGIntVector();
            for (final Map.Entry<String, Integer> entry : solver.underlyingSolver().getName2idx().entrySet()) {
                if (solver.isRelevantVariable(entry.getKey())) {
                    relevantIndices.push(entry.getValue());
                }
            }
        } else {
            relevantIndices = null;
        }
    } else {
        relevantIndices = new LNGIntVector(this.variables.size());
        for (final Variable var : this.variables) {
            relevantIndices.push(solver.underlyingSolver().idxForName(var.name()));
        }
    }
    LNGIntVector relevantAllIndices = null;
    final SortedSet<Variable> uniqueAdditionalVariables = new TreeSet<>(this.additionalVariables == null ? Collections.emptyList() : this.additionalVariables);
    if (this.variables != null) {
        uniqueAdditionalVariables.removeAll(this.variables);
    }
    if (relevantIndices != null) {
        if (uniqueAdditionalVariables.isEmpty()) {
            relevantAllIndices = relevantIndices;
        } else {
            relevantAllIndices = new LNGIntVector(relevantIndices.size() + uniqueAdditionalVariables.size());
            for (int i = 0; i < relevantIndices.size(); ++i) {
                relevantAllIndices.push(relevantIndices.get(i));
            }
            for (final Variable var : uniqueAdditionalVariables) {
                relevantAllIndices.push(solver.underlyingSolver().idxForName(var.name()));
            }
        }
    }
    while (proceed && modelEnumerationSATCall(solver, this.handler)) {
        final LNGBooleanVector modelFromSolver = solver.underlyingSolver().model();
        final Assignment model = solver.createAssignment(modelFromSolver, relevantAllIndices);
        models.add(model);
        proceed = this.handler == null || this.handler.foundModel(model);
        if (model.size() > 0) {
            final LNGIntVector blockingClause = generateBlockingClause(modelFromSolver, relevantIndices);
            solver.underlyingSolver().addClause(blockingClause, null);
            resultSetter.accept(UNDEF);
        } else {
            break;
        }
    }
    if (solver.getStyle() == MiniSat.SolverStyle.MINISAT && solver.isIncremental()) {
        solver.loadState(stateBeforeEnumeration);
    }
    return models;
}
Also used : Variable(org.logicng.formulas.Variable) ArrayList(java.util.ArrayList) LNGIntVector(org.logicng.collections.LNGIntVector) Assignment(org.logicng.datastructures.Assignment) SolverState(org.logicng.solvers.SolverState) TreeSet(java.util.TreeSet) LNGBooleanVector(org.logicng.collections.LNGBooleanVector) Map(java.util.Map)

Example 5 with LNGBooleanVector

use of org.logicng.collections.LNGBooleanVector in project LogicNG by logic-ng.

the class GlucoseSyrup method initializeGlucose.

/**
 * Initializes the additional parameters.
 */
protected void initializeGlucose() {
    this.initializeGlucoseConfig();
    this.watchesBin = new LNGVector<>();
    this.permDiff = new LNGIntVector();
    this.lastDecisionLevel = new LNGIntVector();
    this.lbdQueue = new LNGBoundedLongQueue();
    this.trailQueue = new LNGBoundedIntQueue();
    this.assump = new LNGBooleanVector();
    this.lbdQueue.initSize(this.sizeLBDQueue);
    this.trailQueue.initSize(this.sizeTrailQueue);
    this.myflag = 0;
    this.analyzeBtLevel = 0;
    this.analyzeLBD = 0;
    this.analyzeSzWithoutSelectors = 0;
    this.nbclausesbeforereduce = this.firstReduceDB;
    this.conflicts = 0;
    this.conflictsRestarts = 0;
    this.sumLBD = 0;
    this.curRestart = 1;
}
Also used : LNGBoundedLongQueue(org.logicng.solvers.datastructures.LNGBoundedLongQueue) LNGBooleanVector(org.logicng.collections.LNGBooleanVector) LNGIntVector(org.logicng.collections.LNGIntVector) LNGBoundedIntQueue(org.logicng.solvers.datastructures.LNGBoundedIntQueue)

Aggregations

LNGBooleanVector (org.logicng.collections.LNGBooleanVector)11 LNGIntVector (org.logicng.collections.LNGIntVector)7 Tristate (org.logicng.datastructures.Tristate)5 MSVariable (org.logicng.solvers.datastructures.MSVariable)3 LNGVector (org.logicng.collections.LNGVector)2 Assignment (org.logicng.datastructures.Assignment)2 Literal (org.logicng.formulas.Literal)2 Variable (org.logicng.formulas.Variable)2 ArrayList (java.util.ArrayList)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1 CCIncrementalData (org.logicng.cardinalityconstraints.CCIncrementalData)1 CardinalityConstraint (org.logicng.formulas.CardinalityConstraint)1 Formula (org.logicng.formulas.Formula)1 FormulaFactory (org.logicng.formulas.FormulaFactory)1 SATHandler (org.logicng.handlers.SATHandler)1 SolverState (org.logicng.solvers.SolverState)1 LNGBoundedIntQueue (org.logicng.solvers.datastructures.LNGBoundedIntQueue)1