Using variable level in a conditional statement

Problems with syntax of GAMS
Post Reply
l_n_80
User
User
Posts: 4
Joined: 6 years ago

Using variable level in a conditional statement

Post by l_n_80 »

Hi all, many many thanks in advance for any help you can provide with the following issue:

I am attempting to solve an optimization problem which includes solution of a dynamic system via collocation. My goal is to calculate the time needed for this system to transition from one state to another: the (apparently) complicating factor is that I'd like to use a fixed step size and to allow the number of finite elements to vary. I have a specific syntactical question that I believe I need to resolve for my implementation to work:

I define an integer variable, numFE(S), as follows (bounds are known to be reasonable):

INTEGER VARIABLE numFE(S);
numFE.l(S) = 18;
numFE.lo(S) = 15;
numFE.up(S) = 20;

Later, in the code, I want to ensure that the system is within a tolerance of a desired point for elements greater than or equal to numFE(S):

BCCl(I,j,S)$(ORD(I) gt numFE.l(S)).. Cdes(S)- C(i,j,S) =g= - 0.001 ;

Of course, I very much need this conditional to hold true for the value of numFE returned in the solution!

Here is the issue: the conditional in the above equation is defined in terms of whatever level I initialize the problem at, instead of the level at the solution (in this case numFE is pushed to the lower bound in the absence of the proper interpretation of the equation above)! Here is the print out of the results.

--- VAR numFE

LOWER LEVEL UPPER MARGINAL

1 15.000 15.000 20.000 -0.263
2 15.000 15.000 20.000 -0.284
3 15.000 15.000 20.000 -0.355
4 15.000 15.000 20.000 -0.559

---- EQU BCCh

LOWER LEVEL UPPER MARGINAL

19.1.1 -INF -0.001 0.001 .
19.1.2 -INF -0.001 0.001 .
19.1.3 -INF 0.001 0.001 EPS
19.1.4 -INF 0.001 0.001 EPS
19.2.1 -INF -3.248E-4 0.001 .
19.2.2 -INF -1.726E-4 0.001 .
19.2.3 -INF 2.6447E-4 0.001 .
19.2.4 -INF 2.6678E-4 0.001 .
20.1.1 -INF -1.499E-4 0.001 .
20.1.2 -INF 2.0500E-4 0.001 .
20.1.3 -INF -1.617E-5 0.001 .
20.1.4 -INF 2.4321E-5 0.001 .
20.2.1 -INF 9.4688E-5 0.001 .
20.2.2 -INF 8.5717E-4 0.001 .
20.2.3 -INF -5.685E-4 0.001 .
20.2.4 -INF -3.928E-4 0.001 .


So, my question is how should I modify the above bolded expression so that the equation can be enforced conditionally upon the value of the variable numFE(S)? I have not been able to find any help in the GAMS user guide, since it seems from that chapter that my syntax should work. Thanks so much in advance!
cladelpino
User
User
Posts: 108
Joined: 7 years ago

Re: Using variable level in a conditional statement

Post by cladelpino »

Hi, to make a long story short:

Having constraints that are enforced or not depending on variable values is a thick topic within optimization.
It is not as straightforward as you wish, but not impossible. It usually involves reformulation of this constraints so that they are enforced or relax based on the value of binary variables.

The approach I use is based on something called "disjunctive programming". If you are not advised on this / not keen on writing your own, check out https://www.gams.com/latest/docs/usergu ... logmip.htm, or https://www.gams.com/latest/docs/usergu ... rl/emp.htm, which are "meta-solvers" within GAMS.

Good Luck
Claudio
l_n_80
User
User
Posts: 4
Joined: 6 years ago

Re: Using variable level in a conditional statement

Post by l_n_80 »

cladelpino wrote:Hi, to make a long story short:

Having constraints that are enforced or not depending on variable values is a thick topic within optimization.
It is not as straightforward as you wish, but not impossible. It usually involves reformulation of this constraints so that they are enforced or relax based on the value of binary variables.

The approach I use is based on something called "disjunctive programming". If you are not advised on this / not keen on writing your own, check out https://www.gams.com/latest/docs/usergu ... logmip.htm, or https://www.gams.com/latest/docs/usergu ... rl/emp.htm, which are "meta-solvers" within GAMS.

Good Luck
Claudio
Thanks Claudio! After posting this, I did in fact find a solution to my issue via the use of binary variables, which works well for my relatively small problem. Certainly not as straightforward as I expected. Will have to check out your references on disjunctive programming, thanks again!
Post Reply