GAMS-dev / gams.jl

A MathOptInterface Optimizer to solve JuMP models using GAMS
MIT License
34 stars 3 forks source link

Add support of JuMP variable/constraint names on GAMS level #12

Closed MartinBonde closed 2 years ago

MartinBonde commented 2 years ago

I am sending a JuMP model to CONOPT4 using GAMS.jl and get an error/warning: ** Error in Square System: A variable tries to exceed its bound.

This is perfectly familiar and I get more information by looking in the generated moi.lst file to find out which variable is the culprit:

**** ERRORS/WARNINGS IN VARIABLE x382 1 error(s): The variable tries to exceed its bound.

Is there any way of identifying what “x382” refers to in the above?

miles.lubin on discourse suggested opening an issue since "JuMP does provide the capability to pass variable names down to the solver."

renkekuhlmann commented 2 years ago

Yeah, there is currently no feature to look up the autogenerated names. I agree that it would be useful to use the JuMP variable names on the GAMS level. I'll look into it. Thanks for the feature request.

renkekuhlmann commented 2 years ago

I added writing the variable and constraint (only linear and quadratic) names that the user passes to the generated GAMS model with v0.3.0 - along with some other updates. Note however, that GAMS is very restrictive when it comes to variable naming and that something like x[1,2] or β is not allowed in GAMS source. Therefore, forbidden characters are replaced by _. I can then happen that the name is invalid because it will start with _, e.g. if you are using unicode symbols. In that case GAMS.jl should fall back to generic names. I hope this solution is fine for debugging. The generated files were never meant to be beautiful 😉

Version 0.3.0 should be available in a moment.

MartinBonde commented 2 years ago

Thanks! That should work except for the issue with not just illegal characters, but also case insensitivity of GAMS. Would it be possible to access some mapping (e.g. a dict) between the two? The users can easily do a search and replace of any error message or LST file if needed.

renkekuhlmann commented 2 years ago

Right, I forgot about this. I guess I should revert back to the generated names then, because otherwise the possibility of provoking GAMS compilation errors is too high. Instead, I will introduce Attributes in order to get the mapping, e.g.:

MOI.get(model, GAMS.GeneratedVariableName(), x[1,1])
MOI.get(model, GAMS.OriginalVariableName("x1"))
renkekuhlmann commented 2 years ago

Okay, done with the latest commit, see https://github.com/GAMS-dev/gams.jl#gams-names-vs-jump-names. Version 0.3.1 will be available soon.

MartinBonde commented 2 years ago

Looks great! I did not realize there was an issue with naming restrictions when I opened the issue, but this seems like a good solution. I look forward to trying it.