<![CDATA[GAMS World Forum]]> https://forum.gamsworld.org Sat, 27 Apr 2024 14:27:30 +0000 Smartfeed extension for phpBB https://forum.gamsworld.org/styles/we_universal/theme/images/site_logo.svg <![CDATA[GAMS World Forum]]> https://forum.gamsworld.org en-GB Sat, 27 Apr 2024 14:27:30 +0000 60 <![CDATA[Syntax :: $ifThen set X or Y :: Author zamry]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31286#p31286
Is there a way to execute the following condition when solving a model?

Code: Select all

$ifThen set X or Y
Solve MODEL using nlp minimizing OBJ;
$else
Solve MODEL using lp minimizing OBJ;
$endIf
X and Y are compilation variables, and either one exists at a time.

Thanks,
Zamry]]>
no_email@example.com (zamry) https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31286#p31286 Mon, 01 Apr 2024 17:38:40 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31286#p31286
<![CDATA[Syntax :: Re: $ifThen set X or Y :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31288#p31288

Code: Select all

$set xset 0
$if set x $set xset 1
$set yset 0
$if set y $set yset 1
$log %xset%%yset%
$ifThenE (%xset%)or(%yset%)
Solve MODEL using nlp minimizing OBJ;
$else
Solve MODEL using lp minimizing OBJ;
$endIf
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31288#p31288 Tue, 02 Apr 2024 05:57:28 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31288#p31288
<![CDATA[Syntax :: Re: $ifThen set X or Y :: Reply by zamry]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31291#p31291 no_email@example.com (zamry) https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31291#p31291 Tue, 02 Apr 2024 14:00:36 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12985&p=31291#p31291 <![CDATA[Syntax :: Re: Error 2, Error 149, Error 243 :: Reply by Rodrigue]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31284#p31284
You might be a French speaker.
J'ai crois que tes équations ont un sérieux problèmes. Je ne sais pas comment tu les as obtenues. J'ai néanmoins fourni quelques pistes qui aident à corriger ton problème.

Cordialement,
Rodrigue

Attachments

new.gms (14.24 KiB)
]]>
no_email@example.com (Rodrigue) https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31284#p31284 Mon, 01 Apr 2024 10:17:12 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31284#p31284
<![CDATA[Syntax :: Re: Error 2, Error 149, Error 243 :: Reply by Essouaied Aziz]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31285#p31285
Merci bien pour votre réponse, ça m'a aidé à comprendre les défauts de mon code.
Mais là, ça me donne des résultats un peu étrange, finalement, j'ai besoin de minimiser le nombre de bus par lignes et par saison, tout en servant la méme demande par ces bus.
Les résultats sont du genre "668.000" pour un nombre de bus, ce qui n'est pas assez logique déjà. Je pense qu'il faut multiplier le résultat do code que vous avez suggérer par le facteur FV0(i,j), qui est le minimum de voyages qu'un bus peut faire par ligne i et par période j.
Aussi, je ne comprends pas pourquoi on a définit W.up, X. up, Y.up et Z.up par 34454 alors que la taille de la flotte des bus est de 76.

Votre clarification me sera utile.
Merci]]>
no_email@example.com (Essouaied Aziz) https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31285#p31285 Mon, 01 Apr 2024 15:58:54 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31285#p31285
<![CDATA[Syntax :: Re: Error 2, Error 149, Error 243 :: Reply by Rodrigue]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31292#p31292
Je n'ai pas solutionné ton problème. J'ai juste fait en sorte que ton code fonctionne. Les valeurs maximales que j'ai affectées à ces variables (en utilisant l'extension.Up) permettent juste que certaines valeurs croissent infiniment et empêchent GAMS de trouver une solution à ton problème. C'est à toi de les modifier pour attribuer des valeurs raisonnables.

Je dis encore ton modèle ne me semble pas bien monté. Il faut repenser les équations et s'assurer qu'elles sont correctes. Tu ne peux pas en l'état actuel interpréter ce que je t'ai envoyé. Ça ne signifie rien de bon.

