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

loadProblem() with a single function call #56

Open
grinya007 opened this issue Jul 3, 2023 · 2 comments
Open

loadProblem() with a single function call #56

grinya007 opened this issue Jul 3, 2023 · 2 comments

Comments

@grinya007
Copy link

Hello!

I'm working with various models in the domain of Energy Markets. Some of my models are quite large (tens of millions of variables, millions of constraints) and I'm constantly looking for ways to improve the solving time. I would love to experiment with SCIP but I couldn't find a way to pass the entire problem to the solver with a single function call (well, 3-4 would be ok too but not millions ;)
I developed a generic solver interface for my kind of models, such that at the high level takes network objects (such as Supply/Transport/Demand nodes and Edges) and at the low level passes corresponding variables and constraints down to a solver in the form of ordered lower_bound/upper_bound/cost arrays for variables, and CSC matrix and bounds arrays for constraints.
So far, I managed to integrate my library with

  1. Gurobi via GRBloadmodel
  2. CBC via Cbc_loadProblem
  3. HiGHS via Highs_passLp/Highs_passMip

I'm sure a similar method exists in Mosek but I haven't had a chance to integrate with it just yet.
These methods allow me to quickly integrate different solvers through thin driver libraries as my generic library outputs almost exactly what these methods accept. But I can't find any similar function in the C API of SCIP and the need to pass every variable and constraint with a function call holds me back.

I saw this struct_matrix.h in the docs but it seems this structure can only be read from the model once it is all set up and never used to actually create/load a problem.

I hope to be wrong, or let this be a feature request otherwise =)

Thank you!

@sschnug
Copy link

sschnug commented Jul 6, 2023

Afaik there is no algebraic modelling (or let's say matrix-based modelling) available in SCIP, meaning: there is no way to define a vector / batch of variables and there is no way to define a vector / batch of constraints defined by a constraint coeff-matrix and a constraint rhs-vector.
Each var and each constraint introduced needs an explicit call to do that.

That being said, i don't see the issue.

Targeting this kind of low-lvl algebraic structure (i'm having Highs in mind which i once filled with some parent which also filled or-tools' PDLP) sounds relatively straightforward to me:

  • One loop over your coeff-matrix columns for introducing variables
  • One loop over your coeff-matrix rows for introducing linear-constraints (SCIP actually also provides range-constraints out of the box)

I would guess that's < 100 lines of code. Maybe even < 50 if one would store the algebraic model in something like Eigen. Don't forget the necessary memory-management (SCIPfree...)

Don't you agree, that a 50-100 loc wrapper external_to_scip(...) is a small investment?

One more remark:

  • There might also be a way to just write out lp/mps in one of your other tools and read that into SCIP (even through streams/pipes if "real" files make you nervous)

One more opinion:

  • I think the most interesting part of SCIP (where it even surpasses all commercial solvers and other alternatives) is it's plugin system and what you can do with it:
    • One might argue, that the information-loss you experienced by importing the low-lvl model instead of the high-lvl model is problematic
      • It's not uncommon in my code, that SCIP types are embedded into some high-lvl C++ types like EigenMatrix or boost::graph which (depending on your problem) allows lots of powerful things!

@ambros-gleixner
Copy link
Member

Hi, you are correct that there is no such matrix-based problem creation function in SCIP. I agree that this would be a nice convenience feature. It could be an addition to the interface of cons_linear. I don't think we are going to implement that ourselves, but we would welcome and support a PR! (The solution is pretty much a combination of for loops as described by @sschnug .)

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

No branches or pull requests

3 participants