File: pipe_network.sci

package info (click to toggle)
scilab 2.4-1
  • links: PTS
  • area: non-free
  • in suites: potato, slink
  • size: 55,196 kB
  • ctags: 38,019
  • sloc: ansic: 231,970; fortran: 148,976; tcl: 7,099; makefile: 4,585; sh: 2,978; csh: 154; cpp: 101; asm: 39; sed: 5
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;