munkres_ru 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/munkres_ru.rb +5 -1
- data/lib/munkres_ru/version.rb +1 -1
- data/rust/src/lib.rs +19 -10
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 57aeb4d7f66e44074883ade147c4a2620fd6049c
|
4
|
+
data.tar.gz: cb677ace1ae5617f387210774775948fce641f45
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 784093d58e12dee58e8c754de8ba23e32ba9b505d1a907ca59b13174d1ccfdb97ea3d0e9df804b89496691c076ded0f1062e34b952791dcfba7746324b29e59d
|
7
|
+
data.tar.gz: 76e0a3364dd01447de753b8f210feffa1ee66e427bed9217a5a20bc263bc4a1dbeee458a311db8ee3f13b55ac010e71330364fdc84d65389d4279bd6e6b1e6ee
|
data/lib/munkres_ru.rb
CHANGED
@@ -28,6 +28,10 @@ module MunkresRu
|
|
28
28
|
pointer = FFI::MemoryPointer.new :double, flattened.size
|
29
29
|
pointer.autorelease = false # Rust will take ownership of that memory
|
30
30
|
pointer.put_array_of_double 0, flattened
|
31
|
-
MunkresRu.solve_munkres(array.size, pointer).to_a
|
31
|
+
solved = MunkresRu.solve_munkres(array.size, pointer).to_a
|
32
|
+
if solved == [-1]
|
33
|
+
raise 'Solving Munkres problem failed, check if input is valid'
|
34
|
+
end
|
35
|
+
solved.each_slice(2).to_a
|
32
36
|
end
|
33
37
|
end
|
data/lib/munkres_ru/version.rb
CHANGED
data/rust/src/lib.rs
CHANGED
@@ -22,15 +22,24 @@ impl Array {
|
|
22
22
|
|
23
23
|
#[no_mangle]
|
24
24
|
pub extern fn solve_munkres(n: libc::size_t, array: *mut libc::c_double) -> Array {
|
25
|
-
let
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
25
|
+
let res = ::std::panic::catch_unwind(|| {
|
26
|
+
let size = n as usize;
|
27
|
+
let len = size*size;
|
28
|
+
let vec = unsafe { Vec::from_raw_parts(array, len, len) };
|
29
|
+
for &v in &vec {
|
30
|
+
assert!(!v.is_nan());
|
31
|
+
}
|
32
|
+
let mut weights: WeightMatrix<libc::c_double> = WeightMatrix::from_row_vec(size, vec);
|
33
|
+
let matching = solve_assignment(&mut weights);
|
34
|
+
let mut res = Vec::new();
|
35
|
+
for &(row, col) in &matching[..] {
|
36
|
+
res.push(row as libc::c_int);
|
37
|
+
res.push(col as libc::c_int);
|
38
|
+
}
|
39
|
+
Array::from_vec(res)
|
40
|
+
});
|
41
|
+
match res {
|
42
|
+
Ok(array) => array,
|
43
|
+
Err(_) => Array::from_vec(vec![-1]),
|
34
44
|
}
|
35
|
-
Array::from_vec(res)
|
36
45
|
}
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: munkres_ru
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Pirlik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -97,8 +97,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
version: '0'
|
98
98
|
requirements: []
|
99
99
|
rubyforge_project:
|
100
|
-
rubygems_version: 2.4.5.
|
100
|
+
rubygems_version: 2.4.5.2
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: Kuhn-Munkres implemented in Rust
|
104
104
|
test_files: []
|
105
|
+
has_rdoc:
|