Commit 34e1aafa by Lonca Emmanuel

fixed a bug that made optimization return wrong values

This bug occurs while maximizing an objective function made of a single
literal. In this case, the returned objective values was negated.
1 parent 179b56a6
Pipeline #203 passed
in 10 minutes 40 seconds
......@@ -95,12 +95,12 @@ public class ObjBuilder {
coeffs.push(BigInteger.valueOf(val));
}
final ObjectiveFunction obj = new ObjectiveFunction(literals, coeffs);
// obj.setCorrection(BigInteger.ONE);
return obj;
}
public void buildObjToMaximize(final String id, final XVarInteger x) {
final ObjectiveFunction obj = buildObjForVar(x).negate();
obj.setCorrectionFactor(BigInteger.ONE.negate());
addObjectiveFunction(obj);
}
......@@ -211,7 +211,6 @@ public class ObjBuilder {
}
if(min < 0) throw new UnsupportedOperationException("negative coeff");
final ObjectiveFunction obj = new ObjectiveFunction();
// obj.setCorrection(BigInteger.ONE);
final BigInteger step = BigInteger.valueOf(max+1);
BigInteger fact = BigInteger.ONE;
for(int i=xlist.length; i>=0; --i) {
......@@ -227,7 +226,6 @@ public class ObjBuilder {
private ObjectiveFunction buildExprObjToMinimize(String expr, boolean negate) {
final ObjectiveFunction obj = this.intensionEnc.encodeObj(expr);
// obj.setCorrection(BigInteger.ONE);
if(negate) {
obj.negate();
obj.setCorrectionFactor(BigInteger.ONE.negate());
......@@ -237,7 +235,6 @@ public class ObjBuilder {
private ObjectiveFunction buildSumObjToMinimize(final XVarInteger[] xlist, final int[] xcoeffs) {
final ObjectiveFunction obj = new ObjectiveFunction();
// obj.setCorrection(BigInteger.ONE);
final int size = xlist.length;
for(int i=0; i<size; ++i) {
obj.add(buildObjForVar(xlist[i]).multiply(BigInteger.valueOf(xcoeffs[i])));
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!