graphmatch 1.0.0.pre → 1.0.0
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.
- data/lib/graphmatch.rb +24 -12
- metadata +8 -6
data/lib/graphmatch.rb
CHANGED
@@ -1,25 +1,37 @@
|
|
1
1
|
class Graphmatch
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
# Optimally match two sets of vertices.
|
3
|
+
#
|
4
|
+
# The edges must be specified as a hash of hashes, the keys being left vertices
|
5
|
+
# and the values be a hash of right vertices and the weights to them.
|
6
|
+
#
|
7
|
+
# Ex. Matching ['a', 'b'] to [1, 2], restrict it so 'a' can only reach 2.
|
8
|
+
# All path lengths are uniform (= 0)
|
9
|
+
#
|
10
|
+
# left_vertices = ["a", "b"]
|
11
|
+
# right_vertices = [1, 2]
|
12
|
+
# edges = {"a" => {2 => 0},
|
13
|
+
# "b" => {1 => 0, 2 >= 0}}
|
14
|
+
#
|
15
|
+
# If the path lengths are equal, set search to :shortest_path
|
16
|
+
# If the path lengths vary, set search to :min_cost to optimize for min-cost max-flow
|
17
|
+
#
|
18
|
+
# @param left_vertices [Array] list of names of vertices on the left
|
19
|
+
# @param right_vertices [Array] list of names of vertices on the right
|
20
|
+
# @param edges [Hash] a hash of hashes, edges and their weights from left to right
|
21
|
+
# @param search [Symbol] the augmentation path search type, :shortest_path or :min_cost
|
22
|
+
# @return [Hash] keys are left vertices, values are right vertices
|
23
|
+
def self.match(left_vertices, right_vertices, edges, search = :shortest_path)
|
7
24
|
vertices = left_vertices + right_vertices + [:sink, :source]
|
8
25
|
|
9
26
|
edges[:sink] = {}
|
10
|
-
edges[:source] = {}
|
27
|
+
edges[:source] = {}
|
11
28
|
|
12
29
|
left_vertices.each { |lv| edges[:source][lv] = 0 }
|
13
30
|
right_vertices.each { |rv| edges[rv] = { :sink => 0 } }
|
14
31
|
|
15
32
|
graph = { vertices: vertices, edges: edges }
|
16
|
-
puts graph
|
17
|
-
|
18
|
-
matching = Graphmatch::Maxflow.best_matching! graph
|
19
|
-
puts "Created matching"
|
20
|
-
puts matching
|
21
33
|
|
22
|
-
matching
|
34
|
+
matching = Maxflow.best_matching! graph, search = search
|
23
35
|
end
|
24
36
|
end
|
25
37
|
|
metadata
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: graphmatch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.0
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Paul Hemberger
|
@@ -10,9 +10,10 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2013-02-
|
13
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
14
14
|
dependencies: []
|
15
|
-
description: An implementation of the Ford-Fulkerson max-flow algorithm
|
15
|
+
description: An implementation of the Ford-Fulkerson max-flow algorithm.Supports maximum
|
16
|
+
flow as well as minimum-cost maximum flow.
|
16
17
|
email: pwh@mit.edu
|
17
18
|
executables: []
|
18
19
|
extensions: []
|
@@ -34,9 +35,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
34
35
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
36
|
none: false
|
36
37
|
requirements:
|
37
|
-
- - ! '
|
38
|
+
- - ! '>='
|
38
39
|
- !ruby/object:Gem::Version
|
39
|
-
version:
|
40
|
+
version: '0'
|
40
41
|
requirements: []
|
41
42
|
rubyforge_project:
|
42
43
|
rubygems_version: 1.8.24
|
@@ -44,3 +45,4 @@ signing_key:
|
|
44
45
|
specification_version: 3
|
45
46
|
summary: Optimal bipartite graph matching
|
46
47
|
test_files: []
|
48
|
+
has_rdoc:
|