File: chain_struct.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 (49 lines) | stat: -rw-r--r-- 1,225 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
function [fe,che,fn,chn]=chain_struct(lp,la,ls)
// Copyright INRIA
[lhs,rhs]=argn(0)
if rhs==1 then
  // g
  check_graph(lp)
  [lp,la,ls]=adj_lists(lp)
elseif rhs<>3 then error(39), 
end
// lp
s=size(lp)
if s(1)<>1 then
  error('First argument must be a row vector')
end
// la
s=size(la)
if s(1)<>1 then
  error('Second argument must be a row vector')
end
// ls
s=size(ls)
if s(1)<>1 then
  error('Third argument must be a row vector')
end
// from lp,ls,la to chained structure of edges and nodes
n=size(lp,2);lpm=lp(1:(n-1));
m=size(la,2);la1=[la 0];ls1=[ls 0];
mp1=m+1;lp1=lp;lpM=mp1*ones(lpm);
ii=find((lp(2:n)-lp(1:(n-1)))==0);
fe=la1(lpm);la2=la1;fe(ii)=zeros(ii);fe1=fe;fe1(ii)=mp1*ones(ii);
fn=ls1(lpm);ls2=ls1;fn(ii)=zeros(ii);fn1=fn;fn1(ii)=mp1*ones(ii);
la2(lp1)=zeros(lp1);ls2(lp1)=zeros(lp1);
che=zeros(1,mp1);chn=zeros(1,mp1);
lp2=min(lpm+1,lpM);
u=la2(lp2);un=ls2(lp2);
la2(lp2)=zeros(lp2);ls2(lp2)=zeros(lp2);
che(fe1)=u;chn(fe1)=un;
//loop
uumem=u;
i=2; 
while i<>m 
  lpm2=min(lpm+i,lpM);
  uu=la2(lpm2);uun=ls2(lpm2);
  la2(lpm2)=zeros(lpm2);ls2(lpm2)=zeros(lpm2);
  ii=find(uu<>0);if ii==[] then i=m;else
  che(uumem(ii))=uu(ii);chn(uumem(ii))=uun(ii);
  uumem=uu;i=i+1;end;
end
che=che(1:m);chn=chn(1:m);