Help with Endogenous Relational Operations Error

60 views
Skip to first unread message

Bruno Hannud

unread,
Apr 17, 2016, 11:43:49 PM4/17/16
to gamsworld
Dear All.

I am trying to force a boundary condition in my model and this error appears. Could anyone help me in a way out please.

The code is attached.

tks a lot!

Bruno
Pol.txt
CDfile.gms

Michael Bussieck

unread,
Apr 18, 2016, 12:32:44 AM4/18/16
to gamsworld
Bruno,

The GAMS compiler is not very helpful here. The problem is a construct in the macros HT and ST which are used in equation DeltaGi. Here you have something like (simplified) expr1$(expr2). Expression expr2 contains a variable "Ti(i)" when GAMS expands the macro for equation DeltaGi. This is not allowed in GAMS. The error is only shown when GAMS compiles the solve statement. Right now I cannot think of a scenario why GAMS should not mark the equation when it compiles the equation algebra, I need to check with my colleagues. Anyhow, you need to reformulate this. The easiest way if to use the ifthen function: ifthen(expr2, expr1, 0). If expr2 is there to protect against domain violation errors, this will not necessarily help, because the GAMS function interpreter evaluates all three arguments of the ifthen function, independent of the value of the first argument. You code looks actually more like two function definitions based on the value of a variable. So the ifthen function should work okay.

The other trouble with ifthen is that it is not accepted by global solvers with the notable exception of Lindo. An alternative way to model ifthen(x >= c1 and x <= c2, exprA, exprB) this is to use binary variables (that's what Lindo does probably under the hood):

variable result;
positive variable pslA, nslA, pslB, nslB;
binary variable b;

* models result=ifthen(b, exprA, exprB)
defr1.. result =e= exprA + pslA - nslA;
defr2.. result =e= exprB + pslB- nslB;
defslA.. pslA + nslA =l= (1-b)*bigMA;
defslB.. pslB + nslB =l= b*bigMB;

binary variables blt, bgt;

* models b = blt and bgt
defb1.. b =g= blt + bgt - 1;
defb2.. b =l= blt;
defb3.. b =l= bgt;

* models bgt=1 <=> x >= c1, actually bgt=1 => x>=c1 and bgt=0 => x <= c1-1e-6 (in optimization we can't model x < c1).
defgt1.. x =g= c1 - (1-bgt)*bigMgt;
defgt2.. x =l= c1 - 1e-6 + bgt*bigMgt;

* models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e-6 (in optimization we can't model x > c2).
deflt1.. x =l= c2 + (1-blt)*bigMlt;
deflt2.. x =g= c2 + 1e-6 - blt*bigMlt;

This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, x-c1, x-c2 (so bounds on x)  and should be selected as small as possible (for good numerics, so don't set them to 1e9 which we see very often in bad models).

Hope this helps,
Michael Bussieck - GAMSWorld Coordinator

Bruno Hannud

unread,
Apr 18, 2016, 7:32:17 AM4/18/16
to gamsworld
Thank you very much, Michael. This really helped.

Bruno 

Bruno Hannud

unread,
Apr 18, 2016, 11:09:46 PM4/18/16
to gamsworld
Michael, I have one more question:

Will the variable "result" in equations defr1 and defr2 be the same?

Many thanks.

Bruno

Bruno Hannud

unread,
Apr 18, 2016, 11:09:46 PM4/18/16
to gamsworld
Dear Michael,

I've been through your post and have a couple of questions.

If b = 1, wouldn't eq defsIA = 0?
If b = 0, defsIB = 0?

If so, shouldn't defr1 read result =e=exprA + psIA + nsIA instead of psIA - nsIA? And so for defr2?

Tks

Bruno

On Monday, April 18, 2016 at 1:32:44 AM UTC-3, Michael Bussieck wrote:

Michael Bussieck

unread,
Apr 18, 2016, 11:40:39 PM4/18/16
to gamsworld
Bruno,

result is a single variable, so it can only have one value, independent in how many equations it shows up.


Michael Bussieck - GAMSWorld Coordinator

Michael Bussieck

unread,
Apr 18, 2016, 11:57:28 PM4/18/16
to gamsworld
Bruno,

I don't understand what you mean by "defslA = 0". If b=1 then defslA will become "pslA + nslA =l= 0" which will make pslA and nslA both 0 since they are positive variables, which will then in turn let defr1 read as follows "result =e= exprA;". Same with b=0 and exprB. We do need defr1 read "result =e= exprA + pslA - nslA;" because if b=0 (and hence result =e= exprB) the slack variable pslA and nslA have to take the difference between exprA and exprB. Imaging exprB > exprA, then we need to set pslA = exprB-exprA. With exprA>exprB we need to subtract and hence nslA = exprA-exprB. In essence, you have sl = exprA - exprB which can be <= or >= 0 and you split this up in its positive and negative part: sl = psl - nsl.

This is a trick of the trade used in many many models. You find a good and more thorough description of such standard "tricks" e.g. in the book of HP Williams "Model Building in Mathematical Programming" (http://www.amazon.com/Model-Building-Mathematical-Programming-Williams/dp/1118443330/ref=sr_1_1). These "tricks" result in weak formulations and it is good to apply model knowledge to the reformulation (e.g. if you know that exprA is always greater or equation exprB, you don't need the nslA and pslB).


Hope this helps,
Michael Bussieck - GAMSWorld Coordinator


Bruno Hannud

unread,
Apr 19, 2016, 7:35:07 AM4/19/16
to gams...@googlegroups.com
Thank you very much Michael.

Bruno


Sent with Unibox

-- 
You received this message because you are subscribed to a topic in the Google Groups "gamsworld" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gamsworld/CYoGbymswds/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gamsworld+...@googlegroups.com.
To post to this group, send email to gams...@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.

Bruno Hannud

unread,
Apr 19, 2016, 8:44:10 AM4/19/16
to gams...@googlegroups.com
Michael, tks a lot for the bibliography.

Bruno


Sent with Unibox

On Apr 19, 2016, at 12:57 AM, Michael Bussieck <mbus...@gams.com> wrote:

-- 

Frank Ward

unread,
Apr 19, 2016, 10:18:38 AM4/19/16
to gams...@googlegroups.com

Bruno,

 

I believe that a good part of that book below (Math Programming) is web posted.

 

Frank Ward

--
You received this message because you are subscribed to the Google Groups "gamsworld" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+...@googlegroups.com.

Bruno Hannud

unread,
Apr 20, 2016, 3:16:56 AM4/20/16
to gams...@googlegroups.com
Thank you Frank. 


Sent with Unibox
Reply all
Reply to author
Forward
0 new messages