|
@@ -9,6 +9,7 @@ func edgeDebugString(edge *Edge) string {
|
9
|
9
|
debug := ""
|
10
|
10
|
debug += fmt.Sprintf("\t\tSrc: %p\n", edge.Src)
|
11
|
11
|
debug += fmt.Sprintf("\t\tDest: %p\n", edge.Dest)
|
|
12
|
+ debug += fmt.Sprintf("\t\tWeight: %d\n", edge.Weight)
|
12
|
13
|
debug += fmt.Sprintf("\t\tResidual: %t\n", edge.Residual)
|
13
|
14
|
debug += fmt.Sprintf("\t\tInline: %t\n", edge.Inline)
|
14
|
15
|
return debug
|
|
@@ -57,19 +58,13 @@ func expectedNodesDebugString(Expected []ExpectedNode) string {
|
57
|
58
|
return debug
|
58
|
59
|
}
|
59
|
60
|
|
60
|
|
-// Checks if two edges are equal
|
61
|
|
-func edgesEqual(this, that *Edge) bool {
|
62
|
|
- return this.Src == that.Src && this.Dest == that.Dest &&
|
63
|
|
- this.Residual == that.Residual && this.Inline == that.Inline
|
64
|
|
-}
|
65
|
|
-
|
66
|
61
|
// Checks if all the edges in this equal all the edges in that.
|
67
|
62
|
func edgeMapsEqual(this, that EdgeMap) bool {
|
68
|
63
|
if len(this) != len(that) {
|
69
|
64
|
return false
|
70
|
65
|
}
|
71
|
66
|
for node, thisEdge := range this {
|
72
|
|
- if !edgesEqual(thisEdge, that[node]) {
|
|
67
|
+ if *thisEdge != *that[node] {
|
73
|
68
|
return false
|
74
|
69
|
}
|
75
|
70
|
}
|
|
@@ -122,6 +117,10 @@ func makeEdgeInline(edgeMap EdgeMap, node *Node) {
|
122
|
117
|
edgeMap[node].Inline = true
|
123
|
118
|
}
|
124
|
119
|
|
|
120
|
+func setEdgeWeight(edgeMap EdgeMap, node *Node, weight int64) {
|
|
121
|
+ edgeMap[node].Weight = weight
|
|
122
|
+}
|
|
123
|
+
|
125
|
124
|
// Creates a directed edges from the parent to each of the children
|
126
|
125
|
func createEdges(parent *Node, children ...*Node) {
|
127
|
126
|
for _, child := range children {
|
|
@@ -173,15 +172,15 @@ func createExpectedEdges(parent ExpectedNode, children ...ExpectedNode) {
|
173
|
172
|
|
174
|
173
|
// The first test case looks like:
|
175
|
174
|
// 0
|
176
|
|
-// |
|
|
175
|
+// |(5)
|
177
|
176
|
// 1
|
178
|
|
-// / \
|
179
|
|
-// 2 3
|
|
177
|
+// (3)/ \(4)
|
|
178
|
+// 2 3
|
180
|
179
|
//
|
181
|
180
|
// After Keeping 0, 2, 3. We should see:
|
182
|
181
|
// 0
|
183
|
|
-// / \
|
184
|
|
-// 2 3
|
|
182
|
+// (3)/ \(4)
|
|
183
|
+// 2 3
|
185
|
184
|
func createTestCase1() TrimTreeTestCase {
|
186
|
185
|
// Create Initial graph
|
187
|
186
|
graph := &Graph{make(Nodes, 4)}
|
|
@@ -193,6 +192,9 @@ func createTestCase1() TrimTreeTestCase {
|
193
|
192
|
createEdges(nodes[1], nodes[2], nodes[3])
|
194
|
193
|
makeEdgeInline(nodes[0].Out, nodes[1])
|
195
|
194
|
makeEdgeInline(nodes[1].Out, nodes[2])
|
|
195
|
+ setEdgeWeight(nodes[0].Out, nodes[1], 5)
|
|
196
|
+ setEdgeWeight(nodes[1].Out, nodes[2], 3)
|
|
197
|
+ setEdgeWeight(nodes[1].Out, nodes[3], 4)
|
196
|
198
|
|
197
|
199
|
// Create Expected graph
|
198
|
200
|
Expected, Keep := createExpectedNodes(nodes[0], nodes[2], nodes[3])
|
|
@@ -200,6 +202,8 @@ func createTestCase1() TrimTreeTestCase {
|
200
|
202
|
makeEdgeInline(Expected[0].Out, Expected[1].Node)
|
201
|
203
|
makeExpectedEdgeResidual(Expected[0], Expected[1])
|
202
|
204
|
makeExpectedEdgeResidual(Expected[0], Expected[2])
|
|
205
|
+ setEdgeWeight(Expected[0].Out, Expected[1].Node, 3)
|
|
206
|
+ setEdgeWeight(Expected[0].Out, Expected[2].Node, 4)
|
203
|
207
|
return TrimTreeTestCase{
|
204
|
208
|
Initial: graph,
|
205
|
209
|
Expected: Expected,
|
|
@@ -209,18 +213,18 @@ func createTestCase1() TrimTreeTestCase {
|
209
|
213
|
|
210
|
214
|
// This test case looks like:
|
211
|
215
|
// 3
|
212
|
|
-// |
|
|
216
|
+// | (12)
|
213
|
217
|
// 1
|
214
|
|
-// |
|
|
218
|
+// | (8)
|
215
|
219
|
// 2
|
216
|
|
-// |
|
|
220
|
+// | (15)
|
217
|
221
|
// 0
|
218
|
|
-// |
|
|
222
|
+// | (10)
|
219
|
223
|
// 4
|
220
|
224
|
//
|
221
|
225
|
// After Keeping 3 and 4. We should see:
|
222
|
226
|
// 3
|
223
|
|
-// |
|
|
227
|
+// | (10)
|
224
|
228
|
// 4
|
225
|
229
|
func createTestCase2() TrimTreeTestCase {
|
226
|
230
|
// Create Initial graph
|
|
@@ -233,11 +237,16 @@ func createTestCase2() TrimTreeTestCase {
|
233
|
237
|
createEdges(nodes[1], nodes[2])
|
234
|
238
|
createEdges(nodes[2], nodes[0])
|
235
|
239
|
createEdges(nodes[0], nodes[4])
|
|
240
|
+ setEdgeWeight(nodes[3].Out, nodes[1], 12)
|
|
241
|
+ setEdgeWeight(nodes[1].Out, nodes[2], 8)
|
|
242
|
+ setEdgeWeight(nodes[2].Out, nodes[0], 15)
|
|
243
|
+ setEdgeWeight(nodes[0].Out, nodes[4], 10)
|
236
|
244
|
|
237
|
245
|
// Create Expected graph
|
238
|
246
|
Expected, Keep := createExpectedNodes(nodes[3], nodes[4])
|
239
|
247
|
createExpectedEdges(Expected[0], Expected[1])
|
240
|
248
|
makeExpectedEdgeResidual(Expected[0], Expected[1])
|
|
249
|
+ setEdgeWeight(Expected[0].Out, Expected[1].Node, 10)
|
241
|
250
|
return TrimTreeTestCase{
|
242
|
251
|
Initial: graph,
|
243
|
252
|
Expected: Expected,
|