Commit 27a76efd authored by Daniel Le Berre's avatar Daniel Le Berre
Browse files

Make sure that plain SearchListener objects can be used with CP based

solvers which now expect a PBSearchListener.
parent 62a414b1
......@@ -54,9 +54,12 @@ import org.sat4j.pb.orders.BumpStrategy;
import org.sat4j.pb.orders.Bumper;
import org.sat4j.pb.orders.IBumper;
import org.sat4j.pb.tools.PBSearchListener;
import org.sat4j.pb.tools.PBSearchListenerDecorator;
import org.sat4j.pb.tools.VoidPBTracing;
import org.sat4j.specs.Constr;
import org.sat4j.specs.ISolverService;
import org.sat4j.specs.IVec;
import org.sat4j.specs.SearchListener;
import org.sat4j.specs.TimeoutException;
/**
......@@ -342,4 +345,14 @@ public class PBSolverCP extends PBSolver {
public void postBumpActivity(Constr constr) {
bumper.postBumpActivity(getOrder(), (PBConstr) constr);
}
@Override
public <S extends ISolverService> void setSearchListener(
SearchListener<S> sl) {
if (sl instanceof PBSearchListener) {
super.setSearchListener(sl);
} else {
super.setSearchListener(new PBSearchListenerDecorator<>(sl));
}
}
}
package org.sat4j.pb.tools;
import java.math.BigInteger;
import org.sat4j.pb.constraints.pb.PBConstr;
import org.sat4j.specs.IConstr;
import org.sat4j.specs.ISolverService;
import org.sat4j.specs.Lbool;
import org.sat4j.specs.RandomAccessModel;
import org.sat4j.specs.SearchListener;
/**
* Allow the basic SearchListener objects to be treated as PBSearchListener
* objects in cutting planes based PB solvers.
*
* @author leberre
*
* @param <S>
* @since 3.0.0
*/
public class PBSearchListenerDecorator<S extends ISolverService>
implements PBSearchListener<S> {
/**
*
*/
private static final long serialVersionUID = 1L;
private final SearchListener<S> listener;
public PBSearchListenerDecorator(SearchListener<S> listener) {
this.listener = listener;
}
@Override
public void init(S solverService) {
listener.init(solverService);
}
@Override
public void assuming(int p) {
listener.assuming(p);
}
@Override
public void propagating(int p) {
listener.propagating(p);
}
@Override
public void enqueueing(int p, IConstr reason) {
listener.enqueueing(p, reason);
}
@Override
public void backtracking(int p) {
listener.backtracking(p);
}
@Override
public void adding(int p) {
listener.adding(p);
}
@Override
public void learn(IConstr c) {
listener.learn(c);
}
@Override
public void delete(IConstr c) {
listener.delete(c);
}
@Override
public void conflictFound(IConstr confl, int dlevel, int trailLevel) {
listener.conflictFound(confl, dlevel, trailLevel);
}
@Override
public void conflictFound(int p) {
listener.conflictFound(p);
}
@Override
public void solutionFound(int[] model, RandomAccessModel lazyModel) {
listener.solutionFound(model, lazyModel);
}
@Override
public void beginLoop() {
listener.beginLoop();
}
@Override
public void start() {
listener.start();
}
@Override
public void end(Lbool result) {
listener.end(result);
}
@Override
public void restarting() {
listener.restarting();
}
@Override
public void backjump(int backjumpLevel) {
listener.backjump(backjumpLevel);
}
@Override
public void cleaning() {
listener.cleaning();
}
@Override
public void learnUnit(int p) {
listener.learnUnit(p);
}
@Override
public void onConflict(PBConstr constr) {
}
@Override
public void withReason(PBConstr constr) {
}
@Override
public void weakenOnReason(int p) {
}
@Override
public void weakenOnReason(BigInteger coeff, int p) {
}
@Override
public void weakenOnConflict(int p) {
}
@Override
public void weakenOnConflict(BigInteger coeff, int p) {
}
@Override
public void multiplyReason(BigInteger coeff) {
}
@Override
public void divideReason(BigInteger coeff) {
}
@Override
public void multiplyConflict(BigInteger coeff) {
}
@Override
public void divideConflict(BigInteger coeff) {
}
@Override
public void saturateReason() {
}
@Override
public void saturateConflict() {
}
@Override
public void addReasonAndConflict() {
}
}
Supports Markdown
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