PySCIPOpt icon indicating copy to clipboard operation
PySCIPOpt copied to clipboard

Remove Variable objects from variable data

Open steffanschlein opened this issue 4 years ago • 2 comments

The Python Variable objects created by Model.addVar() are stored as user data in the SCIP data structure:

SCIPvarSetData(scip_var, <SCIP_VARDATA*>pyVar)

In addition, in the same function the Model class implements a mechanism that maps SCIP_VAR pointers to the corresponding Python Variable objects:

self._modelvars[pyVar.ptr()] = pyVar

Currently, the latter mechanism is used for retrieving variables in Model.getVars(). The former mechanism is only used in the Benders plugin in getPyVar(). Having two mechanisms for mapping between Python and C variables seems reduant.

It should be possible to refactor the Benders plugin to access the Python variables through the Model reference that is stored in the plugin's wrapper class. There is a comment in the plugin that seems to hint that a refactoring of how variables are passed could be worthwhile. This would free the user data storage for other use-cases.

Background and motivation: In my project of extending PySCIPOpt for use with GCG, the occupied variable user data causes a problem. GCG stores information in the variable's data field and expects the content to be a GCG struct.

What are your thoughts on this change? I could provide a PR that refactors the Benders plugin.

steffanschlein avatar Sep 17 '21 11:09 steffanschlein

sounds good to me. @stephenjmaher, what do you think?

fserra avatar Sep 17 '21 14:09 fserra

That all sounds reasonable to me. Please put together a PR and we can have a look. Your suggestions seems like a good change.

stephenjmaher avatar Sep 20 '21 08:09 stephenjmaher

Hello @schlein! I am very late to the party, can you tell me what is the status of the PR? Can this issue be closed?

Joao-Dionisio avatar Mar 10 '23 15:03 Joao-Dionisio

Hi @Joao-Dionisio, It seems like I did not get to create the PR. I probably came up with a different solution that did not require the change. I’m no longer working on the project.

In case you want to follow up you could try the mail address of the GCG dev team: [email protected]

Sorry that a cannot give you more details on the issue.

steffanschlein avatar Mar 10 '23 17:03 steffanschlein

No worries! I'll be closing the issue then, to clear the issue page. If someone finds this and can pick it up, please do, and feel free to reopen the issue!

Joao-Dionisio avatar May 02 '23 09:05 Joao-Dionisio