File: subgraph.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 (93 lines) | stat: -rw-r--r-- 2,782 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function [g1]=subgraph(v,ind,g)
// Copyright INRIA
[lhs,rhs]=argn(0)
if rhs<>3 then error(39), end
// check v
s=size(v)
if s(1)<>1 then
  error('First argument must be a row vector')
end
// check ind
if ((ind<>'nodes')&(ind<>'edges')) then
  error('Second argument must be ""nodes"" or ""edges""')
end
// check g
check_graph(g)
// subgraph given by edges or nodes
n=g('node_number'); 
a=g('tail');b=g('head');
ne=prod(size(g('tail')));noe=[1:ne];
if ind=='edges' then
  // case of edges
  if (min(v)<1|max(v)>ne) then
    error('A number in first argument is not an edge number')
  end
  noe(v)=[];
  adel=a(noe);bdel=b(noe);ndel=[adel bdel];
  vv=-sort(-ndel);
  w=vv(2:$)-vv(1:($-1));
  [ir,ic]=find(w==0);
  vv(ic)=[];
  n1=size(a(v),2);
  tri=[a(v) b(v)];[atri,indic]=sort(tri);nn=size(atri,2);
  atri1=atri-[0 atri(1:nn-1)];ij1=find(atri1<>0);ij2=find(atri1==0);
  uu=[1:nn];nij2=size(ij2,2);vv2=[1:nij2];uu(ij2)=uu(ij2)-vv2;
  nij1=size(ij1,2);vv1=[1:nij1];uu(ij1)=vv1;
  w=0*ones(1:nn);w(indic)=uu;
  ta=w(1:(n1));he=w((n1)+1:nn);
  g1=make_graph('foo',g('directed'),nij1,ta,he);
  dd=[1:nij1];dd(ta)=a(v);dd(he)=b(v);
else
  // case of nodes
  [atri,indic]=sort(v);nn=size(atri,2);
  if (v(1)<1|v(nn)>n) then
     error('A number in first argument is not a node number')
   end
  atri1=atri-[0 atri(1:nn-1)];ij2=find(atri1==0);
  if(ij2 <> []) then
    error('Duplicated node number in first argument')
  end
  nnew=size(v,2);
  v=atri($:-1:1);
  vglo=zeros(1,n);vglo(v)=[1:nnew];
  indic=[]
  for i=1:nnew, 
    ij1=find(a==v(i));
    indic=[indic ij1];
  end
  hhe=b(indic);
  indic1=[]
  for i=1:nnew, 
    ij1=find(hhe==v(i));
    indic1=[indic1 indic(ij1)];
  end
  dd=v;v=indic1;
  ta=a(indic1);he=b(indic1);
  ta=vglo(ta);he=vglo(he);
  g1=make_graph('foo',g('directed'),nnew,ta,he);
end
//
a=g('node_name');g1('node_name')=a(dd);
a=g('node_type');g1('node_type')=a(dd);
a=g('node_x');g1('node_x')=a(dd);
a=g('node_y');g1('node_y')=a(dd);
a=g('node_color');g1('node_color')=a(dd);
a=g('node_diam');g1('node_diam')=a(dd);
a=g('node_border');g1('node_border')=a(dd);
a=g('node_font_size');g1('node_font_size')=a(dd);
a=g('node_demand');g1('node_demand')=a(dd);
a=g('node_label');g1('node_label')=a(dd);
//
a=g('edge_name');g1('edge_name')=a(v);
a=g('edge_color');g1('edge_color')=a(v);
a=g('edge_width');g1('edge_width')=a(v);
a=g('edge_hi_width');g1('edge_hi_width')=a(v);
a=g('edge_font_size');g1('edge_font_size')=a(v);
a=g('edge_length');g1('edge_length')=a(v);
a=g('edge_cost');g1('edge_cost')=a(v);
a=g('edge_min_cap');g1('edge_min_cap')=a(v);
a=g('edge_max_cap');g1('edge_max_cap')=a(v);
a=g('edge_q_weight');g1('edge_q_weight')=a(v);
a=g('edge_q_orig');g1('edge_q_orig')=a(v);
a=g('edge_weight');g1('edge_weight')=a(v);
a=g('edge_label');g1('edge_label')=a(v);