Help with Endogenous Relational Operations Error
Help with Endogenous Relational Operations Error
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

 Attachments

 CDfile.gms
 (2.13 KiB) Downloaded 9 times

 Pol.txt
 (2 KiB) Downloaded 7 times
Re: Help with Endogenous Relational Operations Error
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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
defgt1.. x =g= c1  (1bgt)*bigMgt;
defgt2.. x =l= c1  1e6 + bgt*bigMgt;
* models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
deflt1.. x =l= c2 + (1blt)*bigMlt;
deflt2.. x =g= c2 + 1e6  blt*bigMlt;
This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
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

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
Thank you very much, Michael. This really helped.
Bruno
On Monday, April 18, 2016 at 1:32:44 AM UTC3, Michael Bussieck wrote:
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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
defgt1.. x =g= c1  (1bgt)*bigMgt;
defgt2.. x =l= c1  1e6 + bgt*bigMgt;
* models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
deflt1.. x =l= c2 + (1blt)*bigMlt;
deflt2.. x =g= c2 + 1e6  blt*bigMlt;
This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
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

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
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 UTC3, Michael Bussieck wrote:
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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
defgt1.. x =g= c1  (1bgt)*bigMgt;
defgt2.. x =l= c1  1e6 + bgt*bigMgt;
* models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
deflt1.. x =l= c2 + (1blt)*bigMlt;
deflt2.. x =g= c2 + 1e6  blt*bigMlt;
This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
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

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
Michael, I have one more question:
Will the variable "result" in equations defr1 and defr2 be the same?
Many thanks.
Bruno
On Monday, April 18, 2016 at 12:43:49 AM UTC3, Bruno Hannud wrote:
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

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
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
On Monday, April 18, 2016 at 11:09:46 PM UTC4, Bruno Hannud wrote:
Michael, I have one more question:
Will the variable "result" in equations defr1 and defr2 be the same?
Many thanks.
Bruno
On Monday, April 18, 2016 at 12:43:49 AM UTC3, Bruno Hannud wrote:
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

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
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 = exprBexprA. With exprA>exprB we need to subtract and hence nslA = exprAexprB. 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/ModelBuildingMathematicalProgrammingWilliams/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
On Monday, April 18, 2016 at 11:09:46 PM UTC4, Bruno Hannud wrote:
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 UTC3, Michael Bussieck wrote:
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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
defgt1.. x =g= c1  (1bgt)*bigMgt;
defgt2.. x =l= c1  1e6 + bgt*bigMgt;
* models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
deflt1.. x =l= c2 + (1blt)*bigMlt;
deflt2.. x =g= c2 + 1e6  blt*bigMlt;
This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
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

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
Thank you very much Michael.
Bruno
Sent with Unibox
> On Apr 19, 2016, at 12:57 AM, Michael Bussieck
>
> 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 = exprBexprA. With exprA>exprB we need to subtract and hence nslA = exprAexprB. 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/ModelBuildingMathematicalProgrammingWilliams/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
>
>
> On Monday, April 18, 2016 at 11:09:46 PM UTC4, Bruno Hannud wrote:
>
> 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 UTC3, Michael Bussieck wrote:
>
> 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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
> defgt1.. x =g= c1  (1bgt)*bigMgt;
> defgt2.. x =l= c1  1e6 + bgt*bigMgt;
>
> * models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
> deflt1.. x =l= c2 + (1blt)*bigMlt;
> deflt2.. x =g= c2 + 1e6  blt*bigMlt;
>
> This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
>
>
> On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
>
> 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
>
> 
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to gamsworld@googlegroups.com.
> Visit this group at https://groups.google.com/group/gamsworld.
> For more options, visit https://groups.google.com/d/optout.

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
Michael, tks a lot for the bibliography.
Bruno
Sent with Unibox
> On Apr 19, 2016, at 12:57 AM, Michael Bussieck
>
> 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 = exprBexprA. With exprA>exprB we need to subtract and hence nslA = exprAexprB. 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/ModelBuildingMathematicalProgrammingWilliams/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
>
>
> On Monday, April 18, 2016 at 11:09:46 PM UTC4, Bruno Hannud wrote:
>
> 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 UTC3, Michael Bussieck wrote:
>
> 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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
> defgt1.. x =g= c1  (1bgt)*bigMgt;
> defgt2.. x =l= c1  1e6 + bgt*bigMgt;
>
> * models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
> deflt1.. x =l= c2 + (1blt)*bigMlt;
> deflt2.. x =g= c2 + 1e6  blt*bigMlt;
>
> This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
>
>
> On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
>
> 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
>
> 
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to gamsworld@googlegroups.com.
> Visit this group at https://groups.google.com/group/gamsworld.
> For more options, visit https://groups.google.com/d/optout.

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Re: Help with Endogenous Relational Operations Error
Thank you Frank.
Sent with Unibox
> On Apr 19, 2016, at 11:12 AM, Frank Ward
>
> Bruno,
>
>
> I believe that a good part of that book below (Math Programming) is web posted.
>
>
> Frank Ward
>
>
> From:gamsworld@googlegroups.com [mailto:gamsworld@googlegroups.com]On Behalf Of Bruno Hannud
> Sent:Tuesday, April 19, 2016 6:43 AM
> To:gamsworld@googlegroups.com
> Subject:Re: Help with Endogenous Relational Operations Error
>
>
> Michael, tks a lot for the bibliography.
>
>
> Bruno
>
>
>
>
> Sent with Unibox
>
>
>
> On Apr 19, 2016, at 12:57 AM, Michael Bussieck
>
>
> 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 = exprBexprA. With exprA>exprB we need to subtract and hence nslA = exprAexprB. 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/ModelBuildingMathematicalProgrammingWilliams/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
>
>
> On Monday, April 18, 2016 at 11:09:46 PM UTC4, Bruno Hannud wrote:
>
> 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 UTC3, Michael Bussieck wrote:
>
> 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= (1b)*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 <= c11e6 (in optimization we can't model x < c1).
> defgt1.. x =g= c1  (1bgt)*bigMgt;
> defgt2.. x =l= c1  1e6 + bgt*bigMgt;
>
> * models blt=1 <=> x <= c2, actually blt=1 => x<=c2 and blt=0 => x >= c2+1e6 (in optimization we can't model x > c2).
> deflt1.. x =l= c2 + (1blt)*bigMlt;
> deflt2.. x =g= c2 + 1e6  blt*bigMlt;
>
> This changes your model type to MINLP. The various bigM need to be bounds on the exprA, exprB, xc1, xc2 (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
>
>
> On Sunday, April 17, 2016 at 11:43:49 PM UTC4, Bruno Hannud wrote:
>
> 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
>
> 
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to gamsworld@googlegroups.com.
> Visit this group at https://groups.google.com/group/gamsworld.
> For more options, visit https://groups.google.com/d/optout.
>
> 
> To unsubscribe from this group and stop receiving emails from it, send an email togamsworld+unsubscribe@googlegroups.com.
> To post to this group, send email to gamsworld@googlegroups.com.
> Visit this group at https://groups.google.com/group/gamsworld.
> For more options, visit https://groups.google.com/d/optout.
>
> 
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to gamsworld@googlegroups.com.
> Visit this group at https://groups.google.com/group/gamsworld.
> For more options, visit https://groups.google.com/d/optout.

To unsubscribe from this group and stop receiving emails from it, send an email to gamsworld+unsubscribe@googlegroups.com.
To post to this group, send email to gamsworld@googlegroups.com.
Visit this group at https://groups.google.com/group/gamsworld.
For more options, visit https://groups.google.com/d/optout.
Return to “Archive Google Group”
Who is online
Users browsing this forum: No registered users and 2 guests