Skip to content
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

Add WithMipGap trait #38

Merged
merged 8 commits into from
Aug 25, 2023
Merged

Add WithMipGap trait #38

merged 8 commits into from
Aug 25, 2023

Conversation

mfuhr
Copy link
Contributor

@mfuhr mfuhr commented Aug 22, 2023

Add a WithMipGap trait and implement it for coin_cbc, highs, and lp_solvers. This trait mimics the trait of the same name that we recently added to the lp-solvers crate.

Implementing WithMipGap for lpsolve and scip appears to be non-trivial so I haven't done those, and minilp doesn't support integer variables.

I created a macro for generating tests of the WithMipGap trait. This is my first experience writing a Rust macro so hopefully it's okay. It does work as intended.

src/solvers/macros.rs Outdated Show resolved Hide resolved
src/solvers/mod.rs Outdated Show resolved Hide resolved
@lovasoa
Copy link
Collaborator

lovasoa commented Aug 22, 2023

@mmghannam any idea how hard it would be to implement mip gap in russcip ?

@mfuhr
Copy link
Contributor Author

mfuhr commented Aug 23, 2023

I think implementing MIP gap in russcip should be as simple as calling model.set_real_param("limits/gap", gap) but set_real_param is implemented only when the model is in the Unsolved state and the state changes almost immediately after the scip() function creates it:

let mut model = Model::new()  // state is Unsolved
        .hide_output()  // state is Unsolved
        .include_default_plugins()  // state is PluginsIncluded
        .create_prob("problem") // state is ProblemCreated
        .set_obj_sense(match to_solve.direction {
            ObjectiveDirection::Maximisation => ObjSense::Maximize,
            ObjectiveDirection::Minimisation => ObjSense::Minimize,
        });  // state is ProblemCreated

A with_mip_gap method might be able to call model.try_new() to get the model back into the Unsolved state so we can call set_real_param but then we'd have to get the model back into the ProblemCreated state before returning. I haven't investigated any farther yet.

@lovasoa
Copy link
Collaborator

lovasoa commented Aug 23, 2023

@mmghannam what do you think? Maybe russcip could allow setting parameters in the ProblemCreated state? Or would that introduce the possibility for an inconsistent state ?

@mfuhr : anyway, I don't see an issue with with merging this PR without russcip support now, and adding it later.

@mmghannam
Copy link
Contributor

@mmghannam what do you think? Maybe russcip could allow setting parameters in the ProblemCreated state? Or would that introduce the possibility for an inconsistent state ?

Setting parameters in ProblemCreated state should be fine as far as I know. I added an issue scipopt/russcip#105. I'm just not sure when I'll have time to work on it.

@mfuhr
Copy link
Contributor Author

mfuhr commented Aug 23, 2023

How's the latest?

src/solvers/mod.rs Outdated Show resolved Hide resolved
@mfuhr mfuhr requested a review from lovasoa August 25, 2023 16:22
@mfuhr
Copy link
Contributor Author

mfuhr commented Aug 25, 2023

@lovasoa I'd be happy to make any more changes you suggest. Thanks for the help -- I'm pretty new to Rust and to GitHub collaboration so your feedback has been very useful!

Copy link
Collaborator

@lovasoa lovasoa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

great, and the example is very well explained. Thanks, I'll release a new version.

@lovasoa lovasoa merged commit a9285c3 into rust-or:main Aug 25, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants