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;
However,in this model, I have two questions on eq4.
1. When I checked the equation column, I found eq4 is calculated as 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