GAMS parameter initialisation as Modifier in Python GAMSModelInstance

Questions on using the GAMS APIs (Python, .NET, etc.)
Post Reply
nechiforv
User
User
Posts: 8
Joined: 4 years ago

GAMS parameter initialisation as Modifier in Python GAMSModelInstance

Post by nechiforv »

Dear GAMS community,

I am encountering some difficulties trying to run an MCP model through GAMSModelInstance.

In the model, among other things, I have two equations of the type:
EQ1.. X =E= x0 + flag*X_SLACK
EQ2.. Y =E= y0 + (1-flag)*Y_SLACK
where flag is a parameter that take 0 or 1 values, and x0 and y0 are parameters with some default values for the X and Y variables.

As you can see, the two equations are related. When flag is 0, X is basically fixed to X_SLACK, while Y will have a Y_SLACK associated variable. When flag is 1, the opposite applies.

In GAMS, this model works well, with and without holdFixed set to 1.
However, through Python, I will get an error of ncols not equal to nrows. I get this error at the instantiate() stage after adding "flag" as a Modifier.

I presume this may come from a default initialisation of "flag" to some value that will allow both X_SLACK and Y_SLACK to be activated in the model and thus determining the model to be non-square.

Interestingly, if I were to turn flag into a fixed variable, the model would be non-square even in GAMS. I attempted this thinking that as a fixed variable I could attribute a value to it in Python by adding a data_symbol element in the Modifier definition.

Would you have any suggestions on how to get around this?

Many thanks.
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: GAMS parameter initialisation as Modifier in Python GAMSModelInstance

Post by dirkse »

Hi,

This sounds like an interesting problem. If you can provide a minimal sort of example that reproduces this, it seems likely I can provide some useful feedback.

As an example, have a look at the obstacle example in the GAMS model library:

https://www.gams.com/40/gamslib_ml/libh ... tacle.html

This MCP model might give you some hints on how to overcome your immediate hurdle. Also, it's an example of using GUSS. This is closely related to the GAMSModelInstance stuff but it doesn't require any python programming, so it's a handy way to verify things are working before writing any python code.

HTH,

-Steve
User avatar
dirkse
Moderator
Moderator
Posts: 214
Joined: 7 years ago
Location: Fairfax, VA

Re: GAMS parameter initialisation as Modifier in Python GAMSModelInstance

Post by dirkse »

Of course, if you are sending the MRE (Min Reproducible Example), you should also send the .log and .lst files from your run that exhibits the error.

-Steve
Post Reply