Skip to content

Commit

Permalink
Merge pull request #139 from plaans/fix/maximize-final-value
Browse files Browse the repository at this point in the history
fix(up): Maximization of final value was incorrect (minimizing the value instead)
  • Loading branch information
arbimo committed Jul 5, 2024
2 parents fb61f62 + 8b7c733 commit 67ba7c8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion planning/planners/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,9 @@ pub fn add_metric(pb: &FiniteProblem, model: &mut Model, metric: Metric) -> IAto
Metric::MaximizeVar(to_maximize) => {
// we must return a variable to minimize.
// return a new variable constrained to be the negation of the one to maximize
// to_maximize = -to_minimize
let to_minimize = model.new_ivar(INT_CST_MIN, INT_CST_MAX, VarLabel(Container::Base, VarType::Cost));
let sum = LinearSum::zero() + to_maximize - to_minimize;
let sum = LinearSum::zero() + to_maximize + to_minimize;
model.enforce(sum.clone().leq(0), []);
model.enforce(sum.geq(0), []);
to_minimize.into()
Expand Down
6 changes: 6 additions & 0 deletions solver/src/model/lang/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ impl std::fmt::Display for LinearLeq {
}
}

impl std::fmt::Debug for LinearLeq {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{self}")
}
}

impl LinearLeq {
pub fn new(sum: LinearSum, ub: IntCst) -> LinearLeq {
LinearLeq { sum, ub }
Expand Down

0 comments on commit 67ba7c8

Please sign in to comment.