Skip to content

Commit

Permalink
fix #472
Browse files Browse the repository at this point in the history
  • Loading branch information
cprudhom committed Dec 12, 2016
1 parent ed07644 commit be8043b
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main/java/org/chocosolver/solver/Solver.java
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ public void reset() {
if (rootWorldIndex > -1) {
mModel.getEnvironment().worldPopUntil(rootWorldIndex);
engine.flush();
objectivemanager.resetBestBounds();
dpath.synchronize();
feasible = ESat.UNDEFINED;
action = initialize;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
*/
abstract class AbstractIntObjManager extends AbstractObjManager<IntVar> {

private static final long serialVersionUID = 5529060355541720104L;
private static final long serialVersionUID = 5539060355541720114L;

public AbstractIntObjManager(AbstractObjManager<IntVar> objman) {
super(objman);
Expand Down Expand Up @@ -78,6 +78,12 @@ public void setStrictDynamicCut() {
cutComputer = (Number n) -> n.intValue() + precision.intValue();
}

@Override
public void resetBestBounds() {
bestProvedLB = objective.getLB() - 1;
bestProvedUB = objective.getUB() + 1;
}

@Override
public boolean why(RuleStore ruleStore, IntVar var, IEventType evt, int value) {
return isOptimization() && ruleStore.addBoundsRule(objective);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,11 @@ public AbstractObjManager(AbstractObjManager<V> objman) {

public AbstractObjManager(V objective, ResolutionPolicy policy, Number precision) {
super();
Objects.nonNull(objective);
assert Objects.nonNull(objective);
this.objective = objective;
Objects.nonNull(policy);
assert Objects.nonNull(policy);
this.policy = policy;
Objects.nonNull(precision);
assert Objects.nonNull(precision);
this.precision = precision;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ private final int getNbDecimals() {
return dec;
}

@Override
public void resetBestBounds() {
double prec = Math.abs(precision.doubleValue());
bestProvedLB = objective.getLB() - prec;
bestProvedUB = objective.getUB() + prec;
}

@Override
public String toString() {
return String.format("%s %s = %." + getNbDecimals() + "f", policy, objective == null ? "?" : this.objective.getName(), getBestSolutionValue().doubleValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@
*/
package org.chocosolver.solver.objective;

import java.io.Serializable;

import org.chocosolver.solver.ResolutionPolicy;

import java.io.Serializable;

/**
* interface to monitor bounds.
*
Expand Down Expand Up @@ -92,4 +92,9 @@ default void updateBestBounds(IBoundsManager b) {
* @return the best solution value found so far (returns the initial bound if no solution has been found yet)
*/
Number getBestSolutionValue();

/**
* Reset best bounds to the initial domain of the objective variables
*/
default void resetBestBounds(){}
}

0 comments on commit be8043b

Please sign in to comment.