Commit cc4e1322 authored by Daniel Le Berre's avatar Daniel Le Berre

Fixes a few sonarqube violation.

parent 79ee6a46
...@@ -90,11 +90,10 @@ public class ObjectiveFunction implements Serializable { ...@@ -90,11 +90,10 @@ public class ObjectiveFunction implements Serializable {
BigInteger tempDegree = BigInteger.ZERO; BigInteger tempDegree = BigInteger.ZERO;
for (int i = 0; i < this.vars.size(); i++) { for (int i = 0; i < this.vars.size(); i++) {
BigInteger coeff = this.coeffs.get(i); BigInteger coeff = this.coeffs.get(i);
if (varInModel(this.vars.get(i), lazyModel)) { if (varInModel(this.vars.get(i), lazyModel) || coeff.signum() < 0
tempDegree = tempDegree.add(coeff);
} else if (coeff.signum() < 0
&& !varInModel(-this.vars.get(i), lazyModel)) { && !varInModel(-this.vars.get(i), lazyModel)) {
// the variable does not appear in the model: it can be assigned // if the variable does not appear in the model, it can be
// assigned
// either way // either way
tempDegree = tempDegree.add(coeff); tempDegree = tempDegree.add(coeff);
} }
...@@ -117,12 +116,10 @@ public class ObjectiveFunction implements Serializable { ...@@ -117,12 +116,10 @@ public class ObjectiveFunction implements Serializable {
BigInteger tempDegree = BigInteger.ZERO; BigInteger tempDegree = BigInteger.ZERO;
for (int i = 0; i < this.vars.size(); i++) { for (int i = 0; i < this.vars.size(); i++) {
BigInteger coeff = this.coeffs.get(i); BigInteger coeff = this.coeffs.get(i);
if (solver.primeImplicant(this.vars.get(i))) { if (solver.primeImplicant(this.vars.get(i)) || coeff.signum() < 0
tempDegree = tempDegree.add(coeff);
} else if (coeff.signum() < 0
&& !solver.primeImplicant(-this.vars.get(i))) { && !solver.primeImplicant(-this.vars.get(i))) {
// the variable does not appear in the model: it can be assigned // if the variable does not appear in the model, it can be
// either way // assigned either way
tempDegree = tempDegree.add(coeff); tempDegree = tempDegree.add(coeff);
} }
} }
......
...@@ -51,12 +51,12 @@ import org.sat4j.specs.VarMapper; ...@@ -51,12 +51,12 @@ import org.sat4j.specs.VarMapper;
* @author anne * @author anne
* *
*/ */
public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, public abstract class WatchPb
Serializable { implements IWatchPb, Propagatable, Undoable, Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final int LIMIT_SELECTION_SORT = 15; private static final int LIMIT_SELECTION_SORT = 15;
...@@ -137,8 +137,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -137,8 +137,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
BigInteger slack = BigInteger.ZERO; BigInteger slack = BigInteger.ZERO;
for (int i = 0; i < this.lits.length; i++) { for (int i = 0; i < this.lits.length; i++) {
if (this.coefs[i].signum() > 0 if (this.coefs[i].signum() > 0
&& (!this.voc.isFalsified(this.lits[i]) || this.voc && (!this.voc.isFalsified(this.lits[i])
.getLevel(this.lits[i]) >= dl)) { || this.voc.getLevel(this.lits[i]) >= dl)) {
slack = slack.add(this.coefs[i]); slack = slack.add(this.coefs[i]);
} }
} }
...@@ -148,8 +148,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -148,8 +148,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
} }
for (int i = 0; i < this.lits.length; i++) { for (int i = 0; i < this.lits.length; i++) {
if (this.coefs[i].signum() > 0 if (this.coefs[i].signum() > 0
&& (this.voc.isUnassigned(this.lits[i]) || this.voc && (this.voc.isUnassigned(this.lits[i])
.getLevel(this.lits[i]) >= dl) || this.voc.getLevel(this.lits[i]) >= dl)
&& slack.compareTo(this.coefs[i]) < 0) { && slack.compareTo(this.coefs[i]) < 0) {
return true; return true;
} }
...@@ -175,7 +175,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -175,7 +175,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
if (this.voc.isFalsified(q)) { if (this.voc.isFalsified(q)) {
outReason.push(q ^ 1); outReason.push(q ^ 1);
sumfalsified = sumfalsified.add(this.coefs[i]); sumfalsified = sumfalsified.add(this.coefs[i]);
if (this.sumcoefs.subtract(sumfalsified).compareTo(this.degree) < 0) { if (this.sumcoefs.subtract(sumfalsified)
.compareTo(this.degree) < 0) {
return; return;
} }
} }
...@@ -360,7 +361,7 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -360,7 +361,7 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
for (j = i + 1; j < to; j++) { for (j = i + 1; j < to; j++) {
if (this.coefs[j].compareTo(this.coefs[bestIndex]) > 0 if (this.coefs[j].compareTo(this.coefs[bestIndex]) > 0
|| this.coefs[j].equals(this.coefs[bestIndex]) || this.coefs[j].equals(this.coefs[bestIndex])
&& this.lits[j] > this.lits[bestIndex]) { && this.lits[j] > this.lits[bestIndex]) {
bestIndex = j; bestIndex = j;
} }
} }
...@@ -446,12 +447,12 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -446,12 +447,12 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
i++; i++;
} while (this.coefs[i].compareTo(pivot) > 0 } while (this.coefs[i].compareTo(pivot) > 0
|| this.coefs[i].equals(pivot) || this.coefs[i].equals(pivot)
&& this.lits[i] > litPivot); && this.lits[i] > litPivot);
do { do {
j--; j--;
} while (pivot.compareTo(this.coefs[j]) > 0 } while (pivot.compareTo(this.coefs[j]) > 0
|| this.coefs[j].equals(pivot) || this.coefs[j].equals(pivot)
&& this.lits[j] < litPivot); && this.lits[j] < litPivot);
if (i >= j) { if (i >= j) {
break; break;
...@@ -582,6 +583,9 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -582,6 +583,9 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
if (pb == null) { if (pb == null) {
return false; return false;
} }
if (this.getClass() != pb.getClass()) {
return false;
}
// this method should be simplified since now two constraints should // this method should be simplified since now two constraints should
// have // have
// always // always
...@@ -654,7 +658,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -654,7 +658,8 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
outReason.push(q); outReason.push(q);
index = vlits.indexOf(q ^ 1); index = vlits.indexOf(q ^ 1);
sumfalsified = sumfalsified.add(this.coefs[index]); sumfalsified = sumfalsified.add(this.coefs[index]);
if (this.sumcoefs.subtract(sumfalsified).compareTo(this.degree) < 0) { if (this.sumcoefs.subtract(sumfalsified)
.compareTo(this.degree) < 0) {
return; return;
} }
} }
...@@ -673,6 +678,7 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable, ...@@ -673,6 +678,7 @@ public abstract class WatchPb implements IWatchPb, Propagatable, Undoable,
public boolean isSatisfied() { public boolean isSatisfied() {
throw new UnsupportedOperationException("Not implemented yet"); throw new UnsupportedOperationException("Not implemented yet");
} }
public String toString(VarMapper mapper) { public String toString(VarMapper mapper) {
StringBuilder stb = new StringBuilder(); StringBuilder stb = new StringBuilder();
......
...@@ -561,6 +561,9 @@ public abstract class WatchPbLong ...@@ -561,6 +561,9 @@ public abstract class WatchPbLong
if (pb == null) { if (pb == null) {
return false; return false;
} }
if (this.getClass() != pb.getClass()) {
return false;
}
// this method should be simplified since now two constraints should // this method should be simplified since now two constraints should
// have // have
// always // always
......
...@@ -45,12 +45,12 @@ import org.sat4j.specs.Propagatable; ...@@ -45,12 +45,12 @@ import org.sat4j.specs.Propagatable;
import org.sat4j.specs.UnitPropagationListener; import org.sat4j.specs.UnitPropagationListener;
import org.sat4j.specs.VarMapper; import org.sat4j.specs.VarMapper;
public abstract class WatchPbLongCP implements IWatchPb, Propagatable, public abstract class WatchPbLongCP
Undoable, Serializable { implements IWatchPb, Propagatable, Undoable, Serializable {
/** /**
* *
*/ */
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static final int LIMIT_SELECTION_SORT = 15; private static final int LIMIT_SELECTION_SORT = 15;
...@@ -156,9 +156,8 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable, ...@@ -156,9 +156,8 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable,
public boolean isAssertive(int dl) { public boolean isAssertive(int dl) {
long slack = 0; long slack = 0;
for (int i = 0; i < this.lits.length; i++) { for (int i = 0; i < this.lits.length; i++) {
if (this.coefs[i] > 0 if (this.coefs[i] > 0 && (!this.voc.isFalsified(this.lits[i])
&& (!this.voc.isFalsified(this.lits[i]) || this.voc || this.voc.getLevel(this.lits[i]) >= dl)) {
.getLevel(this.lits[i]) >= dl)) {
slack = slack + this.coefs[i]; slack = slack + this.coefs[i];
} }
} }
...@@ -168,8 +167,8 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable, ...@@ -168,8 +167,8 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable,
} }
for (int i = 0; i < this.lits.length; i++) { for (int i = 0; i < this.lits.length; i++) {
if (this.coefs[i] > 0 if (this.coefs[i] > 0
&& (this.voc.isUnassigned(this.lits[i]) || this.voc && (this.voc.isUnassigned(this.lits[i])
.getLevel(this.lits[i]) >= dl) || this.voc.getLevel(this.lits[i]) >= dl)
&& slack < this.coefs[i]) { && slack < this.coefs[i]) {
return true; return true;
} }
...@@ -389,7 +388,7 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable, ...@@ -389,7 +388,7 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable,
for (j = i + 1; j < to; j++) { for (j = i + 1; j < to; j++) {
if (this.coefs[j] > this.coefs[bestIndex] if (this.coefs[j] > this.coefs[bestIndex]
|| this.coefs[j] == this.coefs[bestIndex] || this.coefs[j] == this.coefs[bestIndex]
&& this.lits[j] > this.lits[bestIndex]) { && this.lits[j] > this.lits[bestIndex]) {
bestIndex = j; bestIndex = j;
} }
} }
...@@ -474,12 +473,12 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable, ...@@ -474,12 +473,12 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable,
for (;;) { for (;;) {
do { do {
i++; i++;
} while (this.coefs[i] > pivot || this.coefs[i] == pivot } while (this.coefs[i] > pivot
&& this.lits[i] > litPivot); || this.coefs[i] == pivot && this.lits[i] > litPivot);
do { do {
j--; j--;
} while (pivot > this.coefs[j] || this.coefs[j] == pivot } while (pivot > this.coefs[j]
&& this.lits[j] < litPivot); || this.coefs[j] == pivot && this.lits[j] < litPivot);
if (i >= j) { if (i >= j) {
break; break;
...@@ -596,6 +595,9 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable, ...@@ -596,6 +595,9 @@ public abstract class WatchPbLongCP implements IWatchPb, Propagatable,
if (pb == null) { if (pb == null) {
return false; return false;
} }
if (this.getClass() != pb.getClass()) {
return false;
}
// this method should be simplified since now two constraints should // this method should be simplified since now two constraints should
// have // have
// always // always
......
...@@ -83,8 +83,7 @@ public class AtLeastCard { ...@@ -83,8 +83,7 @@ public class AtLeastCard {
if (degree != other.degree) if (degree != other.degree)
return false; return false;
if (lits == null) { if (lits == null) {
if (other.lits != null) return other.lits == null;
return false;
} }
Set<Integer> litsSet1 = new HashSet<Integer>(); Set<Integer> litsSet1 = new HashSet<Integer>();
for (IteratorInt it = lits.iterator(); it.hasNext();) for (IteratorInt it = lits.iterator(); it.hasNext();)
......
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