yousuf
yousuf

Reputation: 1

need help writing index in equation in GAMS for a transportation network problem

I have the following code , but due to indexing error in equation 3 and 4 cant run the problem , need help writing them in a correct way

/ minimize travel time in multiple origin destination pair sets a "links" /l1l19/ b "path sets" /p1*p25/ r "origin node" /1,4/ s "destination node" /2,3/;

table demand(r,s,*) "demand between rs pairs"
    d
1.2 11000
1.3 24000
4.2 13000
4.3 6000
;

Table link_data(a,*) "free travel time ta0"
        length  ta0     Capacity
l1      7       7       800
l2      9       9       400
.
.
l19     11      11      600
;

set paths(r,s,b) "paths in origin r to destiantion s"
/1.2.p1*p8, 1.3.p9*p14, 4.2.p15*p19, 4.3.p20*p25 /
;


table del(r,s,b,a) "parameter to show path b passes through link a from r to s"

        l1  l2  l3  l4  l5  l6  l7  l8  l9  l10 l11 l12 l13 l14 l15 l16 l17 l18 l19
1.2.p1  0   1   0   0   0   0   0   0   0   0   1   0   0   0   0   0   0   1   0
1.2.p2  1   0   0   0   1   0   1   0   1   0   1   0   0   0   0   0   0   0   0
.
.
1.3.p14 0   1   0   0   0   0   0   1   0   0   0   0   0   1   0   1   1   0   0
4.2.p15 0   0   0   1   0   0   0   0   0   0   0   1   0   1   1   0   0   0   0
.
.
4.3.p25 0   0   1   0   0   1   0   0   0   0   0   1   0   1   0   1   0   0   0

;

variables of "objective function"
        t(a) "travel time in link a"
        x(a) "vehicle in link a"
        f(r,s,b) "vehicle flow in origin r to destination s on path b";

f.lo(r,s,b)=0;
x.up(a)= link_data(a,'capacity')*10;
x.lo(a)=0;

equations eq1,eq2,eq3,eq4;

eq1..of=e=sum(a,t(a)); 
eq2(a)..t(a)=e=link_data(a,'ta0')*(1+0.15*(x(a)/link_data(a,'Capacity'))**4);

eq3(a)..x(a)=e=sum((r,s),sum((r,s,b)$paths(r,s,b),f(r,s,b)*del(r,s,b,a)));

eq4(r,s)..sum((r,s),f(r,s,b))=e=demand(r,s,'d');

Model mc / all /;

solve mc minimizing of using NLP ;

display f.l ;

How do I write the equation 3 and 4 with correct syntax minimizing the travel time

Upvotes: 0

Views: 25

Answers (1)

Mitch Phillipson
Mitch Phillipson

Reputation: 293

I took a look at your listing file and found the following:

  52  eq3(a)..    x(a)=e=sum((r,s),sum((r,s,b)$paths(r,s,b),f(r,s,b)*del(r,s,b,a)));
****                                     $125,125
**** 125  Set is under control already
  53   
  54  eq4(r,s)..  sum((r,s),f(r,s,b))=e=demand(r,s,'d');
****                    $125,125   $149
**** 125  Set is under control already
**** 149  Uncontrolled set entered as constant

In line 52 you're using r and s twice in the summation. Basically what you're writing is

\sum_{r\in R,s\in S} \sum_{r\in R, s\in S, b\in B|path(r,s,b)}

One way around this is to set up aliases

alias (r,rr), (s,ss);

and then using the alias to disambiguate the summations.

Upvotes: 0

Related Questions