Sum of the dynamic set

Problems with syntax of GAMS
Post Reply
sullian
User
User
Posts: 4
Joined: 4 years ago

Sum of the dynamic set

Post by sullian »

Hello, I am modeling a radial network. I simply my problem as:

Code: Select all

 set
n  /n1*n4/
cl(n,n) candidate line /n1.n2,n2.n3,n3.n4,n1.n3,n2.n4/
j source /j1/
jnd(j,n) location of source /j1.n3/  ;
Alias (n,nf,nt);
variables
fl(n,n)
z  ;
binary variable
xl(n,n);
parameter
demand /n1 1,n2 1,n3 1,n4 1/
s(j) /j1 4 /               ;
scalar
max   /20/
equation
object
eq1(n)
eq2(n,n)
eq3(n,n)
eq4(n);
object..           z=e= sum(cl(nf,nt),xl(nf,nt))*5;
eq1(n)..           sum(cl(nf,n),fl(nf,n))+sum(cl(n,nt),fl(n,nt))=e=demand(n)-sum(jnd(j,n),s(j));
eq2(cl(nf,nt))..   fl(nf,nt)=l=max*xl(nf,nt);
eq3(cl(nf,nt))..   fl(nf,nt)=g=-max*xl(nf,nt);
eq4(nt)$(not ord(nt)=3)..          sum(nf,xl(nf,nt))=e=1;
model network /all/;
solve network using mip min z; 
As you see, eq1 denotes flow node balance. eq2 and eq3 are flow capacity limits. eq4 is the radiality constraints.

However,in this model, I have two questions on eq4.
1. When I checked the equation column, I found eq4 is calculated as
image.png
image.png (11.46 KiB) Viewed 2154 times
How could I use dynamic set to only make a summation of the from point(nf) of the candidate lines, not all the mappings of (nf,nt).
2. Because n3 is the location of the source, as subset jnd shows, so I added a condition $(not ord(nt)=3) to eq4 domain. But sometimes I need to change the source location index, is there any way to change this condition description and make it related to the index of subset jnd(j,nd) ?
THX FOR YOU HELP!

Sue
User avatar
Renger
Posts: 639
Joined: 7 years ago

Re: Sum of the dynamic set

Post by Renger »

Hi Sue
Could you write out examples of the equation you want in point 1. It is not clear to me.
Point 2: You could use a set defining which elements you don't want (e.g. set src(nt) /n3/; and write the equation q4(nt)$(not src(nt)).

Cheers
Renger
____________________________________
Enjoy modeling even more: Read my blog on modeling at The lazy economist
sullian
User
User
Posts: 4
Joined: 4 years ago

Re: Sum of the dynamic set

Post by sullian »

Hi Renger,
Thx for your reply. I found the way to solve Q1. I modified eq4 like

Code: Select all

eq4(nt)$(not ord(nt)=3)..       sum(cl(nf,nt),xl(nf,nt))=e=1;  
and the equation list is shown as expected:
image.png
However, I have another problem in terms of undirected graph modelling. As you see in my last post, I define ' cl(n,n) candidate line /n1.n2,n2.n3,n3.n4,n1.n3,n2.n4/', but xl(n,n) is a binary variable shows whether to add a line or not between nodes, which is undirected.
If I code like
'eq4(nt)$(not ord(nt)=3).. sum(cl(nf,nt),xl(nf,nt))=e=1;'
with 'cl(n,n) /n1.n2,n2.n3,n3.n4,n1.n3,n2.n4/', the eq4 list is definitely empty and wrong.
In this situation, do I need to add the reverse direction like n2.n1,n3.n2? Or any other good way/references/codes to model the undirected graph?
Here, I posted the modified code:

Code: Select all

set
n  /n1*n4/
cl(n,n) candidate line /n1.n2,n2.n3,n3.n4,n1.n3,n2.n4,n1.n4,n4.n3,n4.n1/
j source /j1/
jnd(j,n) location of source /j1.n3/  ;
Alias (n,nf,nt);
variables
fl(n,n)
z  ;
binary variable
xl(nf,nt);
parameter
demand /n1 1,n2 1,n3 1,n4 1/
s(j) /j1 40 /               ;
scalar
max   /20/
equation
object
eq1(n)
eq2(n,n)
eq3(n,n)
eq4(n)
eq5(n,n);
object..           z=e= sum(cl(nf,nt),xl(nf,nt))*5;
eq1(n)..           sum(cl(nf,n),fl(nf,n))+sum(cl(n,nt),fl(n,nt))=e=demand(n)-sum(jnd(j,n),s(j));
eq2(cl(nf,nt))..   fl(nf,nt)=l=max*xl(nf,nt);
eq3(cl(nf,nt))..   fl(nf,nt)=g=-max*xl(nf,nt);
eq4(nt)$(not ord(nt)=3)..       sum(cl(nf,nt),xl(nf,nt))=e=1;
eq5(cl(nf,nt))..    xl(nf,nt)=e= xl(nt,nf);
model network /all/;
solve network using mip min z;
Post Reply