-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdepgraph.p
193 lines (160 loc) · 4.7 KB
/
depgraph.p
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
{ **** depgraph.i **** }
{ This module implments the operations to be performed on the dependence
graph of the current basis.
All global variables used in this module are defined in either
parityGlob.i or userGlob.i, except for BasisGraph.
The following operations are provided for manipulating the
dependence graph:
1. IsInMstar( e: ELEMENT): boolean
Returns true if e is in the current basis, false otherwise.
2. Mate(e: ELEMENT): ELEMENT
Returns the parity mate of e.
3. ForAdjacent( e: ELEMENT, procedure P( f: ELEMENT))
Performs P for every element f adjacent to e in the dependance
graph.
4. GetInitialBasis
Constructs an initial basis of all singletons from the input graph.
5. ForElement( procedure P(e: ELEMENT))
executes P for every element in the matroid.
6. Swap(e: ELEMENT)
Swap modifies the global indicator array InMS to indicate a
change in the basis.
The element e (and its mate if e is not a singleton ), are put into
or removed from the basis, according to its current status.
7. Update
Update calls the routines which update the dependence graph
and the basis Mstar.
Update is called after all calls to Swap have been made.
Routines which deal with transforms and singletons are in the modules
transforms.i and singletons.i, resp.
}
var
BasisGraph: GRAPH; { graph containing the edges of the current basis }
function IsInMstar(e: ELEMENT): boolean;
begin
IsInMstar:= InMS[e];
end; (* IsInMstar *)
{ Include subsidiary modules }
#include "singletons.i"
#include "transforms.i"
function Mate(e: ELEMENT): ELEMENT;
{ this function returns the mate of the element e }
begin
if IsSingleton(e) or IsTransform(e) then
Mate:= NULLELEMENT
else
if (e mod 2) = 0 then
Mate:= e-1
else
Mate:= e+1;
end;
procedure ForAdjacent( e: ELEMENT; procedure P(o:ELEMENT));
var
f: ELEMENT; { name of an element adjacent to e }
i: integer; { loop indexing }
begin
if IsInMstar(e) then
for f:= 1 to NumEl + NumSingle + NumXform do
if IsAdjacent(e,f) then
P(f)
else
else begin
for i:= 1 to BasisSize do
if IsAdjacent(e,Mstar[i]) then
P(Mstar[i]);
{ look at transforms in Mstar }
for i:= 1 to NumBasicXform do
if IsAdjacent(e,BasicXform[i]) then
P(BasicXform[i]);
end; (* if *)
end; (* For Adjacent *)
procedure GetInitialBasis;
{ this routine constructs an initial basis of singletons from the
edges in a depth first search tree of the input graph. }
var
j: integer; { counter }
begin (* get_initial_basis *)
{ initialize }
for j:= 1 to NumEl do
InMS[j]:= false;
BasisSize:= 0;
NumXform:= 0;
{ end initialize }
InitSpForest( InputGraph, BasisTree, makeSingleton);
end; (* get_initial_basis *)
procedure ForElement( procedure P( e: ELEMENT));
var
i: ELEMENT;
begin
for i:= 1 to NumEl do
P(i);
end;
procedure updateDepGraph;
procedure NullProc(u,v:VERTEX);
begin
end;
begin
InitSpForest(BasisGraph, BasisTree, NullProc);
end;
procedure PrintEl(j: ELEMENT);
begin
write(j);
end;
procedure PrintDepGraph;
var
i: ELEMENT;
begin
writeln(' Adjacency lists for dependency graph');
for i:= 1 to NumEl + NumSingle + NumXform do
if InMS[i] then begin
writeln(' Adjacency list for element ',i);
ForAdjacent(i,PrintEl);
writeln;
end;
end; (* Print Dep Graph *)
procedure Swap(e: ELEMENT);
begin
InMS[e]:= not InMS[e];
if not IsSingleton(e) then { e has a mate }
begin
SwapTrace(e,InMS[e]); SwapTrace(Mate(e), InMS[e]);
InMS[Mate(e)]:= InMS[e];
end
else
SwapTrace(e,InMS[e]);
end; (* SWAP *)
procedure Update;
procedure chMstar;
{ This procedure updates the array Mstar to reflect the changes in
the basis }
var
i, pos: integer;
begin
{ set pos to the first non-singleton position in Mstar }
pos:= NumSingle + 1;
for i:= 1 to NumEl do
if InMS[i] then begin
Mstar[pos]:= i;
pos:= pos + 1;
end; (* if *)
end; (* Ch Mstar *)
procedure newBasisGraph;
{ this procedure sets BasisGraph to be the graph of basic edges }
var
i: integer;
begin
EraseGr(BasisGraph);
for i:= 1 to BasisSize do
begin newBasisGraphTrace( Mstar[i],
Parity[Mstar[i]]^.end1, Parity[Mstar[i]]^.end2);
AddEdgeGr( BasisGraph, Parity[Mstar[i]]^.end1,
Parity[Mstar[i]]^.end2);
end; (* for *)
end; (* new basis graph *)
begin (* Update *)
compactSingles;
chMstar;
newBasisGraph;
updateDepGraph;
NumXform:= 0;
end; (* Update *)