-
Notifications
You must be signed in to change notification settings - Fork 22
Add objective_value method to SolvedModel
#29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about changing the return type to
Option<f64>? I feel like this would be a lot more intuitive than having to check manually whether the value is meaningful or not. It also feels a bit more rusty?Just throwing this suggestion into the discussion from the sideline, feel free to ignore me if you have a strong opinion about it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree in general (zero is a pretty crap default value), though I am wondering if there are cases where the user might want the objective value when the
HighsModelStatusisn'tOptimal(i.e. it hasn't fully converged). I'm not sure what HiGHS would do in this case.What do you think @lovasoa? Are you happy to return
Noneif the status is anything other than optimal?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
An alternative would be to panic if the status is not optimal, then the onus is on the user to ensure this doesn't happen.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ideally the behavior should match what highs does ? Return None in situations where Highs does not set the value, return Some when highs does have a value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You definitively want the objective if the search stopped before proving the optimality. The case where this value would be meaningless are unfeasible, unbounded, and no feasible solution found.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@lovasoa I'm assuming you'd still like to return
Nonein the case that no error has occurred?Looking at
HighsModelStatus, I think the following statuses would indicate that there is a meaningful objective value:OptimalObjectiveTargetReachedTimeLimitReachedIterationLimit(We could also include
Unknownif we want to be conservative.)]So if we want to return an
Option<f64>from this method, we could returnSome(objective_value)if the status matches any of the above, elseNone.HOWEVER: I'm not totally confident that an objective value would not be returned for certain other statuses, such as
SolveError. It would be good to have this confirmed.Alternatively, we can just update the doc comment to state that zero may be returned in case of error and put the responsibility back onto the user to check the status before using this value.
Let me know what you prefer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm fairly certain that the objective value - as with everything in Highs::info_ - always has a value, since it's cleared when HiGHS:: run() is called. I'll confirm tonight, when I'm at a computer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the response @jajhall! I've noticed it seems to have a value of 0.0 when the model is infeasible, for example, but I'm not sure about other cases. I assume zero is the default value.
I think the suggestion here was that we could return
Noneinstead for cases where there isn't a meaningful objective value, as that's maybe a bit more "Rust-y" (it would help prevent accidental use of the value in cases where the model is infeasible etc.). But we could just return the value given by HiGHS and mention that it might be zero in case of error in the documentation, which I think would also be fine. That would have the advantage of being simpler and not requiring changes if new statuses are added to HiGHS in future.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm okay with both solutions. If we have a guarantee that
Highs_getObjectiveValuedoes not access uninitialized memory even in cases when no value is available, then we can just return an f64, and be clear about its value in the documentation in all cases.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That sounds simplest. I'll update the docs and add a test as you suggest.