Hello everybody,

I am currently trying to establish my first GAMS model. However, I can’t figure out a solution for my problem.

I have a variable x, which depends on a sector and a time: x (sector, time)

The goal is to find the optimal x for each hour of the year for my problem.

In my model I have the condition that if x(sector1, t) is 0 and for the next hour at x(sector1, t+1) is positiv, it has to be positiv for the next three hours.

My former solution to model this was to use an equation. It is in the following code:

equation1(t)$((x(‘sector1’,t)=0)and(x(‘sector1’,t+1)>0)) … x(‘Cement’,t+2) and x(‘Cement’,t+3) and x(‘Cement’,t+4) =g= 1;

Does anybody know a solution to my problem?

Any form of help is appreciated. Thank you in advance.

Hi,

Your () expression on the equation contains endogenous variables. That's not possible. The () on the equation determines at model generation if the equation should be part of your model or not. You want this constraint in your model, so you need to implement:

equation1(t)… ((x(‘sector1’,t)=0)and(x(‘sector1’,t+1)>0)) => x(‘Cement’,t+2) and x(‘Cement’,t+3) and x(‘Cement’,t+4);

I assume x to be a binary variable, otherwise *x(‘Cement’,t+2) and x(‘Cement’,t+3) and x(‘Cement’,t+4)* makes little sense. Then x(‘sector1’,t+1)>0 becomes x(‘sector1’,t+1)>=1. Optimization with strict greater or less is difficult (see e.g. http://yetanothermathprogrammingconsultant.blogspot.com/2017/03/strict-inequalities-in-optimization.html).

If this is the only logical constraint (and x is indeed a binary variable) you can declare equation1 as “logic equation” (see https://www.gams.com/latest/docs/UG_Equations.html#UG_Equations_Def_LogicEquations) and “solve” as model type EMP and solver LogMIP. This will reformulate into a MIP/MINLP and solve with a regular MINLP solver.

If you have more of this type, x is an integer variable, or you want to understand what goes on behind the scenes you should reformulate this your self. There is a lot of literature available dealing with reformulations for logical conditions. The popular Big M method even has its own Wikipedia article: https://en.wikipedia.org/wiki/Big_M_method

To give you just one reference: The book Model Building in Mathematical Programming by H.P Williams (https://www.wiley.com/en-us/Model+Building+in+Mathematical+Programming%2C+5th+Edition-p-9781118443330) is good in general and has a section dedicated to Logical conditions (9.2).

-Michael