bipartite_graph 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4ea037a79cf9dbd088c8d4351057ea39f62bdfa3
4
- data.tar.gz: ab0f8cc6fb801adf2a3460b01e45a36e7679638e
3
+ metadata.gz: 0337edfbdb191cec4827f50b61319f7b22f09b6e
4
+ data.tar.gz: 603a6ea7949fc5ceb857835b20f198dd24dfc4ef
5
5
  SHA512:
6
- metadata.gz: 0737da7745f9f99d8f2c7983d61d4b6277a840417afd5db021076733a024b811a345915fd1a6a9ac1a4ad1803a71a37bbb6b81f02f49a812e91609533977c7c6
7
- data.tar.gz: 8a1b329e9270035a201e55cc036b29ed103e42073dcecea9c9f9d80e2e4aec7f8dbe356ca37e8389ed89f84d90e02c008f6d935cddcc3314fcb695700de978e6
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
- next
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
@@ -1,3 +1,3 @@
1
1
  module BipartiteGraph
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  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.3
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-16 00:00:00.000000000 Z
11
+ date: 2015-02-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler