bipartite_graph 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0337edfbdb191cec4827f50b61319f7b22f09b6e
|
4
|
+
data.tar.gz: 603a6ea7949fc5ceb857835b20f198dd24dfc4ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 92c315de8e08462a47c4f16e9ae8ad8447f75658e6ac2efafff13dd728c1633472b9db0d4b97970b900605187ae3fb465d4e8f10c27996d68edaecdedd8215bf
|
7
|
+
data.tar.gz: 53cc47a8d53c86f049cdaa5fa82f828bf6051406c797db89eac109ad8a51109555011856b0343a085fe83d0d954e5baefa4f48b3a03bf8ecac7ca616aa2c9dd3
|
@@ -34,12 +34,14 @@ module BipartiteGraph
|
|
34
34
|
matching = Matching.new(graph)
|
35
35
|
|
36
36
|
eq_graph.sources.each do |source|
|
37
|
+
matched = false
|
37
38
|
eq_graph.edges.from(source).each do |edge|
|
39
|
+
next if matched
|
38
40
|
included = matching.has_node?(edge.to)
|
39
41
|
|
40
42
|
if !included
|
41
43
|
matching.add_edge(edge)
|
42
|
-
|
44
|
+
matched = true
|
43
45
|
end
|
44
46
|
end
|
45
47
|
end
|
@@ -167,6 +169,10 @@ module BipartiteGraph
|
|
167
169
|
def augment_labelling_using(tree)
|
168
170
|
target_edges = graph.edges.from(tree.sources).not_to(tree.sinks)
|
169
171
|
|
172
|
+
if target_edges.empty?
|
173
|
+
raise "Target edge not found"
|
174
|
+
end
|
175
|
+
|
170
176
|
slack = target_edges.map do |edge|
|
171
177
|
labelling.label_for(edge.from) + labelling.label_for(edge.to) - edge.weight
|
172
178
|
end
|
@@ -74,7 +74,7 @@ describe "weighted matchings" do
|
|
74
74
|
# this example is constructed from simple example 2, so that the algorithm
|
75
75
|
# will fail (unless extra edges are added)
|
76
76
|
before do
|
77
|
-
|
77
|
+
[
|
78
78
|
['x1', 'y1', 3],
|
79
79
|
['x2', 'y1', 11],
|
80
80
|
['x3', 'y1', 10],
|
@@ -93,4 +93,26 @@ describe "weighted matchings" do
|
|
93
93
|
])
|
94
94
|
end
|
95
95
|
end
|
96
|
+
|
97
|
+
describe "massively degenerate example" do
|
98
|
+
before do
|
99
|
+
[
|
100
|
+
['x1', 'y1', 1],
|
101
|
+
['x2', 'y1', 1],
|
102
|
+
['x3', 'y1', 1],
|
103
|
+
['x1', 'y2', 1],
|
104
|
+
['x2', 'y2', 1],
|
105
|
+
['x3', 'y2', 1],
|
106
|
+
].each { |from, to, weight| graph.add_edge(from, to, weight) }
|
107
|
+
end
|
108
|
+
|
109
|
+
it "finds the solution" do
|
110
|
+
matching = graph.max_weight_matching.edges
|
111
|
+
|
112
|
+
expect(matching.length).to eq(2)
|
113
|
+
expect(matching.edges.inject(0) {|s, e| s + e.weight}).to eq(2)
|
114
|
+
end
|
115
|
+
|
116
|
+
|
117
|
+
end
|
96
118
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bipartite_graph
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Close
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-02-
|
11
|
+
date: 2015-02-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|