Commit 34e1aafa authored by Lonca Emmanuel's avatar 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.
parent 179b56a6
Pipeline #203 passed with stage
in 10 minutes and 40 seconds
...@@ -95,12 +95,12 @@ public class ObjBuilder { ...@@ -95,12 +95,12 @@ public class ObjBuilder {
coeffs.push(BigInteger.valueOf(val)); coeffs.push(BigInteger.valueOf(val));
} }
final ObjectiveFunction obj = new ObjectiveFunction(literals, coeffs); final ObjectiveFunction obj = new ObjectiveFunction(literals, coeffs);
// obj.setCorrection(BigInteger.ONE);
return obj; return obj;
} }
public void buildObjToMaximize(final String id, final XVarInteger x) { public void buildObjToMaximize(final String id, final XVarInteger x) {
final ObjectiveFunction obj = buildObjForVar(x).negate(); final ObjectiveFunction obj = buildObjForVar(x).negate();
obj.setCorrectionFactor(BigInteger.ONE.negate());
addObjectiveFunction(obj); addObjectiveFunction(obj);
} }
...@@ -211,7 +211,6 @@ public class ObjBuilder { ...@@ -211,7 +211,6 @@ public class ObjBuilder {
} }
if(min < 0) throw new UnsupportedOperationException("negative coeff"); if(min < 0) throw new UnsupportedOperationException("negative coeff");
final ObjectiveFunction obj = new ObjectiveFunction(); final ObjectiveFunction obj = new ObjectiveFunction();
// obj.setCorrection(BigInteger.ONE);
final BigInteger step = BigInteger.valueOf(max+1); final BigInteger step = BigInteger.valueOf(max+1);
BigInteger fact = BigInteger.ONE; BigInteger fact = BigInteger.ONE;
for(int i=xlist.length; i>=0; --i) { for(int i=xlist.length; i>=0; --i) {
...@@ -227,7 +226,6 @@ public class ObjBuilder { ...@@ -227,7 +226,6 @@ public class ObjBuilder {
private ObjectiveFunction buildExprObjToMinimize(String expr, boolean negate) { private ObjectiveFunction buildExprObjToMinimize(String expr, boolean negate) {
final ObjectiveFunction obj = this.intensionEnc.encodeObj(expr); final ObjectiveFunction obj = this.intensionEnc.encodeObj(expr);
// obj.setCorrection(BigInteger.ONE);
if(negate) { if(negate) {
obj.negate(); obj.negate();
obj.setCorrectionFactor(BigInteger.ONE.negate()); obj.setCorrectionFactor(BigInteger.ONE.negate());
...@@ -237,7 +235,6 @@ public class ObjBuilder { ...@@ -237,7 +235,6 @@ public class ObjBuilder {
private ObjectiveFunction buildSumObjToMinimize(final XVarInteger[] xlist, final int[] xcoeffs) { private ObjectiveFunction buildSumObjToMinimize(final XVarInteger[] xlist, final int[] xcoeffs) {
final ObjectiveFunction obj = new ObjectiveFunction(); final ObjectiveFunction obj = new ObjectiveFunction();
// obj.setCorrection(BigInteger.ONE);
final int size = xlist.length; final int size = xlist.length;
for(int i=0; i<size; ++i) { for(int i=0; i<size; ++i) {
obj.add(buildObjForVar(xlist[i]).multiply(BigInteger.valueOf(xcoeffs[i]))); obj.add(buildObjForVar(xlist[i]).multiply(BigInteger.valueOf(xcoeffs[i])));
......
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