Cordialement]]>
no_email@example.com (Rodrigue) https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31292#p31292 Wed, 03 Apr 2024 06:18:11 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31292#p31292
<![CDATA[Syntax :: Re: Error 2, Error 149, Error 243 :: Reply by Essouaied Aziz]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31293#p31293
Cher Rodriguez, merci beaucoup pour la réponse. Je comprends, je vais essayé de travailler encore sur le code et le solutionner (même si je suis encore un débutant à ce niveau).
Je partagerais le résultat une fois qu'il est trouvé.

Cdt;]]>
no_email@example.com (Essouaied Aziz) https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31293#p31293 Wed, 03 Apr 2024 08:51:39 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12979&p=31293#p31293
<![CDATA[Syntax :: A problem with parentheses :: Author Essouaied Aziz]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31298#p31298
I'am running a GAMS code with this command:

W.lo(i, j)$[(D(i, j)/55) ≤ (FV0(i, j) ∗ P(i) ∗ 55)] = FV0(i, j)/55;

Yet, I always get "Error 8: ')' expected", I've tried my best to count the parentheses and correct the command, but i didn't succeed.

Any help with this please?

Thnaks!]]>
no_email@example.com (Essouaied Aziz) https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31298#p31298 Wed, 03 Apr 2024 16:15:55 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31298#p31298
<![CDATA[Syntax :: Re: A problem with parentheses :: Reply by vistro]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31299#p31299 no_email@example.com (vistro) https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31299#p31299 Thu, 04 Apr 2024 05:31:34 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31299#p31299 <![CDATA[Syntax :: Re: A problem with parentheses :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31300#p31300
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31300#p31300 Thu, 04 Apr 2024 07:06:13 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31300#p31300
<![CDATA[Syntax :: Re: A problem with parentheses :: Reply by Essouaied Aziz]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31302#p31302 Thnak you both of you for the help!]]> no_email@example.com (Essouaied Aziz) https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31302#p31302 Thu, 04 Apr 2024 07:47:01 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=12993&p=31302#p31302 <![CDATA[Syntax :: Connecting ordered sets :: Author Exlaw]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31322#p31322 I am currently learning GAMS and I came up on this issue:
I am using these sets:

Sets
y "Set of years in the planning horizon" /y2023*y2045/
d "Set of all days in a year" /d1*d366/
t "Set of all hours in a day" /h1*h24/;

Then I am importing data for some parameters from excel. e.g. E(y,d,t)
Therefore I would prefer not to change the way my sets are defined, because I will need to change everything in my excel as well.

And further down the code, in certain equations I need to use variables like this one: "E_b_res(y,d,t-1)"
So is should work like this:

if ( ord(t)=1 AND ord(d)=1 AND E(y-1,'d366','h24') <> 0 )
x=E_b_res(y-1,'d366','h24')
else if ( ord(t=1) AND ord(d)=1 )
x=E_b_res(y-1,'d365','h24')
else if( ord(t=1) )
x=E_b_res(y,d-1,'h24')
else
x=E_b_res(y,d,t-1)


Where x is the value I need E_b_res(y,d,t-1) to have.

*note: in the E(y-1,'d366','h24') <> 0 part, I am checking whether or not its a leap year. My excel doesn't input values for d366 of non leap years so this is an easy way of checking

This felt very complex to do using the $ operator. I am also considering using Multi-Dimensional Sets, but I couldn't really figure out how they work just using the documentation. For example: why can't I define a variable over a multi-dimensional set?
I am pretty sure there are some easy solutions for this that I am missing.]]>
no_email@example.com (Exlaw) https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31322#p31322 Wed, 10 Apr 2024 16:09:28 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31322#p31322
<![CDATA[Syntax :: Re: Connecting ordered sets :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31338#p31338
-Michael

Code: Select all

Sets
  y "Set of years in the planning horizon" /y2023*y2045/
  d "Set of all days in a year" /d1*d366/
  t "Set of all hours in a day" /h1*h24/;
  
$eval P card(y)*card(d)*card(t)
Set p period / p1*p%P% /;

Parameter E(y,d,t), cnt /0/;
loop((y,d,t), cnt=cnt+1; E(y,d,t) = cnt);

* Remove data for non leap years
set leap(y) / y2024, y2028, y2032, y2036, y2040, y2044 /;
E(y,'d366',t)$(not leap(y)) = 0;

* Now match non-zero E to p:
set ydt(y,d,t), pydtmap(p,y,d,t);
option ydt<E, pydtmap(p:ydt);

* Have parameters in p space
alias (y,yy), (d,dd), (t,tt);
Parameter Ep(p); Ep(p) = sum(pydtmap(p,y,d,t), E(y,d,t));

Variable Ep_b_res(p), oo(d);
Equation balance(p), daystart(p);
balance(p).. Ep_b_res(p) =e= sum(pydtmap(p,y,d,t), oo(d))*(Ep_b_res(p-1) + Ep(p));
daystart(p)$sum(pydtmap(p,y,d,'h1'),1).. Ep_b_res(p) =l= 2*Ep_b_res(p-1);
]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31338#p31338 Thu, 18 Apr 2024 11:56:01 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31338#p31338
<![CDATA[Syntax :: Re: Connecting ordered sets :: Reply by Exlaw]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31340#p31340 no_email@example.com (Exlaw) https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31340#p31340 Fri, 19 Apr 2024 18:20:38 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=13011&p=31340#p31340 <![CDATA[Syntax :: BESS modeling Error 148 and 258 in obj function. :: Author GeGo]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=13021&p=31341#p31341 I get in the last line the following errors. I cant understand why,
*** Error 148 in C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms[ERR:"C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms",115,40][LST:102]
Dimension different - The symbol is referenced with more/less
indices as declared
*** Error 257 in C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms[ERR:"C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms",115,42][LST:102]
Solve statement not checked because of previous errors
--- PPA_PV_BESS.gms(115) 3 Mb 2 Errors[FIL:"C:\Users\eirini\Documents\GAMS\Studio\workspace\gams 240\PPA_PV_BESS.gms",115,0]
*** Status: Compilation error(s)[LST:151]
--- Job PPA_PV_BESS.gms Stop 04/20/24 15:52:36 elapsed 0:00:10.719

I want to maximize income so i am trying to fine the best combination of z and h for all t.

This is my code:
Set t "Time" /t1*t240/;
Set h "hour of bess" /h1*h4/;
Set z 'safety level of contracted energy' /z1*z2/;


Parameters
P_real(t)
P_ppa(t,z)
P_excess(t,z)
pvf(t) pv is in producing
mp(t) more profitable market price
iseop(t,z) there is excess of power P_real-P_ppa>0
SoCz1(t,h) 'state of charge time, hours of batery, z1'
SoCz2(t,h) 'state of charge time, hours of batery, z2'
SoC(t,h,z) 'state of charge time, hours of batery, safety level'
P_b2g(t,z) 'Power battery to grid';


$CALL GDXXRW P_r.xlsx trace=3 par=P_real rng=New_Sheet! rdim=1
$CALL GDXXRW P_p.xlsx trace=3 par=P_ppa rng=New_Sheet! rdim=1 cdim=1
$CALL GDXXRW P_e.xlsx trace=3 par=P_excess rng=Sheet1! rdim=1 cdim=1
$CALL GDXXRW pvf.xlsx trace=3 par=pvf rng=New_Sheet! rdim=1
$CALL GDXXRW iseop.xlsx trace=3 par=iseop rng=Sheet1! rdim=1 cdim=1
$CALL GDXXRW mp.xlsx trace=3 par=mp rng=New_Sheet! rdim=1
$CALL GDXXRW P_b2g.xlsx trace=3 par=P_b2g rng=Sheet1! rdim=1 cdim=1
$CALL GDXXRW SoC_z1.xlsx trace=3 par=SoCz1 rng=New_Sheet! rdim=1 cdim=1
$CALL GDXXRW SoC_z2.xlsx trace=3 par=SoCz2 rng=New_Sheet! rdim=1 cdim=1


$GDXIN P_r.gdx
$LOAD P_real
$GDXIN
*Display P_real;


$GDXIN P_p.gdx
$LOAD P_ppa
$GDXIN

$GDXIN P_e.gdx
$LOAD P_excess
$GDXIN

$GDXIN pvf.gdx
$LOAD pvf
$GDXIN

$GDXIN mp.gdx
$LOAD mp
$GDXIN

$GDXIN P_b2g.gdx
$LOAD P_b2g
$GDXIN

$GDXIN iseop.gdx
$LOAD iseop
$GDXIN

$GDXIN SoC_z1.gdx
$LOAD SoCz1
$GDXIN

$GDXIN SoC_z2.gdx
$LOAD SoCz2
$GDXIN

SoC(t,h,z)$(ord(z)=1) = SoCz1(t,h);
SoC(t,h,z)$(ord(z)=2) = SoCz2(t,h);

Scalar P_pv_max max PV power out put same as battery /8/;
Scalar SP_ppa strike price of the PPA /85/;


Parameter hb(h) hours of battery
/h1 1
h2 2
h3 4
h4 6/;




Variables
obj(h,z) objective function
C(h) 'variable for CAPEX'
ppa_i(z) 'income through ppa';



*SP_ppa.up = 195;
*SP_ppa.lo = 175;


Equations
Income ObjetiveFunction
CAPEX 'capital cost of pv+storage'
ppa_income 'income through ppa'
con_ppa_income_lb 'income through ppa lower bound';


*sto 2o athrisma tis antikimenikis sinartisis prepei na mpi mia diadiki metavliti
*b=1 otan SoC(T)>0, b=0 otan SoC(T)<=0 mporei na gini xoris senaria?
Income(h,z) .. obj(h,z) =e= sum(t,(P_ppa(t,z)/1000)*SP_ppa) + sum(t,(mp(t)*(1-pvf(t))*(P_b2g(t,z))))
+sum(t,(182*(P_excess(t,z)/1000)*(1-iseop(t,z))*pvf(t)))-C(h);

CAPEX(h) .. C(h) =e= (200000*P_pv_max+220000*hb(h)*P_pv_max)*240/(12*8760);
ppa_income(z).. ppa_i(z) =e= sum(t,(P_ppa(t,z)/1000)*SP_ppa);
con_ppa_income_lb(h,z).. ppa_i(z) =g= 0.5*C(h);



Model PP_PV_BESS /all/ ;
Option mip=cplex;
Solve PP_PV_BESS using lp maximizing obj ;]]>
no_email@example.com (GeGo) https://forum.gamsworld.org/viewtopic.php?f=2&t=13021&p=31341#p31341 Sat, 20 Apr 2024 13:06:10 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=13021&p=31341#p31341
<![CDATA[Syntax :: Re: BESS modeling Error 148 and 258 in obj function. :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=2&t=13021&p=31345#p31345
First the is a very nice formatting control to copy and paste code. Please use that. On the particular question. You have an objective variable obj(h,z), so for every h and z there is a variable and you ask the solver to optimize it. A solver can only optimize a single variable not h times z many. So GAMS assumes your obj is a scalar variable and hence complains that you use z as a 2-dim variable in the declaration and equations and as a scalar variable in the solve statement. Perhaps, you want to add all income, then you should redefine your income equation:

Code: Select all

Variables
obj objective function
Income .. obj =e= sum((h,z),sum(t,(P_ppa(t,z)/1000)*SP_ppa) + sum(t,(mp(t)*(1-pvf(t))*(P_b2g(t,z)))));

Hope this helps,
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=2&t=13021&p=31345#p31345 Sun, 21 Apr 2024 07:20:44 +0000 https://forum.gamsworld.org/viewtopic.php?f=2&t=13021&p=31345#p31345
<![CDATA[Modeling :: Erorr 149 :: Author osmane]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13003&p=31312#p31312
why am i getting error 149 here

s(i) service level of state i
d(j) Demand of state j
z(i,j) number of humanitarian kits sent from state i to state j]]>
no_email@example.com (osmane) https://forum.gamsworld.org/viewtopic.php?f=9&t=13003&p=31312#p31312 Sat, 06 Apr 2024 23:19:46 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13003&p=31312#p31312
<![CDATA[Modeling :: Re: Erorr 149 :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13003&p=31316#p31316
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=9&t=13003&p=31316#p31316 Mon, 08 Apr 2024 06:25:34 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13003&p=31316#p31316
<![CDATA[Modeling :: Nonlinear Programming/ Steiner Weber Modell with barriers :: Author Student75]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13007&p=31317#p31317 I would like to solve a mathematical model with GAMS and unfortunately I can't find the solution. I would like to solve the following problem with the GAMS programme:

I would like to carry out location planning taking a barrier into account. I will take the federal state of Brandenburg as an example. My demand/requirement locations are all cities in Brandenburg. I get the coordinates of the cities from Excel using geocoordinates and can thus determine the respective distances between the cities. To do this, I form a distance matrix between the cities and insert the values in a table in GAMS. I have one demand point per 200 inhabitants. For example, if I have 1000 inhabitants in a small town, then I have 5 demand points for this town. My barrier should be Berlin. The barrier area is represented by a circle or, even more simply, by the corner points of the rectangle as an area. The corner points of the rectangle represent the area for the barrier zone. The new locations should be shown with X and Y coordinates. If a new location falls on the barrier area, the location is moved to the edge of the barrier. There should also be a capacity limit for the new location. For example, a location can only cover 20 demand points.

My objective function is to minimise the distance between demand points and new locations.There should also be the possibility to limit the number of new locations.

How can I create a formula, that moves locations out of the barrier zone to the edge of the barrier zones?

Many thanks in advance :)]]>
no_email@example.com (Student75) https://forum.gamsworld.org/viewtopic.php?f=9&t=13007&p=31317#p31317 Mon, 08 Apr 2024 20:32:21 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13007&p=31317#p31317
<![CDATA[Modeling :: Re: Nonlinear Programming/ Steiner Weber Modell with barriers :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13007&p=31320#p31320
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=9&t=13007&p=31320#p31320 Tue, 09 Apr 2024 05:24:42 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13007&p=31320#p31320
<![CDATA[Modeling :: Zero Division Error :: Author Merey]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13020&p=31335#p31335 I was trying to create a model for Mozambique. But the program gets zero division error every time. I see gaps in my data set, but I don't know how I can fill them. Any ideas?

Attachments

MOZSAM.xlsx (179.57 KiB)
MOZSAM_test.gms (5.86 KiB)
]]>
no_email@example.com (Merey) https://forum.gamsworld.org/viewtopic.php?f=9&t=13020&p=31335#p31335 Wed, 17 Apr 2024 14:11:13 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13020&p=31335#p31335
<![CDATA[Modeling :: Re: Zero Division Error :: Reply by Fred]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13020&p=31339#p31339
Running your code, I get

Code: Select all

--- MOZSAM_test.gms(165) 4 Mb[FIL:"C:\Users\ffian\Documents\support\MOZSAM_test.gms",165,0]
*** Error at line 165: division by zero (0)[LST:522]
--- MOZSAM_test.gms(171) 4 Mb 1 Error[FIL:"C:\Users\ffian\Documents\support\MOZSAM_test.gms",171,0]
*** Error at line 171: division by zero (0)[LST:523]
--- MOZSAM_test.gms(899) 6 Mb 2 Errors
The corresponding lines in the echo print are

Code: Select all

165  tq(c)=SAM("stax",c)/QQ0(c);
[...]
171  tim(c) = SAM("mtax",c)/SAM("ROW",c);
If QQ0(c) is zero for certain c, you get a division by zero error. The question is, what should tq(c) be for those elements in c? You could for example just skip those c by adding a simple dollar condition

Code: Select all

tq(c)$QQ0(c)=SAM("stax",c)/QQ0(c);
You could use the same "trick" in line 171 as well. The question is, whether this gives you the desired results? You are the only person that can answer this question.

I hope this helps!

Fred]]>
no_email@example.com (Fred) https://forum.gamsworld.org/viewtopic.php?f=9&t=13020&p=31339#p31339 Thu, 18 Apr 2024 12:21:29 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13020&p=31339#p31339
<![CDATA[Modeling :: How can I random the consecutive number? :: Author celebpanama]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31342#p31342 My target is like, for example,

Code: Select all

i/j  1    2    3    4    5   6
1    0    1    0    0    0   1
2    0    1    0    0    0   1
3    0    1    1    0    0   1
4    1    1    1    0    0   1
5    1    0    1    0    1   0
6    1    0    1    0    1   0
7    1    0    0    0    1   0
8    0    0    0    0    1   0
9    0    0    0    0    0   0
10   0    0    0    0    0   0
Thank you for the recommendation.

Right now, I cannot fix 4 times each column

set i /r1*r10/, j /c1*c6/, iter /1*3/;

parameter
randval(i,j) Random values,
randvalloop(iter, i,j) Store the random values;

$set seed 123456
loop(iter,
randval(i, j) = uniformInt(0,1);
randvalloop(iter, i,j) = randval(i,j);
);

* Check the results
display randvalloop;]]>
no_email@example.com (celebpanama) https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31342#p31342 Sat, 20 Apr 2024 21:22:50 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31342#p31342
<![CDATA[Modeling :: Re: How can I random the consecutive number? :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31344#p31344

Code: Select all

set i /r1*r10/, j /c1*c6/, iter /1*3/;

parameter
rowstart, cnt,
randval(i,j) Random values,
randvalloop(iter, i,j) Store the random values;

$set seed 123456
loop(iter,
  loop(j,
    rowstart = uniformInt(1,card(i)-3);
    loop(i$(ord(i)=rowstart),
      for (cnt=0 to 3,
        randvalloop(iter, i+cnt,j) = 1;
      )
    )
  )
);

* Check the results
option randvalloop:0:1:1;
display randvalloop;
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31344#p31344 Sun, 21 Apr 2024 07:12:16 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31344#p31344
<![CDATA[Modeling :: Re: How can I random the consecutive number? :: Reply by celebpanama]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31347#p31347 I have some question. How GAMS can start 1 from r1 at some column and 1 end up with the last row (r10) in every iteration? As shown in the table below, 1 can start in row 1 (r1) both c2 and c6, and 1 end at row 10 (r10) in c5.

Code: Select all

      c1   c2   c3   c4   c5  c6
r1    0    1    0    0    0   1
r2    0    1    0    0    0   1
r3    0    1    1    0    0   1
r4    1    1    1    0    0   1
r5    1    0    1    0    0   0
r6    1    0    1    0    0   0
r7    1    0    0    0    1   0
r8    0    0    0    0    1   0
r9    0    0    0    0    1   0
r10   0    0    0    0    1   0
]]>
no_email@example.com (celebpanama) https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31347#p31347 Sun, 21 Apr 2024 18:56:55 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31347#p31347
<![CDATA[Modeling :: Re: How can I random the consecutive number? :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31349#p31349

Code: Select all

set i /r1*r10/, j /c1*c6/, iter /1*3/;

parameter
rowstart, cnt,
randval(i,j) Random values,
randvalloop(iter, i,j) Store the random values;

$set seed 123456
loop(iter,
  loop(j,
    rowstart = uniformInt(1,card(i)-3);
    loop(i$(ord(i)=rowstart),
      for (cnt=0 to 3,
        randvalloop(iter, i+cnt,j) = 1;
      )
    )
  )
* No start in any column  
  if (sum(j, randvalloop(iter,'r1',j))=0, randvalloop(iter,i,'c1') = ord(i)<5);
* No end in any column  
  if (sum(j, randvalloop(iter,'r10',j))=0, randvalloop(iter,i,'c6') = ord(i)>card(i)-4);
);

* Check the results
option randvalloop:0:1:1;
display randvalloop;
]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31349#p31349 Mon, 22 Apr 2024 13:53:04 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31349#p31349
<![CDATA[Modeling :: Re: How can I random the consecutive number? :: Reply by celebpanama]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31350#p31350 no_email@example.com (celebpanama) https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31350#p31350 Mon, 22 Apr 2024 23:17:04 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31350#p31350 <![CDATA[Modeling :: Re: How can I random the consecutive number? :: Reply by celebpanama]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31354#p31354

Code: Select all

set t /1*10/, i /1*6/, [b]iter /1*1/[/b];

parameter
rowstart, cnt, q,
randval(t,i) Random values,
randvalloop(iter, t,i) Store the random values

$set seed 123456

loop(iter,
  q = 6  
  loop(i,
    rowstart = uniformInt(1,card(t)-(q-1));
    loop(t$(ord(t)=rowstart),
      for (cnt=0 to (q-1),
        randvalloop(iter, t+cnt,i) = 1;
      )
    )
  )
* No start in any column  
  if (sum(i, randvalloop(iter,'1',i))=0, randvalloop(iter,t,'1') = ord(t)<(q+1));
* No end in any column  
  if (sum(i, randvalloop(iter,'10',i))=0, randvalloop(iter,t,'6') = ord(t)>card(t)-q);
  
);

* Check the results
option randvalloop:0:1:1;
display randvalloop;
]]>
no_email@example.com (celebpanama) https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31354#p31354 Wed, 24 Apr 2024 00:02:44 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13022&p=31354#p31354
<![CDATA[Modeling :: Error on finding max value in MIP :: Author Agustino]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13031&p=31359#p31359

Code: Select all

 Error 59 Endogenous prod smin smax require model type "dnlp"
 Error 256 equation eq2.. VAR prod smin smax
Suppose I have EM(f,t,i) as the positive variable, which is the result from previous constraints like this

Code: Select all

      i1 i2 i3 i4 i5
f1.t1  7  5  6  0  6
f1.t2  8  4  6  1  6
f1.t3  6  7  3  2  4
f2.t1  8  7  5  3  1
f2.t2  0  5  5  7  0
f2.t3  0  8  0  5  9

Code: Select all

eq2(f,i)..         last(i) =e= smax((t),EM(f,t,i));
So, I would like to fix the above coding and find the max value each column, and then collect in last(i) variable.
My target should be

last(1) = 8
last(2) = 8
last(3) = 6
last(4) = 7
last(5) = 9

Please help me to achieve this MIP model. Thank you.]]>
no_email@example.com (Agustino) https://forum.gamsworld.org/viewtopic.php?f=9&t=13031&p=31359#p31359 Fri, 26 Apr 2024 08:32:43 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13031&p=31359#p31359
<![CDATA[Modeling :: Re: Error on finding max value in MIP :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=9&t=13031&p=31360#p31360
Can you help me reformulate a non-linear constraint of a mathematical optimization model using the max operator like x(i) = max(j, y(i,j)) into linear constraints with additional binary variables?
Sure, I can help with that. To reformulate a non-linear constraint using the max operator into linear constraints with additional binary variables, you can use a common technique called "big M" method.

Here's how you can do it:

Let's say you have a non-linear constraint of the form:

x(i) = max_{j} (y(i,j))

You can reformulate it using the following linear constraints:

1. Introduce a binary variable z(i,j) for each pair of indices i and j.
2. Add a constraint ensuring that z(i,j) = 1 if and only if y(i,j) is greater than or equal to all other values of y(i,.):

y(i,j) - y(i,k) <= M (1 - z(i,j)), for all j, k where j <> k

3. Add a constraint enforcing that z(i,j) = 1 if and only if x(i) = y(i,j):

x(i) - y(i,j) <= M (1 - z(i,j)), for all j

4. Add a constraint ensuring that x(i) is no less than any y(i,j):

x(i) - y(i,j) >= 0, for all j

In these constraints, M is a sufficiently large constant, which acts as a "big M" to ensure that the binary variables z(i,j) and the auxiliary variables do not violate the logic of the original non-linear constraint.

Keep in mind that the value of M should be chosen carefully to ensure that it is larger than the maximum possible value of y(i,j) in your problem. If it is too large, it may lead to numerical instability or suboptimal solutions.

This reformulation allows you to model the non-linear constraint using only linear constraints and binary variables.
ChatGPT even gives you some GAMS code

Code: Select all

Sets
    i /i1*iN/
    j /j1*jM/;

Parameters
    M /1000/;  // Adjust this value based on the problem

Variables
    x(i)  // Your decision variable
    y(i,j)  // Your original variable
    z(i,j) binary;  // Binary variable for reformulation

Binary Variables z;

Equations
    non_linear_constraint1(i,j)
    non_linear_constraint2(i,j)
    non_linear_constraint3(i);

non_linear_constraint1(i,j)..
    y(i,j) - y(i,k) - M * (1 - z(i,j)) =L= 0
    $(j <> k);

non_linear_constraint2(i,j)..
    x(i) - y(i,j) - M * (1 - z(i,j)) =L= 0;

non_linear_constraint3(i)..
    x(i) - y(i,j) =G= 0;

Model reformulated_constraint /all/;
which is not correct GAMS code but that's what you get from AI today and you have to use your knowledge and experience to interpret ChatGPT's answer (you should do that with the theoretical one too). In any case here is the correct GAMS code:

Code: Select all

$eolcom //
$set N 10
$set M 15
Sets
    i /i1*i%N%/
    j /j1*j%M%/;

Parameters
    M /1000/;  // Adjust this value based on the problem

Variables
    x(i)  // Your decision variable
    y(i,j)  // Your original variable
    z(i,j) binary;  // Binary variable for reformulation

Binary Variables z;

alias (j,k);
Equations
    non_linear_constraint1(i,j,k)
    non_linear_constraint2(i,j)
    non_linear_constraint3(i,j);
 
non_linear_constraint1(i,j,k)$(not sameas(j,k))..
    y(i,j) - y(i,k) - M * (1 - z(i,j)) =L= 0;

non_linear_constraint2(i,j)..
    x(i) - y(i,j) - M * (1 - z(i,j)) =L= 0;

non_linear_constraint3(i,j)..
    x(i) - y(i,j) =G= 0;

Model reformulated_constraint /all/;
With GAMS you can also just solve the problem as a DNLP and choose a solver that still gives you a global optimal solution. SCIP and LINDO both accepts DNLP with smax. If you have other discrete variables, turn the model into an MINLP.

Lots of choices... Good luck.
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=9&t=13031&p=31360#p31360 Sat, 27 Apr 2024 07:03:57 +0000 https://forum.gamsworld.org/viewtopic.php?f=9&t=13031&p=31360#p31360
<![CDATA[Tools :: GDX MPS2GMS :: Author Rester]]> https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31346#p31346 no_email@example.com (Rester) https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31346#p31346 Sun, 21 Apr 2024 11:11:04 +0000 https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31346#p31346 <![CDATA[Tools :: Re: GDX MPS2GMS :: Reply by bussieck]]> https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31348#p31348

Good luck,
-Michael]]>
no_email@example.com (bussieck) https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31348#p31348 Mon, 22 Apr 2024 06:43:25 +0000 https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31348#p31348
<![CDATA[Tools :: Re: GDX MPS2GMS :: Reply by ClssicSupreme11]]> https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31352#p31352
GAMS (General Algebraic Modeling System) is often used with .gdx files, as it is a modeling language and environment that supports optimization modeling. If you have a .gdx file generated from MPS2GMS, you can use GAMS to read the data from the .gdx file and formulate and solve your optimization model.

After formulating your optimization model in GAMS, you can solve it using a solver compatible with GAMS, such as CPLEX, Gurobi, or others.

If you have specific requirements or constraints for your optimization problem, please provide more details, and I can assist you further.]]>
no_email@example.com (ClssicSupreme11) https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31352#p31352 Tue, 23 Apr 2024 07:24:57 +0000 https://forum.gamsworld.org/viewtopic.php?f=3&t=13024&p=31352#p31352
<![CDATA[API :: Python API picking up wrong GAMS version :: Author akingCCC]]> https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31332#p31332
I started by creating a new environment in Anaconda, and in a command line entered:

Code: Select all

(gams_py46) C:\Users\myusername>pip install gamsapi[all]==46.4.0
which seemed to install successfully. Then (following the instructions in https://www.gams.com/latest/docs/API_PY ... ARTED.html), I entered

Code: Select all

python -c "import gams; print(f'API OK -- Version {gams.__version__}')"
which gave me

Code: Select all

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\GAMS\38\apifiles\Python\gams\gams\__init__.py", line 32, in <module>
    from .workspace import *
  File "C:\GAMS\38\apifiles\Python\gams\gams\workspace.py", line 32, in <module>
    from .database import *
  File "C:\GAMS\38\apifiles\Python\gams\gams\database.py", line 26, in <module>
    from gdxcc import *
ModuleNotFoundError: No module named 'gdxcc'
so clearly it is trying to get something from GAMS 38 instead of GAMS 46. So I tried

Code: Select all

(gams_py46) C:\Users\myusername>python -m site
and got

Code: Select all

sys.path = [
    'C:\\Users\\myusername',
    'C:\\GAMS\\38\\apifiles\\Python\\gams',
    'C:\\Users\\myusername\\%PYTHONPATH%',
    'C:\\Anaconda3\\envs\\gams_py46\\python311.zip',
    'C:\\Anaconda3\\envs\\gams_py46\\DLLs',
    'C:\\Anaconda3\\envs\\gams_py46\\Lib',
    'C:\\Anaconda3\\envs\\gams_py46',
    'C:\\Anaconda3\\envs\\gams_py46\\Lib\\site-packages',
]
USER_BASE: 'C:\\Users\\myusername\\AppData\\Roaming\\Python' (exists)
USER_SITE: 'C:\\Users\\myusername\\AppData\\Roaming\\Python\\Python311\\site-packages' (doesn't exist)
ENABLE_USER_SITE: True
The instructions tell me to correct the GAMS path in the file sitecustomize.py, but there is no such file in the USER_BASE folder (and the USER_SITE folder doesn't exist), and any other files I can find with this name don't have a C:\GAMS\38 path in them (or any other explicit GAMS path for that matter).

I don't really want to uninstall GAMS 38 as I need to retain that for the working version of the code I want to upgrade. How do I fix this path issue? Thanks!]]>
no_email@example.com (akingCCC) https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31332#p31332 Mon, 15 Apr 2024 04:22:43 +0000 https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31332#p31332
<![CDATA[API :: Re: Python API picking up wrong GAMS version :: Reply by Clemens]]> https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31334#p31334
Something seems to put in the GAMS 38 path into your configuration. Have you checked if the PYTHONPATH environment variable is set? Run from the Anaconda command prompt:

Code: Select all

echo %PYTHONPATH%
Best,
Clemens]]>
no_email@example.com (Clemens) https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31334#p31334 Wed, 17 Apr 2024 10:41:44 +0000 https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31334#p31334
<![CDATA[API :: Re: Python API picking up wrong GAMS version :: Reply by dirkse]]> https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31336#p31336
It sounds to me like the GAMS 38 in the sitecustomize.py file is confusing your fresh conda install.

Many years ago I used the Python site package, but once I started to use miniconda I dropped it completely. I found that the two don't work well together. And at some level they are fundamental incompatible. With conda I want to create a self-contained environment that is independent of other Python stuff (conda or otherwise). But with the site package, I am sharing settings between Python versions.

-Steve]]>
no_email@example.com (dirkse) https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31336#p31336 Wed, 17 Apr 2024 15:15:46 +0000 https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31336#p31336
<![CDATA[API :: Re: Python API picking up wrong GAMS version :: Reply by akingCCC]]> https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31337#p31337
Clemens wrote: 1 week ago Hi,

Something seems to put in the GAMS 38 path into your configuration. Have you checked if the PYTHONPATH environment variable is set? Run from the Anaconda command prompt:

Code: Select all

echo %PYTHONPATH%
Best,
Clemens
Hi Clemens,

Yes, thanks, I think that's it! When I put that into the command prompt, I get

Code: Select all

C:\GAMS\38\apifiles\Python\gams;%PYTHONPATH%
and I remember changing something along those lines a year or two ago when we were setting up the original connection between GAMS and Python.

To remove it, in my Windows search I looked up "edit environment variables for your account", which opened the Environment Variables box (similar to but distinct from the System Environment Variables). In the top box User variables, I had a couple of variables that had values that included the path to GAMS 38. I deleted those and closed that box, closed and restarted Anaconda, then checked the echo %PYTHONPATH% command again, and the reference to GAMS 38 was gone. I then reinstalled the API using the commands above and checked the install, and this time it told me it was using the right version of GAMS:

Code: Select all

C:\Users\myusername>python -c "import gams; print(f'API OK -- Version {gams.__version__}')"
API OK -- Version 46.4.0
Now I just need to try using it...]]>
no_email@example.com (akingCCC) https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31337#p31337 Thu, 18 Apr 2024 03:38:45 +0000 https://forum.gamsworld.org/viewtopic.php?f=10&t=13019&p=31337#p31337
<![CDATA[Solvers :: Re: CNS Solver: Pivot Too Small :: Reply by Rodrigue]]> https://forum.gamsworld.org/viewtopic.php?f=11&t=12928&p=31282#p31282 Note that many equations do not solve either because they are not correctly written or the initialisation of variables is wrong.
Rodrigue,

Cheers]]>
no_email@example.com (Rodrigue) https://forum.gamsworld.org/viewtopic.php?f=11&t=12928&p=31282#p31282 Mon, 01 Apr 2024 09:09:01 +0000 https://forum.gamsworld.org/viewtopic.php?f=11&t=12928&p=31282#p31282
<![CDATA[Archive Google Group :: Re: GAMS Installation Error :: Reply by Clemens]]> https://forum.gamsworld.org/viewtopic.php?f=13&t=12959&p=31333#p31333
This is a Windows problem that can most likely be prevented by running the installer from a command prompt with /SILENT or /VERYSILENT. There is a note on this in the documentation: https://www.gams.com/latest/docs/UG_WIN_INSTALL.html
image.png
1. Open command prompt
2. Switch to directory containing the GAMS installer
3. Run "windows_x64_64.exe /SILENT" or "windows_x64_64.exe /VERYSILENT"

Best,
Clemens

Attachments


image.png (23.6 KiB)


(Click on the image to see it full size.)
]]>
no_email@example.com (Clemens) https://forum.gamsworld.org/viewtopic.php?f=13&t=12959&p=31333#p31333 Wed, 17 Apr 2024 07:22:21 +0000 https://forum.gamsworld.org/viewtopic.php?f=13&t=12959&p=31333#p31333
<![CDATA[Bugs :: Re: Search in Studio :: Reply by Rob Davies]]> https://forum.gamsworld.org/viewtopic.php?f=6&t=12942&p=31326#p31326 I am using search and replace. The search still finds the wrong thing, but now in all of the files, not just the lst file.
I also notice that it tells me at the start there are, say, 5 matches found, but when I replace the first one, it still indicates 5 remaining, and after replacing all, it indicates there is 1 match remaining.
Trivial, but clearly a bug. I am scared to use replace all, since it may replace the wrong thing.
Best
Rob]]>
no_email@example.com (Rob Davies) https://forum.gamsworld.org/viewtopic.php?f=6&t=12942&p=31326#p31326 Fri, 12 Apr 2024 10:36:28 +0000 https://forum.gamsworld.org/viewtopic.php?f=6&t=12942&p=31326#p31326
<![CDATA[Bugs :: Re: Search in Studio :: Reply by Lutz]]> https://forum.gamsworld.org/viewtopic.php?f=6&t=12942&p=31328#p31328
Thanks again for the report! Would it be possible, that you send an example of this to support@gams.com?
Just two days ago, I discovered, that the replace action works correctly, but the find afterwards still reports the old results (though, they were replaced correctly), if I use use "This project" as serach scope. That problem does not happenn, if I do a replace in a single file. I am not sure, if that is actually the same, you ran into.

Best regards,
Lutz]]>
no_email@example.com (Lutz) https://forum.gamsworld.org/viewtopic.php?f=6&t=12942&p=31328#p31328 Fri, 12 Apr 2024 19:05:17 +0000 https://forum.gamsworld.org/viewtopic.php?f=6&t=12942&p=31328#p31328