Condition in an equation

Problems with syntax of GAMS
Post Reply
Posts: 1
Joined: 8 months ago

Condition in an equation

Post by Philipp4747 » 8 months ago

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.

User avatar
Posts: 330
Joined: 2 years ago

Re: Condition in an equation

Post by bussieck » 8 months ago


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://yetanothermathprogrammingconsult ... ation.html).

If this is the only logical constraint (and x is indeed a binary variable) you can declare equation1 as "logic equation" (see ... cEquations) 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:
To give you just one reference: The book Model Building in Mathematical Programming by H.P Williams ( ... 1118443330) is good in general and has a section dedicated to Logical conditions (9.2).


Post Reply