GAMS error in equation when using conditional sum

Problems with modeling
Post Reply
T_k
User
User
Posts: 8
Joined: 1 year ago

GAMS error in equation when using conditional sum

Post by T_k »

online truck routing.gms
(3.14 KiB) Downloaded 74 times
I am new to GAMS. I apologize in advance if I am making silly mistakes. I am getting the following errors when I attempt to solve the model on the equation Xlt_eq-
Error 8
')' expected
*** Error 10 in
',' expected
*** Error 119
Number (primary) expected
*** Error 8
')' expected
*** Error 408
Too many ),] or }

The code is below

Set

j 'OD pair' /OD1, OD2/
w 'VOT classes' /VOT1, VOT2/
l 'road segment' /12,24,13,34,23/
all_routes 'all routes' /124,1234,134,24,234/
route_OD1(all_routes) 'route of OD1' /124,1234,134/
route_OD2(all_routes) 'route of OD2' /24,234/
d(j,all_routes) /OD1.(124,1234,134),OD2.(24,234)/
q(j,all_routes,w) /(OD1.(124,1234,134)).(VOT1,VOT2),(OD2.(24,234)).(VOT1,VOT2)/;
alias (l,ll),(all_routes,a_r)
display d,q

set Table e(j,w) '# of trucks of class w with OD pair j'
VOT1 VOT2
OD1 20 20
OD2 20 20;
*alias (e,ee);
set Table f(l,all_routes) 'links in routes'
124 1234 134 24 234
12 YES YES
24 YES YES
13 YES YES
34 YES YES YES
23 YES YES;

set Table M(w,all_routes) 'VOT classes in routes'
124 1234 134 24 234
VOT1 YES YES YES YES YES
VOT2 YES YES YES YES YES;


Set g(l,all_routes ,w);
g(l,all_routes ,w) = f(l,all_routes)*M(w,all_routes);
display g;
Alias (j,jj),(w,ww)

Variables

obj, Fjwr, Cl,alpha_equal_1, Xlt, cost;

Positive Variable
*alpha
alpha(j, w, all_routes)
zeta(j,w);

Scalar
epsilon_a /2/
epsilon_b /3/
pass_vehicles /5/
t_f /3/
Capacity /3/;


Equations
Cl_eq, Fjwr_eq, alpha_equal_1_eq, Xlt_eq,cost_eq,F_zeta_eq;

alpha_equal_1_eq(j,w).. 1=e=sum(all_routes$d(j,all_routes),alpha(j,w,all_routes));

XlT_eq(l).. Xlt(l) =e= sum((j,w,all_routes$d(j,all_routes)),e(j,w)*alpha(j,w,all_routes$d(j,all_routes)));

Cl_eq(l).. Cl(l) =e= t_f*[1+epsilon_a*((pass_vehicles+3*Xlt(l))/Capacity)*epsilon_b];

Fjwr_eq(j,w,all_routes).. Fjwr(j,w,all_routes) =e= sum(l,Cl(l));

F_zeta_eq(j,w,all_routes).. 0 =l= zeta(j,w) - Fjwr(j,w,all_routes);

Model OTR /F_zeta_eq.alpha, alpha_equal_1_eq, XlT_eq/;

option limrow = 120;
solve OTR using mcp;


What's wrong with my approach?
Last edited by T_k 1 year ago, edited 1 time in total.
User avatar
bussieck
Moderator
Moderator
Posts: 1038
Joined: 7 years ago

Re: GAMS error in equation when using conditional sum

Post by bussieck »

Even if you are new to GAMS you should read and follow the forum rules. Pasting model code that is sensitive to alignment (table statements) is a bad idea. Either attached your model or use the inline code tags. The compiler error message was also pretty clear about misplaced parenthesis. The syntax for sum over multiple sets with $ condition is sum((i,j,k)$(cond), ...) not sum((i,j,k$(cond)), xxx.). Also the second "$d(j,all_routes)" is unnecessary. So the correct equation XlT_eq reads as follows: "XlT_eq(l).. Xlt(l) =e= sum((j,w,all_routes)$d(j,all_routes),e(j,w)*alpha(j,w,all_routes));". With that change the model compiles. Your model type is MCP and GAMS can't match variables and constraints (you only provide a partial matching). The model you generate is not square (29 rows and 39 columns), but MCP needs a square system. If you know MCP then you know what to do. If you don't, start learning first about MCP.

-Michael
T_k
User
User
Posts: 8
Joined: 1 year ago

Re: GAMS error in equation when using conditional sum

Post by T_k »

Thank you. I am sorry. Ill make sure to follow the forum rules for my future posts.
Post Reply