I’m developing a simple problem of water transport. But I need a help, someone please could help me.

In my code the flow conservation equation at each node, is working.

(I’m using waterx.gms as reference).

But I need a code that exclude tubes which have zero flow.

I tried to multiply by the binary however it didn’t work as I expected.

(You can see the expression in “*”)

In my case

```
Set n nodes / n1 * n12 /
* anel simples a(n,n)
a(n,n) arcos / n1.n2, n2.n3, n3.n4, n4.n6, n6.n8 , n8.n12
n5.n7, n7.n9, n9.n10, n10.n11, n11.n12
n1.n5 /
si(n) saida / n12 /
cont(n) contribucao; cont(n)=yes; cont(si)=no; display cont;
alias(n,np);
Table node(n,*) dados dos nos
Q cota
* (m**3 per s) (m)
n1 10 10
n2 20 9.8
n3 30 9.6
n4 40 9.4
n5 5 9.9
n6 60 9.2
n7 15 9.7
n8 70 9.0
n9 25 9.5
n10 35 9.3
n11 45 9.1
n12 8.1;
Scalar
dmin minimum diameter of pipe / 0.15 /
dmax maximum diameter of pipe / 2.00 /
;
Variables
qp(n,n) flow on each arc - positive (m**3 per sec)
qn(n,n) flow on each arc - negative (m**3 per sec)
d(n,n) pipe diameter for each arc (m)
* dt(n,n) diam teste
s(n) vazão de saída da rede (m**3 per sec)
qma(n,n) vazão máxima no trecho (m**3 per sec)
cost total discounted costs (custo aleatorio)
pen objective penalty
;
Positive variables qp, qn(n,np);
Binary variable qb(n,np);
Equation
cons(n) equação da conservação de vazão de cada nó
qpup(n,np) positive bounds
qnup(n,np) negative bounds
qamx(n,np) vazão máxima
* diam(n,np) determinação do diametro
dpen penalty definition
fo função objetivo
;
cons(n).. sum(a(np,n), qp(a)-qn(a)) - sum(a(n,np), qp(a)-qn(a)) - s(n)$si(n) =e= node(n,"Q");
qpup(a).. qp(a) =l= qma(a)*qb(a);
qnup(a).. qn(a) =l= qma(a)*(1-qb(a));
qamx(a).. qma(a) =e= sum(n, node(n,"Q"));
*diam(a).. d(a) =e= dt(a)*qb(a);
dpen.. pen =e= sum(a, d(a));
fo.. cost =e= pen ;
* bounds
d.lo(n,np)$a(n,np) = dmin; d.up(n,np)$a(n,np) = dmax;
* initial values
d.l(n,np)$a(n,np) = 0.1;
Model network /all/;
network.domlim = 1000;
network.iterlim = 100000;
Solve network using minlp minimizing cost
```

In my case, I’m looking for the answer, that pepe d(n1 .n5)=0.0, because qn(n1.n5) is “.” zero.

```
---- VAR qn flow on each arc - negative (m**3 per sec)
LOWER LEVEL UPPER MARGINAL
n1 .n2 . 10.000 +INF .
n1 .n5 . . +INF EPS
n2 .n3 . 30.000 +INF .
n3 .n4 . 60.000 +INF .
n4 .n6 . 100.000 +INF .
n5 .n7 . 5.000 +INF .
n6 .n8 . 160.000 +INF .
n7 .n9 . 20.000 +INF .
n8 .n12 . 230.000 +INF .
n9 .n10 . 45.000 +INF .
n10.n11 . 80.000 +INF .
n11.n12 . 125.000 +INF .
---- VAR d pipe diameter for each arc (m)
LOWER LEVEL UPPER MARGINAL
n1 .n2 0.150 0.150 2.000 1.000
n1 .n5 0.150 0.0 2.000 1.000
n2 .n3 0.150 0.150 2.000 1.000
n3 .n4 0.150 0.150 2.000 1.000
n4 .n6 0.150 0.150 2.000 1.000
n5 .n7 0.150 0.150 2.000 1.000
n6 .n8 0.150 0.150 2.000 1.000
n7 .n9 0.150 0.150 2.000 1.000
n8 .n12 0.150 0.150 2.000 1.000
n9 .n10 0.150 0.150 2.000 1.000
n10.n11 0.150 0.150 2.000 1.000
n11.n12 0.150 0.150 2.000 1.000
```

And if is possible the binary:

```
---- VAR qb
LOWER LEVEL UPPER MARGINAL
n1 .n2 . 1.0 1.000 EPS
n1 .n5 . . 1.000 EPS
n2 .n3 . 1.0 1.000 EPS
n3 .n4 . 1.0 1.000 EPS
n4 .n6 . 1.0 1.000 EPS
n5 .n7 . 1.0 1.000 EPS
n6 .n8 . 1.0 1.000 EPS
n7 .n9 . 1.0 1.000 EPS
n8 .n12 . 1.0 1.000 EPS
n9 .n10 . 1.0 1.000 EPS
n10.n11 . 1.0 1.000 EPS
n11.n12 . 1.0 1.000 EPS
```