-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathrelabelgraph.m
117 lines (87 loc) · 3.51 KB
/
relabelgraph.m
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
function[NEW_GRAPH,MAPVERT,MAPEDGE]=relabelgraph(ED)
%returns the new graphical structure
%and the mapping between old and new graphs
NODES=ED.V;
UNSHRUNK=setdiff(NODES,ED.VERTICESINCKT);%nodes not in
SHRUNK=ED.VERTICESINCKT;
% first find the mapping of vertices
destcount=2;
for i=1:numel(NODES)
if ismember(NODES(i),SHRUNK)
MAPVERT(i,:)=[NODES(i),1];
else
MAPVERT(i,:)=[NODES(i),destcount];
destcount=destcount+1;
end
end
NEW_GRAPH.V=unique( MAPVERT(:,2));
%%now obtaining relabelled graphs
destcount=1; NEW_GRAPH.BE=[];NEW_GRAPH.E=[];
for i=1:numel(ED.E(:,1))
ARC=ED.E(i,:);
SP=ARC(1);EP=ARC(2);WT=ARC(3);%start end and weight
if ismember(SP,SHRUNK)==0 && ismember(EP,SHRUNK)==0
'No changes this just relabelling'
ISP=MAPVERT(find(MAPVERT(:,1)==SP),2);
IEP=MAPVERT(find(MAPVERT(:,1)==EP),2);
NEW_GRAPH.E(destcount,:)=[ISP,IEP,WT];
if(ismember(i,ED.BE))
NEW_GRAPH.BE=[NEW_GRAPH.BE,destcount]
end
MAPEDGE(i,:)=[i,destcount];
destcount=destcount+1;
elseif (ismember(SP,SHRUNK)==1 && ismember(EP,SHRUNK)==0)
'No changes this just relabelling'
ISP=MAPVERT(find(MAPVERT(:,1)==SP),2);
IEP=MAPVERT(find(MAPVERT(:,1)==EP),2);
NEW_GRAPH.E(destcount,:)=[ISP,IEP,WT];
if(ismember(i,ED.BE))
NEW_GRAPH.BE=[NEW_GRAPH.BE,destcount]
end
MAPEDGE(i,:)=[i,destcount];
destcount=destcount+1;
elseif (ismember(SP,SHRUNK)==0 && ismember(EP,SHRUNK)==1)
'Need changes in weight';
ISP=MAPVERT(find(MAPVERT(:,1)==SP),2);
IEP=MAPVERT(find(MAPVERT(:,1)==EP),2);
[MINWTINCKTWT,INCIDENTCKTWT]=finde0e1(ED,EP);
NEWWT=WT+MINWTINCKTWT-INCIDENTCKTWT;
NEW_GRAPH.E(destcount,:)=[ISP,IEP,NEWWT];
if(ismember(i,ED.BE))
NEW_GRAPH.BE=[NEW_GRAPH.BE,destcount]
end
MAPEDGE(i,:)=[i,destcount];
destcount=destcount+1;
else %ismember(SP,SHRUNK)==1 && ismember(EP,SHRUNK)==1
MAPEDGE(i,:)=[i,-1];
'Bucket Edges inside CKT Dropped, totally inside circuit' ;
end
end
% see where BV maps to
count=1; NEW_GRAPH.BV=[];
for i=1:numel(ED.BV)
if ismember(ED.BV(i),SHRUNK)==0
IND=find(MAPVERT(:,1)==ED.BV(i));
NEW_GRAPH.BV(count)=MAPVERT(IND,2);
count=count+1;
end
end
if count>1
NEW_GRAPH.BV=unique(NEW_GRAPH.BV);
end
function[min_wt_in_ckt,incident_wt_in_ckt]=finde0e1(ED,EP)
%first thing is to find edges which are in circuit
INBE= ED.E(ED.BE,:); % in BE
count=1;
for i=1:numel(ED.BE)
if sum(ismember(INBE(i,1:2),ED.VERTICESINCKT))==2
ISCKTEDGE(count,:)=INBE(i,:);
count=count+1;
end
end
% now find the minimum
min_wt_in_ckt=min(ISCKTEDGE(:,3));
%now find the one incident on EP
INDEXofINCIDENT=find(ISCKTEDGE(:,2)==EP);
incident_wt_in_ckt=ISCKTEDGE(INDEXofINCIDENT,3);
return