use of org.logicng.collections.LNGIntVector in project LogicNG by logic-ng.
the class MSU3 method rebuildSolver.
protected MiniSatStyleSolver rebuildSolver() {
final MiniSatStyleSolver s = newSATSolver();
for (int i = 0; i < nVars(); i++) {
newSATVariable(s);
}
for (int i = 0; i < nHard(); i++) {
s.addClause(this.hardClauses.get(i).clause(), null);
}
LNGIntVector clause;
for (int i = 0; i < nSoft(); i++) {
clause = new LNGIntVector(this.softClauses.get(i).clause());
for (int j = 0; j < this.softClauses.get(i).relaxationVars().size(); j++) {
clause.push(this.softClauses.get(i).relaxationVars().get(j));
}
s.addClause(clause, null);
}
return s;
}
use of org.logicng.collections.LNGIntVector in project LogicNG by logic-ng.
the class MSU3 method none.
protected MaxSATResult none() {
this.nbInitialVariables = nVars();
Tristate res;
this.initRelaxation();
this.solver = this.rebuildSolver();
final LNGIntVector assumptions = new LNGIntVector();
final LNGIntVector currentObjFunction = new LNGIntVector();
this.encoder.setIncremental(IncrementalStrategy.NONE);
this.activeSoft.growTo(nSoft(), false);
for (int i = 0; i < nSoft(); i++) {
this.coreMapping.put(this.softClauses.get(i).assumptionVar(), i);
}
while (true) {
final SATHandler satHandler = satHandler();
res = searchSATSolver(this.solver, satHandler, assumptions);
if (aborted(satHandler)) {
return MaxSATResult.UNDEF;
} else if (res == Tristate.TRUE) {
this.nbSatisfiable++;
final int newCost = computeCostModel(this.solver.model(), Integer.MAX_VALUE);
saveModel(this.solver.model());
if (this.verbosity != Verbosity.NONE) {
this.output.println("o " + newCost);
}
this.ubCost = newCost;
if (this.nbSatisfiable == 1) {
if (!foundUpperBound(this.ubCost, null)) {
return MaxSATResult.UNDEF;
}
for (int i = 0; i < this.objFunction.size(); i++) {
assumptions.push(not(this.objFunction.get(i)));
}
} else {
return MaxSATResult.OPTIMUM;
}
} else {
this.lbCost++;
this.nbCores++;
if (this.verbosity != Verbosity.NONE) {
this.output.println("c LB : " + this.lbCost);
}
if (this.nbSatisfiable == 0) {
return MaxSATResult.UNSATISFIABLE;
} else if (this.lbCost == this.ubCost) {
assert this.nbSatisfiable > 0;
if (this.verbosity != Verbosity.NONE) {
this.output.println("c LB = UB");
}
return MaxSATResult.OPTIMUM;
} else if (!foundLowerBound(this.lbCost, null)) {
return MaxSATResult.UNDEF;
}
this.sumSizeCores += this.solver.conflict().size();
for (int i = 0; i < this.solver.conflict().size(); i++) {
assert !this.activeSoft.get(this.coreMapping.get(this.solver.conflict().get(i)));
this.activeSoft.set(this.coreMapping.get(this.solver.conflict().get(i)), true);
}
currentObjFunction.clear();
assumptions.clear();
for (int i = 0; i < nSoft(); i++) {
if (this.activeSoft.get(i)) {
currentObjFunction.push(this.softClauses.get(i).relaxationVars().get(0));
} else {
assumptions.push(not(this.softClauses.get(i).assumptionVar()));
}
}
if (this.verbosity != Verbosity.NONE) {
this.output.printf("c Relaxed soft clauses %d / %d%n", currentObjFunction.size(), this.objFunction.size());
}
this.solver = this.rebuildSolver();
this.encoder.encodeCardinality(this.solver, currentObjFunction, this.lbCost);
}
}
}
use of org.logicng.collections.LNGIntVector in project LogicNG by logic-ng.
the class WBO method rebuildWeightSolver.
protected MiniSatStyleSolver rebuildWeightSolver(final WeightStrategy strategy) {
assert strategy == WeightStrategy.NORMAL || strategy == WeightStrategy.DIVERSIFY;
final MiniSatStyleSolver s = newSATSolver();
for (int i = 0; i < nVars(); i++) {
newSATVariable(s);
}
for (int i = 0; i < nHard(); i++) {
s.addClause(this.hardClauses.get(i).clause(), null);
}
if (this.symmetryStrategy) {
this.symmetryBreaking();
}
LNGIntVector clause = new LNGIntVector();
this.nbCurrentSoft = 0;
for (int i = 0; i < nSoft(); i++) {
if (this.softClauses.get(i).weight() >= this.currentWeight) {
this.nbCurrentSoft++;
clause.clear();
clause = new LNGIntVector(this.softClauses.get(i).clause());
for (int j = 0; j < this.softClauses.get(i).relaxationVars().size(); j++) {
clause.push(this.softClauses.get(i).relaxationVars().get(j));
}
clause.push(this.softClauses.get(i).assumptionVar());
s.addClause(clause, null);
}
}
return s;
}
use of org.logicng.collections.LNGIntVector in project LogicNG by logic-ng.
the class WBO method initSymmetry.
void initSymmetry() {
for (int i = 0; i < nSoft(); i++) {
this.softMapping.push(new LNGIntVector());
this.relaxationMapping.push(new LNGIntVector());
}
}
use of org.logicng.collections.LNGIntVector in project LogicNG by logic-ng.
the class PlaistedGreenbaumTransformationSolver method vector.
private static LNGIntVector vector(final int elt, final LNGIntVector a) {
final LNGIntVector result = new LNGIntVector(a.size() + 1);
result.unsafePush(elt);
for (int i = 0; i < a.size(); i++) {
result.unsafePush(a.get(i));
}
return result;
}
Aggregations