Network representation

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 /0
10/ ;

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 ;

  1. 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?

  2. 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.

  3. 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.

Hi Sapeksh
Please read the paper by Ferris et al on computing Wardropian
Equilibria
(you can download it from this page: http://pages.cs.wisc.edu/~ferris/ferris.publications.html).
The network problem can be written as a MCP problem.
Cheers
Renger

On 17 Feb., 11:55, sapeksh vemulapati wrote:

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 /0
10/ ;

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 ;

  1. 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?

  2. 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.

  3. 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.

\

Reply-to: gamsworld@googlegroups.com

Hi Renger,

Thanks for the link. I have gone through the paper. It sure was helpful.

I have a recurring error message for my code.

x(i,t) - x(i,t-1) - sum(i$((ord(i) ne 10) and (ord(i) ne 1)),y(k$link(k,i),i,t-1)) + sum(i$((ord(i) ne 10) and (ord(i) ne 1)),y(i,l$link(i,l),t-1) =e= 0

$149 : Uncontrolled set entered as constant. The cursor stands at t, when showing this error.

I have defined both i and t as below.

t set of time intervals / 010 /
i(t) set of cells /1
10/ ;

What do I need to do?

Sapeksh.

On Thu, Feb 17, 2011 at 4:49 PM, rvannieuwkoop@gmail.com wrote:

Hi Sapeksh
Please read the paper by Ferris et al on computing Wardropian
Equilibria
(you can download it from this page: http://pages.cs.wisc.edu/~ferris/ferris.publications.html).
The network problem can be written as a MCP problem.
Cheers
Renger

On 17 Feb., 11:55, sapeksh vemulapati wrote:

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 /0
10/ ;

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 ;

  1. 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?

  2. 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.

  3. 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.



\

Sapeksh Vemulapati
Department of Civil Engineering
Final Year, B.Tech
IIT Madras


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.

Hi Sapeksh
I guess that you defined your equation over i but not over t, but I am
not sure as you only send the equation a not the equation definition
Renger

\

Hi Renger,

I redefined the equation. Its working now.

Thanks.
Sapeksh.

On Sun, Feb 20, 2011 at 5:09 PM, rvannieuwkoop@gmail.com wrote:

Hi Sapeksh
I guess that you defined your equation over i but not over t, but I am
not sure as you only send the equation a not the equation definition
Renger


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.



\

Sapeksh Vemulapati
Department of Civil Engineering
Final Year, B.Tech
IIT Madras


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.