Skip to content

Export variable and constraint names in LP files#391

Closed
olivierjuan wants to merge 0 commit intoPyPSA:masterfrom
olivierjuan:master
Closed

Export variable and constraint names in LP files#391
olivierjuan wants to merge 0 commit intoPyPSA:masterfrom
olivierjuan:master

Conversation

@olivierjuan
Copy link
Contributor

@olivierjuan olivierjuan commented Dec 6, 2024

A small modification to export LP files with variable and constraint names.
Gurobi is able to read the generated LP files.

This modification does not apply to polar export.
I'm ready to improve the code if needed

This is related to issue #157

@olivierjuan olivierjuan changed the title Export variable and constraints names in LP files Export variable and constraint names in LP files Dec 6, 2024
@olivierjuan
Copy link
Contributor Author

I'll fix the tests first

@olivierjuan
Copy link
Contributor Author

I added a new io_api type called "lp-debug" to write lp file with variable and constraint names. I don't know if you will like that approach. I can replace it by an extra argument to the function to_file instead if you prefer.

Copy link
Collaborator

@FabianHofmann FabianHofmann left a comment

Choose a reason for hiding this comment

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

pretty cool @olivierjuan! Thank you for your contribution! I would suggest to have an extra argument for this and raise an error if a non-supported io-api is passed. Could you check whether this has any impact on the regular lp file writing?

@olivierjuan
Copy link
Contributor Author

Ok. I'm on it

@olivierjuan
Copy link
Contributor Author

olivierjuan commented Dec 13, 2024

@FabianHofmann , I extended it to lp-polars too, and added tests to check with and without variable names.
A variable name is now passed with the following pattern '{name}#{index}' to maintain the logic of extracting the index of the variable from the name. (same for the constraint). This makes the export compatible with solving.
It seems to me that it is now feasible to extend it to direct io_api. Do you want me to try it ?
BTW, that will add it also to MPS file.

@olivierjuan
Copy link
Contributor Author

Well I did it in the end.
So the variable and constraint names can be transfered to the solver either for lp, lp-polars, mps or direct api.

Only CBC and GLPK are incompatible (if trying to solve with_names=True and with one of these solvers, a warning will be printed and the option will be deactivated).
I couldn't test it with mindopt due to issues with my mindopt license. But all other solvers work fine

@FabianHofmann
Copy link
Collaborator

Wow, well done @olivierjuan ! I promise to have a look soon and then we can merge it 🚀

Copy link
Member

@lkstrp lkstrp left a comment

Choose a reason for hiding this comment

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

Hey @olivierjuan, thanks for the contribution! This was a requested feature
We wanna get this merged now and have only some minor changes, e.g. use explicit_coordinate_names as argument name instead.
Would you mind if I just push those changes?

@olivierjuan
Copy link
Contributor Author

As you want, I fine with you modifying it.

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