Commit 1fc1c0dd authored by Anne Parrain's avatar Anne Parrain

Add a solver with the "Divide by 2" feature. Correctthe previous version

and remove it from the standard process.
parent c5a99b7a
Pipeline #138 failed with stage
......@@ -68,6 +68,7 @@ import org.sat4j.pb.core.PBSolverCP;
import org.sat4j.pb.core.PBSolverCPCardLearning;
import org.sat4j.pb.core.PBSolverCPClauseLearning;
import org.sat4j.pb.core.PBSolverCPLong;
import org.sat4j.pb.core.PBSolverCPLongDivideBy2;
import org.sat4j.pb.core.PBSolverCPLongReduceToCard;
import org.sat4j.pb.core.PBSolverCPLongRounding;
//import org.sat4j.pb.core.PBSolverCard;
......@@ -632,6 +633,18 @@ public final class SolverFactory extends ASolverFactory<IPBSolver> {
return solver;
}
private static PBSolverCP newPBCPStarDivideBy2(PBDataStructureFactory dsf,
IOrder order, boolean noRemove) {
MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
PBSolverCP solver = new PBSolverCPLongDivideBy2(learning, dsf, order,
noRemove);
learning.setDataStructureFactory(solver.getDSFactory());
learning.setVarActivityListener(solver);
solver.setRestartStrategy(new ArminRestarts());
solver.setLearnedConstraintsDeletionStrategy(solver.lbd_based);
return solver;
}
private static PBSolverCP newPBCPStarRounding(PBDataStructureFactory dsf,
IOrder order, boolean noRemove) {
MiniSATLearning<PBDataStructureFactory> learning = new MiniSATLearning<PBDataStructureFactory>();
......@@ -704,6 +717,11 @@ public final class SolverFactory extends ASolverFactory<IPBSolver> {
new VarOrderHeapObjective(), true);
}
public static IPBSolver newCuttingPlanesStarDivideBy2() {
return newPBCPStarDivideBy2(new PBMaxClauseCardConstrDataStructure(),
new VarOrderHeapObjective(), true);
}
/**
* Cutting Planes based solver. The inference during conflict analysis is
* based on cutting planes instead of resolution as in a SAT solver.
......
......@@ -75,10 +75,14 @@ public class MapPb implements IDataStructurePB {
}
public int reduceCoeffsByPower2() {
int nbBits = 1;
for (int i = 0; i < this.weightedLits.size() && nbBits > 0; i++)
assert this.weightedLits.size() > 0;
int nbBits = this.weightedLits.getCoef(0).bitLength();
for (int i = 0; i < this.weightedLits.size() && nbBits > 0; i++) {
nbBits = Math.min(nbBits,
this.weightedLits.getCoef(i).getLowestSetBit());
if (nbBits == 0)
break;
}
if (nbBits > 0) {
for (int i = 0; i < this.weightedLits.size(); i++) {
this.weightedLits.changeCoef(i,
......
......@@ -164,12 +164,6 @@ public class PBSolverCP extends PBSolver {
}
// assertive PB-constraint is build and referenced
int nbBits = confl.reduceCoeffsByPower2();
if (nbBits > 0) {
stats.numberOfReductionsByPower2++;
stats.numberOfRightShiftsForCoeffs = stats.numberOfRightShiftsForCoeffs
+ nbBits;
}
confl.postProcess(currentLevel);
PBConstr resConstr = (PBConstr) this.dsfactory
.createUnregisteredPseudoBooleanConstraint(confl);
......
package org.sat4j.pb.core;
import org.sat4j.minisat.core.IOrder;
import org.sat4j.minisat.core.LearningStrategy;
import org.sat4j.minisat.core.RestartStrategy;
import org.sat4j.minisat.core.SearchParams;
import org.sat4j.pb.constraints.pb.ConflictMap;
import org.sat4j.pb.constraints.pb.ConflictMapReduceToClause;
import org.sat4j.pb.constraints.pb.IConflict;
import org.sat4j.pb.constraints.pb.PBConstr;
public class PBSolverCPLongDivideBy2 extends PBSolverCPLong {
public PBSolverCPLongDivideBy2(
LearningStrategy<PBDataStructureFactory> learner,
PBDataStructureFactory dsf, IOrder order) {
super(learner, dsf, order);
// TODO Auto-generated constructor stub
}
public PBSolverCPLongDivideBy2(
LearningStrategy<PBDataStructureFactory> learner,
PBDataStructureFactory dsf, SearchParams params, IOrder order,
RestartStrategy restarter) {
super(learner, dsf, params, order, restarter);
// TODO Auto-generated constructor stub
}
public PBSolverCPLongDivideBy2(
LearningStrategy<PBDataStructureFactory> learner,
PBDataStructureFactory dsf, SearchParams params, IOrder order) {
super(learner, dsf, params, order);
// TODO Auto-generated constructor stub
}
public PBSolverCPLongDivideBy2(
LearningStrategy<PBDataStructureFactory> learner,
PBDataStructureFactory dsf, IOrder order, boolean noRemove) {
super(learner, dsf, order, noRemove);
// TODO Auto-generated constructor stub
}
public PBSolverCPLongDivideBy2(
LearningStrategy<PBDataStructureFactory> learner,
PBDataStructureFactory dsf, SearchParams params, IOrder order,
RestartStrategy restarter, boolean noRemove) {
super(learner, dsf, params, order, restarter, noRemove);
// TODO Auto-generated constructor stub
}
public PBSolverCPLongDivideBy2(
LearningStrategy<PBDataStructureFactory> learner,
PBDataStructureFactory dsf, SearchParams params, IOrder order,
boolean noRemove) {
super(learner, dsf, params, order, noRemove);
// TODO Auto-generated constructor stub
}
@Override
protected IConflict chooseConflict(PBConstr myconfl, int level) {
return ConflictMapReduceToClause.createConflict(myconfl, level,
noRemove, ConflictMap.POSTPROCESSDIVIDEBY2, stats);
}
@Override
public String toString(String prefix) {
return super.toString(prefix) + "\n" + prefix
+ "Performs a post-processing after conflict analysis in order to divide by 2 as much as possible coefficients of learned constraints";
}
}
package org.sat4j.pb.constraints;
import org.sat4j.pb.IPBSolver;
import org.sat4j.pb.SolverFactory;
public class PBCPMaxClauseCardConstrLearningDivideBy2Test
extends AbstractPseudoBooleanAndPigeonHoleTest {
public PBCPMaxClauseCardConstrLearningDivideBy2Test(String arg) {
super(arg);
// TODO Auto-generated constructor stub
}
@Override
protected IPBSolver createSolver() {
return SolverFactory.newCuttingPlanesStarDivideBy2();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment