File: pipe_network.sci

package info (click to toggle)
scilab 2.6-4
  • links: PTS
  • area: non-free
  • in suites: woody
  • size: 54,632 kB
  • ctags: 40,267
  • sloc: ansic: 267,851; fortran: 166,549; sh: 10,005; makefile: 4,119; tcl: 1,070; cpp: 233; csh: 143; asm: 135; perl: 130; java: 39
file content (34 lines) | stat: -rw-r--r-- 671 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
function [x,pi]=pipe_network(g)
// Copyright INRIA
[lhs,rhs]=argn(0)
if rhs<>1 then error(39), end 
// g
check_graph(g)
if g('directed') <> 1 then
  error('The graph must be directed')
end
// check weights
r=g('edge_weight');
if max(r)<=0 then
  error('Weights (resistances) must be strictly positive')
end
// check demands
n=g('node_number');
ma=edge_number(g);
demand=g('node_demand');
if demand==[] then
  demand=zeros(1,n)
end
if demand*ones(n,1)<>0 then
  error('The problem is not feasible')
end

a=graph_2_mat(g);
rp=sparse([[1:ma]' [1:ma]'],1 ./ r);
ap=a(1:$-1,:);
A=ap*rp*ap';
B=demand(1:$-1)';
[h,rk]=lufact(A);
pi=lusolve(h,B); pi(n)=0;
ludel(h);
x=-rp*a'*pi;