## How to formulate the indicator constraint correctly?

Problems with syntax of GAMS
GabrielYin
User Posts: 60
Joined: 4 years ago
Location: Dallas, TX, USA
Contact:

### How to formulate the indicator constraint correctly?

Hello,

I'm trying to formulate an indicator constraint. I'm using a small example for testing, but it still failed.

I used the small example from the GAMS official website, slightly modified though:

Here is the code

Code: Select all

``````set      i       /i1, i2, i3/
j       /j1, j2, j3/;

Binary Variable use(i,j);
positive variable x(i,j);
variable z;

Equations
iminship(i,j), imaxship(i,j), ieqship(i,j), cost, binrel(i,j);

iminship(i,j)..   x(i,j) =g= 0;
imaxship(i,j)..   x(i,j) =l= 50;
ieqship(i,j)..    x(i,j) =e= 0;
cost..            z =e= 20 * sum(i, sum(j, x(i,j)));
binrel(i,j)\$(ord(i)=1)..     use(i,j) =e= 0;

Model indicatorModel /all/ ;

file fcpx Cplex Option file / cplex.opt /;
putclose fcpx 'indic iminship(i,j)\$use(i,j) 1' / 'indic ieqship(i,j)\$use(i,j) 0';
indicatorModel.optfile = 1;

Solve indicatorModel using mip maximizing z ;
``````
I did strictly follow the syntax in the GAMS official website to write the option file but it still gave the following error:

Code: Select all

``````Error: Variable not in model
Option record: indic iminship(i,j)\$use(i,j) 1
``````
Can anyone enlighten me on what I did wrong here for the small test? Thanks!

P.S. I also tried formulating it in my big instance but it gave me a different error of

Code: Select all

`` Error: Column is not of type Variable ``

Though it is a separate issue, I would highly appreciate it if someone could shed some light on this error as well!

Best,
Gabriel

Fred
Posts: 313
Joined: 6 years ago

### Re: How to formulate the indicator constraint correctly?

Gabriel,

Trouble is that binary variable use(i,j) occurs in the model only with i=i1. If you change the cplex option file to

Code: Select all

``````indic iminship('i1','j1')\$use('i1','j1') 1
indic iminship('i1','j2')\$use('i1','j2') 1
indic iminship('i1','j3')\$use('i1','j3') 1
indic ieqship('i1','j1')\$use('i1','j1') 0
indic ieqship('i1','j2')\$use('i1','j2') 0
indic ieqship('i1','j3')\$use('i1','j3') 0
``````
the error should disappear. I agree that the example from the documentation can be misleading.
I did strictly follow the syntax in the GAMS official website to write the option file but it still gave the following error:

Code: Select all

``````Error: Variable not in model
Option record: indic iminship(i,j)\$use(i,j) 1
``````
Can anyone enlighten me on what I did wrong here for the small test? Thanks!
This is discussed in the documentation:

There are situations where the indicator binary variable exist in the indicator constraint only and hence will not be generated by GAMS to be passed on to the solver. In such cases the solver will issue the following error message:
Error: Column is not of type Variable

I hope this helps!

Fred