Hello,
I am very new to the GAMS software and am finding it difficult to code certain things.
I need to code a cell transmission model in GAMS IDE. I have written the following code so far.
sets
i set of cells /110/
t set of time intervals /010/ ;
alias(i,j) ;
sets link(i,j) set of cell connectors connecting cells
/ 1 . 2
2 . 3
2 . 5
3 . 4
3 . 6
4 . 9
5 . 7
6 . 7
7 . 8
8 . 9
9 . 10 / ;
Variables
x(i,t) number of vehicles in cell i at time interval t
z total system travel time ;
Positive variable x ;
variables
y(i,j,t) flow in the cell connectors ;
Parameters
N(i) maximum number of vehicles in cell i / 1 inf, 2 20, 3 10, 4 10, 5 10, 6 10, 7 10, 8 10, 9 20, 10 inf /
Q(i,t) maximum number of vehicles that can flow into or out of cell i
del(i) ratio v by w for cell i at time interval t / 1 1, 2 1, 3 1, 4 1, 5 1, 6 1, 7 1, 8 1, 9 1, 10 1 /
d(t) demand(inflow) for cell 1 at time interval t / 0 8, 1 16, 2 8, 3 0, 4 0, 5 0, 6 0, 7 0, 8 0, 9 0, 10 0 / ;
Table Q(i,t)
0 1 2 3 4 5 6 7 8 9 10
1 inf inf inf inf inf inf inf inf inf inf inf
2 12 12 12 12 12 12 12 12 12 12 12
3 6 6 6 6 6 6 6 6 6 6 6
4 6 6 0 0 3 3 6 6 6 6 6
5 6 6 6 6 6 6 6 6 6 6 6
6 6 6 6 6 6 6 6 6 6 6 6
7 6 6 6 6 6 6 6 6 6 6 6
8 6 6 6 6 6 6 6 6 6 6 6
9 6 6 6 6 6 6 6 6 6 6 6
10 12 12 12 12 12 12 12 12 12 12 12 ;
Equations
optimum minimize total travel time
con13
con14a
con14b
con14c
con14d
con15a
con15b
con16a
con16b
con16c
con16d
con16a2
con16b2
con16c2
con16d2
con17a different constraints to optimising the network travel time
con17b
con17c
con17d
con18a
con18b
con18c
con18d
con18e
con18f
con18g
con18h
con19a
con19b
con19c
con19d
con20a
con20b
con21
con22
con23 ;
optimum… z =e= sum(t,sum(i$(i ne ‘10’), 10*x(i,t))) ;
con13… x(i,t) - x(i,t-1) - sum(i$(i ne ‘10’ and i ne ‘1’),y(k$(link(k,i),i,t-1)) + sum(i$(i ne ‘10’ and i ne ‘1’),y(i,l$(link(i,l),t-1) =e= 0 ;
con14a… y(‘1’,‘2’,t) - x(‘1’,t) =l= 0 ;
con14b… y(‘1’,‘2’,t) =l= Q(‘2’,t) ;
con14c… y(‘1’,‘2’,t) =l= Q(‘1’,t) ;
con14d… y(‘1’,‘2’,t) + del(‘2’)*x(‘2’,t) =l= del(‘2’)*N(‘2’) ;
con15a… y(‘9’,‘10’,t) - x(‘9’,t) =l= 0 ;
con15b… y(‘9’,‘10’,t) =l= Q(‘9’,t) ;
con16a… y(‘2’,‘3’,t) =l= Q(‘3’,t) ; ;
con16b… y(‘2’,‘3’,t) + del(‘3’)*x(‘3’,t) =l= del(‘3’)*N(‘3’) ;
con16c… y(‘2’,‘5’,t) =l= Q(‘5’,t) ;
con16d… y(‘2’,‘5’,t) + del(‘5’)*x(‘5’,t) =l= del(‘5’)*N(‘5’) ;
con16a2… y(‘3’,‘4’,t) =l= Q(‘4’,t) ;
con16b2… y(‘3’,‘4’,t) + del(‘4’)*x(‘4’,t) =l= del(‘4’)*N(‘4’) ;
con16c2… y(‘3’,‘6’,t) =l= Q(‘6’,t) ;
con16d2… y(‘3’,‘6’,t) + del(‘6’)*x(‘6’,t) =l= del(‘6’)*N(‘6’) ;
con17a… y(‘2’,‘3’,t) + y(‘2’,‘5’,t) - x(‘2’,t) =l= 0 ;
con17b… y(‘2’,‘3’,t) + y(‘2’,‘5’,t) =l= Q(‘2’,t) ;
con17c… y(‘3’,‘4’,t) + y(‘3’,‘6’,t) - x(‘3’,t) =l= 0 ;
con17d… y(‘3’,‘4’,t) + y(‘3’,‘6’,t) =l= Q(‘3’,t) ;
con18a… y(‘4’,‘9’,t) - x(‘4’,t) =l= 0 ;
con18b… y(‘8’,‘9’,t) - x(‘8’,t) =l= 0 ;
con18c… y(‘5’,‘7’,t) - x(‘5’,t) =l= 0 ;
con18d… y(‘6’,‘7’,t) - x(‘6’,t) =l= 0 ;
con18e… y(‘4’,‘9’,t) =l= Q(‘4’,t) ;
con18f… y(‘8’,‘9’,t) =l= Q(‘8’,t) ;
con18g… y(‘5’,‘7’,t) =l= Q(‘5’,t) ;
con18h… y(‘6’,‘7’,t) =l= Q(‘6’,t) ;
con19a… y(‘4’,‘9’,t) + y(‘8’,‘9’,t) =l= Q(‘9’,t) ;
con19b… y(‘5’,‘7’,t) + y(‘6’,‘7’,t) =l= Q(‘7’,t) ;
con19c… y(‘4’,‘9’,t) + y(‘8’,‘9’,t) + del(‘9’)*x(‘9’,t) =l= del(‘9’)*N(‘9’) ;
con19d… y(‘5’,‘7’,t) + y(‘6’,‘7’,t) + del(‘7’)*x(‘7’,t) =l= del(‘7’)*N(‘7’) ;
con20a… x(‘1’,t) - x(‘1’,t-1) + y(‘1’,‘2’,t-1) =e= d(t-1) ;
con20b… x(i,‘0’) =e= 0 ;
con21… y(i,j,‘0’) =e= 0 ;
con22… x(i,t) =g= 0 ;
con23… y(i,j,t) =g= 0 ;
con24… y(i,j$link(i,j),t)
Model sapeksh /all/ ;
Solve sapeksh using lp minimizing z ;
display x.l, x.m ;
-
The flow defined as above is allowing flow between all nodes. The flow should only be allowed for those where links exist. How do i do this?
-
I have mostly “hard coded” all the constraints for finding the optimum. Is there a better way to do this?
I have learned about the $ operator but haven’t figured out how to use it here. -
How do I define predecessor cells and successor cells which can greatly reduce the code length?
Any kind of help is welcome, be it partial or complete.
Thank you,
Sapeksh.
–
To post to this group, send email to gamsworld@googlegroups.com.
To unsubscribe from this group, send email to gamsworld+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/gamsworld?hl=en.