hungarian_algorithm_c 0.0.4 → 0.0.5
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 93a7a92bf3729fb33bc7c669b574d0b8d6745c76
|
4
|
+
data.tar.gz: 8b0dbc726cbbdd0ae011506864969a63a3dde4d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22b1b5a810bc278a4631d76ee3e5e66304c3aac95df4521599a243688087f4b324bc1d7966e3031c910ed28c4dbf1876e8439a1c2f6802bf5082038f81d2b65f
|
7
|
+
data.tar.gz: 059bf391ceddd1cbff317559a50892c180f206759658d482b16003931d90181d6d97e5c896b67169716e5e5dcd189251fd267383530d587cef03bce749aa9cc3
|
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Add the following to your [Gemfile](http://tosbourn.com/what-is-the-gemfile/):
|
|
8
8
|
|
9
9
|
```ruby
|
10
10
|
# Gemfile
|
11
|
-
gem 'hungarian_algorithm_c'
|
11
|
+
gem 'hungarian_algorithm_c'
|
12
12
|
```
|
13
13
|
|
14
14
|
Run `bundle install`.
|
@@ -44,7 +44,7 @@ HungarianAlgorithmC.find_pairings(costs)
|
|
44
44
|
#=> [[0, 0], [1, 2], [2, 1]]
|
45
45
|
```
|
46
46
|
|
47
|
-
**Note**:
|
47
|
+
**Note**: Costs are held in the C code using `signed long long int`. If your matrix has values outside the range of the data type (e.g. `Float::INFINITY`, `BigNumber::INFINITY`, `-1e19`), they will be capped to the closest limit i.e. positive or negative 9_223_372_036_854_775_807.
|
48
48
|
|
49
49
|
## Acknowledgements
|
50
50
|
|
@@ -53,8 +53,7 @@ VALUE pairs(VALUE self, VALUE flattened_array_ruby, VALUE row_size_val) {
|
|
53
53
|
|
54
54
|
int index;
|
55
55
|
for (index = 0; index < array_size; index++) {
|
56
|
-
long
|
57
|
-
long long int rounded_element = element;
|
56
|
+
signed long long int rounded_element = NUM2LL(rb_ary_entry(flattened_array_ruby, index));
|
58
57
|
array_c[index] = rounded_element;
|
59
58
|
}
|
60
59
|
|
@@ -1,22 +1,48 @@
|
|
1
1
|
require_relative './hungarian_algorithm_c.so'
|
2
2
|
|
3
3
|
module HungarianAlgorithmC
|
4
|
+
# Limits for 'signed long long int' C data type
|
5
|
+
LIMITS = {
|
6
|
+
positive: +9_223_372_036_854_775_807,
|
7
|
+
negative: -9_223_372_036_854_775_807
|
8
|
+
}
|
9
|
+
private_constant :LIMITS
|
10
|
+
|
4
11
|
class << self
|
5
|
-
def find_pairings(
|
6
|
-
validate!(
|
7
|
-
|
12
|
+
def find_pairings(matrix)
|
13
|
+
validate!(matrix)
|
14
|
+
array = value_capped_flattened_array(matrix)
|
15
|
+
pairs(array, matrix.size)
|
16
|
+
end
|
17
|
+
|
18
|
+
def value_capped_flattened_array(matrix)
|
19
|
+
[].tap do |array|
|
20
|
+
matrix.each do |row|
|
21
|
+
row.each do |element|
|
22
|
+
array << begin
|
23
|
+
if element > LIMITS[:positive]
|
24
|
+
LIMITS[:positive]
|
25
|
+
elsif element < LIMITS[:negative]
|
26
|
+
LIMITS[:negative]
|
27
|
+
else
|
28
|
+
element
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
8
34
|
end
|
9
35
|
|
10
|
-
def validate!(
|
11
|
-
return if rectangular?(
|
12
|
-
raise ArgumentError.new('
|
36
|
+
def validate!(matrix)
|
37
|
+
return if rectangular?(matrix)
|
38
|
+
raise ArgumentError.new('matrix must be rectangular')
|
13
39
|
end
|
14
40
|
|
15
|
-
def rectangular?(
|
16
|
-
row_size =
|
17
|
-
|
41
|
+
def rectangular?(matrix)
|
42
|
+
row_size = matrix.size
|
43
|
+
matrix.all? { |column| row_size == column.size }
|
18
44
|
end
|
19
45
|
|
20
|
-
private :pairs, :validate!, :rectangular
|
46
|
+
private :pairs, :validate!, :rectangular?, :value_capped_flattened_array
|
21
47
|
end
|
22
48
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hungarian_algorithm_c
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Syed Humza Shah
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-05-
|
11
|
+
date: 2017-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|