Commit 3e4cb2b8 authored by Lonca Emmanuel's avatar Lonca Emmanuel

made objective functions corrections linear

parent bbd24d04
...@@ -66,6 +66,8 @@ public class ObjectiveFunction implements Serializable { ...@@ -66,6 +66,8 @@ public class ObjectiveFunction implements Serializable {
private BigInteger correction = BigInteger.ZERO; private BigInteger correction = BigInteger.ZERO;
private BigInteger correctionFactor = BigInteger.ONE;
public ObjectiveFunction() { public ObjectiveFunction() {
this.vars = new VecInt(); this.vars = new VecInt();
this.coeffs = new Vec<BigInteger>(); this.coeffs = new Vec<BigInteger>();
...@@ -142,14 +144,32 @@ public class ObjectiveFunction implements Serializable { ...@@ -142,14 +144,32 @@ public class ObjectiveFunction implements Serializable {
return this.vars; return this.vars;
} }
@Deprecated // replaced by setCorrectionOffset()
public void setCorrection(BigInteger correction) { public void setCorrection(BigInteger correction) {
this.correction = correction; this.correction = correction;
} }
public void setCorrectionOffset(BigInteger correction) {
this.correction = correction;
}
@Deprecated // replaced by getCorrectionOffset()
public BigInteger getCorrection() { public BigInteger getCorrection() {
return this.correction; return this.correction;
} }
public BigInteger getCorrectionOffset() {
return this.correction;
}
public void setCorrectionFactor(final BigInteger correctionFactor) {
this.correctionFactor = correctionFactor;
}
public BigInteger getCorrectionFactor() {
return this.correctionFactor;
}
@Override @Override
public String toString() { public String toString() {
StringBuilder stb = new StringBuilder(); StringBuilder stb = new StringBuilder();
...@@ -164,7 +184,8 @@ public class ObjectiveFunction implements Serializable { ...@@ -164,7 +184,8 @@ public class ObjectiveFunction implements Serializable {
lit = -lit; lit = -lit;
coef = coef.negate(); coef = coef.negate();
} }
stb.append((coef.signum() < 0 ? "" : "+") + coef + " x" + lit + " "); stb.append(
(coef.signum() < 0 ? "" : "+") + coef + " x" + lit + " ");
} }
return stb.toString(); return stb.toString();
} }
......
...@@ -308,8 +308,11 @@ public class PseudoOptDecorator extends PBSolverDecorator ...@@ -308,8 +308,11 @@ public class PseudoOptDecorator extends PBSolverDecorator
} }
public Number getObjectiveValue() { public Number getObjectiveValue() {
return this.objectiveValue final BigInteger offset = decorated().getObjectiveFunction()
.add(decorated().getObjectiveFunction().getCorrection()); .getCorrectionOffset();
final BigInteger factor = decorated().getObjectiveFunction()
.getCorrectionFactor();
return this.objectiveValue.multiply(factor).add(offset);
} }
public void discard() throws ContradictionException { public void discard() throws ContradictionException {
......
...@@ -74,8 +74,10 @@ public final class SearchOptimizerListener extends ...@@ -74,8 +74,10 @@ public final class SearchOptimizerListener extends
public void solutionFound(int[] model, RandomAccessModel lazyModel) { public void solutionFound(int[] model, RandomAccessModel lazyModel) {
if (obj != null) { if (obj != null) {
this.currentValue = obj.calculateDegree(lazyModel); this.currentValue = obj.calculateDegree(lazyModel);
final BigInteger offset = obj.getCorrectionOffset();
final BigInteger factor = obj.getCorrectionFactor();
System.out.println(ILauncherMode.CURRENT_OPTIMUM_VALUE_PREFIX System.out.println(ILauncherMode.CURRENT_OPTIMUM_VALUE_PREFIX
+ this.currentValue.add(obj.getCorrection())); + this.currentValue.multiply(factor).add(offset));
if (this.prevConstr != null) { if (this.prevConstr != null) {
this.solverService.removeSubsumedConstr(prevConstr); this.solverService.removeSubsumedConstr(prevConstr);
} }
......
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