Closed rrandall1471 closed 1 year ago
Yes we need some name cleanup handling or warnings here, similar to what we discussed with datetime formats when we met last. There is a bit to think about but we can have saner defaults for sure.
Can you send a minimal example of where the constraint name occurs? I guess you are creating constraints from a dataframe with a four level index?
Simon,
I've attached several models that seem to cause problems with exporting:
Constraint Multi-index.ipynb.gz
- In an index data value there is a space, this prevents the model from being exported correctlySpace in Data.ipynb.gz
- There is a multi-index in the constraint name, this by default has spaces in it in the current gurobipy
implementation, whereas vars do not have spaces between the comma and the next index value.Variable Name with Space.ipynb.gz
- This could be a miss in the gurobipy-pandas
implementation and something you should probably not allow to begin with. I was playing around with the variable name and gave it one with a space in the name, I tried to use the pandas query notation and surround it with back-ticks but it didn't like that. So you should probably throw an error when someone creates a variable name with a space or determine a method to allow them to use it when creating constraints.Another possible solution is that when you auto-create any names, substitute all spaces with an underscore _
. We did this with our own internally built naming function.
I did an example, and if I wrote out an LP file, I get a message about a space in the constraint names, but the resulting LP file has the spaces replaced with underscores. But if I write out an MPS file with the same model, the constraints are renamed to c0
, c1
, etc.
Thank you both for testing this thoroughly!
It looks like there might be an issue in how you're creating the constraint name and how that works with MPS naming conventions. I get the following message when I try to export my model to MPS, so that I can compare it to my original model.
It looks like the code that creates the full constraint name creates spaces after the commas in a multi-index, which is not allowed in MPS format. A second potential issue with exporting to MPS is that the
name
attribute inpd_add_constrs
would probably allow a column name with a space, and while it's fine for the code, no write function of the model will be happy with spaces (or various other symbols) that so at a minimum you'd probably want to provide a warning if you detect spaces in that attribute telling the user that any export of the model is going to have an issue or remove the space internally or throw an error.