This repository was archived by the owner on Jun 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathclimb.m
More file actions
56 lines (49 loc) · 1.26 KB
/
climb.m
File metadata and controls
56 lines (49 loc) · 1.26 KB
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
function [result,flow] = climb( F , node , req )
result=[];
flow=[];
for i=1:length(F(:,1))
if F(i,node)>0&&req>0
if F(i,node)<=req
req=req-F(i,node);
[T,fw]=climb(F,i,F(i,node));
r2=[ T ones(length(T(:,1)),1).*node];
[m1,n1]=size(result);
[m2,n2]=size(r2);
if n1<n2
o=zeros(m1,n2-n1);
result=[result o;r2];
flow=[flow;fw];
else
o=zeros(m2,n1-n2);
result=[result;r2 o];
flow=[flow;fw];
end
F(i,node)=0;
else
[T fw]=climb(F,i,req);
r2=[ T ones(length(T(:,1)),1).*node];
[m1,n1]=size(result);
[m2,n2]=size(r2);
if n1<n2
o=zeros(m1,n2-n1);
result=[result o;r2];
flow=[flow;fw];
else
o=zeros(m2,n1-n2);
result=[result;r2 o];
flow=[flow;fw];
end
F(i,node)=F(i,node)-req;
req=0;
end
end
end
if req>0
if node~=1
result=[1 node];
else
result=1;
end
flow=req;
end
end