dither 0.1.5 → 0.2.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -1
- data/README.md +3 -0
- data/Rakefile +4 -0
- data/dither.gemspec +4 -0
- data/ext/dither/README.md +2 -0
- data/ext/dither/base_constraint_handler.h +36 -0
- data/ext/dither/combinations.h +127 -0
- data/ext/dither/dither.cc +47 -0
- data/ext/dither/dither.h +31 -0
- data/ext/dither/dither_types.h +32 -0
- data/ext/dither/extconf.rb +4 -0
- data/ext/dither/ipog.cc +451 -0
- data/ext/dither/ipog.h +128 -0
- data/ext/dither/simple_constraint_handler.cc +119 -0
- data/ext/dither/simple_constraint_handler.h +38 -0
- data/lib/dither/api.rb +20 -0
- data/lib/dither/version.rb +1 -1
- data/lib/dither.rb +64 -13
- data/spec/dither/dither_spec.rb +27 -96
- metadata +47 -12
- data/lib/dither/ipog.rb +0 -58
- data/lib/dither/ipog_helper.rb +0 -161
- data/lib/dither/mipog.rb +0 -85
- data/lib/dither/param.rb +0 -19
- data/lib/dither/test_case.rb +0 -80
- data/lib/dither/unbound_param.rb +0 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 378d5b7748d2b3993ef979f2e0ecc1e7f2f1866a
|
4
|
+
data.tar.gz: 6c3159e8073600044df182be4bd6dc201c9f45a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ac2ff8f4c0110f4a3b5d81e361bb52c568eccb7bc32cb28a7eed55f0f36ae7f7b2f1689804c4ed5a4c2cddec162c3946fa8bc995980e1f9968b606368e132b3
|
7
|
+
data.tar.gz: 6c4cc50f3da60255d6f1065506a8d1b2a2d0b601e96af11d3f664ee2374c08bd06c2bbc40006c2403308d021dd84d96d15f8cb83a11be9e51d4663c52ef88dab
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
dither (0.1.
|
4
|
+
dither (0.1.5)
|
5
|
+
ffi (~> 1.0)
|
5
6
|
|
6
7
|
GEM
|
7
8
|
remote: https://rubygems.org/
|
@@ -14,10 +15,13 @@ GEM
|
|
14
15
|
thor
|
15
16
|
diff-lcs (1.2.5)
|
16
17
|
docile (1.1.5)
|
18
|
+
ffi (1.9.6)
|
17
19
|
mime-types (2.3)
|
18
20
|
multi_json (1.10.1)
|
19
21
|
netrc (0.7.7)
|
20
22
|
rake (0.9.6)
|
23
|
+
rake-compiler (0.9.5)
|
24
|
+
rake
|
21
25
|
rest-client (1.7.2)
|
22
26
|
mime-types (>= 1.16, < 3.0)
|
23
27
|
netrc (~> 0.7)
|
@@ -52,4 +56,5 @@ DEPENDENCIES
|
|
52
56
|
coveralls
|
53
57
|
dither!
|
54
58
|
rake (~> 0.9.2)
|
59
|
+
rake-compiler
|
55
60
|
rspec (~> 3.2)
|
data/README.md
CHANGED
data/Rakefile
CHANGED
data/dither.gemspec
CHANGED
@@ -16,6 +16,7 @@ Gem::Specification.new do |s|
|
|
16
16
|
|
17
17
|
s.add_development_dependency "rspec", "~> 3.2"
|
18
18
|
s.add_development_dependency "rake", "~> 0.9.2"
|
19
|
+
s.add_development_dependency "rake-compiler"
|
19
20
|
s.add_development_dependency "coveralls"
|
20
21
|
|
21
22
|
files = `git ls-files`.split("\n")
|
@@ -25,6 +26,9 @@ Gem::Specification.new do |s|
|
|
25
26
|
# compile dither-java on jdk 8
|
26
27
|
files << "lib/dither-0.1.3.jar"
|
27
28
|
files << "lib/choco-solver-3.3.1-with-dependencies.jar"
|
29
|
+
else
|
30
|
+
s.add_dependency "ffi", "~> 1.0"
|
31
|
+
s.extensions = 'ext/dither/extconf.rb'
|
28
32
|
end
|
29
33
|
s.files = files
|
30
34
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright (C) 2015 Jason Gowan
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This software may be modified and distributed under the terms
|
7
|
+
* of the BSD license. See the LICENSE file for details.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#ifndef BASE_CONSTRAINT_HANDLER_H_
|
11
|
+
#define BASE_CONSTRAINT_HANDLER_H_
|
12
|
+
|
13
|
+
#include <vector>
|
14
|
+
#include "dither_types.h"
|
15
|
+
|
16
|
+
namespace dither {
|
17
|
+
|
18
|
+
class BaseConstraintHandler {
|
19
|
+
public:
|
20
|
+
BaseConstraintHandler(){};
|
21
|
+
virtual ~BaseConstraintHandler(){};
|
22
|
+
virtual bool violate_constraints(const dtest_case &test_case) { return false; }
|
23
|
+
virtual bool violate_constraints(const std::vector<param> &test_case) {
|
24
|
+
return false;
|
25
|
+
}
|
26
|
+
virtual bool ground(dtest_case &test_case) {
|
27
|
+
for (auto it = test_case.begin(); it != test_case.end(); ++it) {
|
28
|
+
if ((*it) == -1) {
|
29
|
+
*it = 0;
|
30
|
+
}
|
31
|
+
}
|
32
|
+
return true;
|
33
|
+
}
|
34
|
+
};
|
35
|
+
}
|
36
|
+
#endif // BASE_CONSTRAINT_HANDLER_H_
|
@@ -0,0 +1,127 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright (C) 2015 Jason Gowan
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This software may be modified and distributed under the terms
|
7
|
+
* of the BSD license. See the LICENSE file for details.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#ifndef COMBINATIONS_H_
|
11
|
+
#define COMBINATIONS_H_
|
12
|
+
|
13
|
+
#include <vector>
|
14
|
+
#include <forward_list>
|
15
|
+
#include "dither_types.h"
|
16
|
+
|
17
|
+
namespace dither {
|
18
|
+
|
19
|
+
inline void product(
|
20
|
+
std::forward_list<dtest_case>& rvvi, // final result
|
21
|
+
dtest_case& rvi, // current result
|
22
|
+
std::vector<dtest_case>::const_iterator me, // current input
|
23
|
+
std::vector<dtest_case>::const_iterator end); // final input
|
24
|
+
|
25
|
+
inline void product2(
|
26
|
+
std::forward_list<std::vector<param>>& rvvi, // final result
|
27
|
+
std::vector<param>& rvi, // current result
|
28
|
+
std::vector<std::vector<param>>::const_iterator me, // current input
|
29
|
+
std::vector<std::vector<param>>::const_iterator end); // final input
|
30
|
+
|
31
|
+
inline void gcombinations_(const std::vector<int>&, std::vector<int>&,
|
32
|
+
std::forward_list<std::vector<int>>&);
|
33
|
+
|
34
|
+
inline void combinations(const int, const std::vector<int>&,
|
35
|
+
std::forward_list<std::vector<int>>&);
|
36
|
+
|
37
|
+
inline void product2(
|
38
|
+
std::forward_list<std::vector<param>>& rvvi, // final result
|
39
|
+
std::vector<param>& rvi, // current result
|
40
|
+
std::vector<std::vector<param>>::const_iterator me, // current input
|
41
|
+
std::vector<std::vector<param>>::const_iterator end) // final input
|
42
|
+
{
|
43
|
+
if (me == end) {
|
44
|
+
// terminal condition of the recursion. We no longer have
|
45
|
+
// any input vectors to manipulate. Add the current result (rvi)
|
46
|
+
// to the total set of results (rvvvi).
|
47
|
+
rvvi.push_front(rvi);
|
48
|
+
return;
|
49
|
+
}
|
50
|
+
|
51
|
+
// need an easy name for my vector-of-ints
|
52
|
+
const std::vector<param>& mevi = *me;
|
53
|
+
for (std::vector<param>::const_iterator it = mevi.begin(); it != mevi.end();
|
54
|
+
it++) {
|
55
|
+
// final rvi will look like "a, b, c, ME, d, e, f"
|
56
|
+
// At the moment, rvi already has "a, b, c"
|
57
|
+
rvi.push_back(*it); // add ME
|
58
|
+
product2(rvvi, rvi, me + 1, end); // add "d, e, f"
|
59
|
+
rvi.pop_back(); // clean ME off for next round
|
60
|
+
}
|
61
|
+
}
|
62
|
+
|
63
|
+
void combinations(const int n, const std::vector<int>& input,
|
64
|
+
std::forward_list<std::vector<int>>& output) {
|
65
|
+
std::vector<int> scratch(n);
|
66
|
+
|
67
|
+
if (n <= input.size()) {
|
68
|
+
for (int i = 0; i < n; i++) {
|
69
|
+
scratch[i] = i;
|
70
|
+
}
|
71
|
+
|
72
|
+
gcombinations_(input, scratch, output);
|
73
|
+
while (1) {
|
74
|
+
int i;
|
75
|
+
for (i = n - 1; (i >= 0) && (scratch[i] == (input.size() - n + i)); i--)
|
76
|
+
;
|
77
|
+
|
78
|
+
if (i < 0) {
|
79
|
+
break;
|
80
|
+
} else {
|
81
|
+
scratch[i]++;
|
82
|
+
for (++i; i < n; i++) {
|
83
|
+
scratch[i] = scratch[i - 1] + 1;
|
84
|
+
}
|
85
|
+
gcombinations_(input, scratch, output);
|
86
|
+
}
|
87
|
+
}
|
88
|
+
}
|
89
|
+
}
|
90
|
+
|
91
|
+
inline void gcombinations_(const std::vector<int>& input,
|
92
|
+
std::vector<int>& scratch,
|
93
|
+
std::forward_list<std::vector<int>>& output) {
|
94
|
+
std::vector<int> result(scratch.size());
|
95
|
+
for (std::size_t i = 0; i < result.size(); i++) {
|
96
|
+
result[i] = input[scratch[i]];
|
97
|
+
}
|
98
|
+
output.push_front(result);
|
99
|
+
}
|
100
|
+
|
101
|
+
inline void product(
|
102
|
+
std::forward_list<dtest_case>& rvvi, // final result
|
103
|
+
dtest_case& rvi, // current result
|
104
|
+
std::vector<dtest_case>::const_iterator me, // current input
|
105
|
+
std::vector<dtest_case>::const_iterator end) // final input
|
106
|
+
{
|
107
|
+
if (me == end) {
|
108
|
+
// terminal condition of the recursion. We no longer have
|
109
|
+
// any input vectors to manipulate. Add the current result (rvi)
|
110
|
+
// to the total set of results (rvvvi).
|
111
|
+
rvvi.push_front(rvi);
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
|
115
|
+
// need an easy name for my vector-of-ints
|
116
|
+
const dtest_case& mevi = *me;
|
117
|
+
for (dtest_case::const_iterator it = mevi.begin(); it != mevi.end(); it++) {
|
118
|
+
// final rvi will look like "a, b, c, ME, d, e, f"
|
119
|
+
// At the moment, rvi already has "a, b, c"
|
120
|
+
rvi.push_back(*it); // add ME
|
121
|
+
product(rvvi, rvi, me + 1, end); // add "d, e, f"
|
122
|
+
rvi.pop_back(); // clean ME off for next round
|
123
|
+
}
|
124
|
+
}
|
125
|
+
}
|
126
|
+
|
127
|
+
#endif
|
@@ -0,0 +1,47 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright (C) 2015 Jason Gowan
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This software may be modified and distributed under the terms
|
7
|
+
* of the BSD license. See the LICENSE file for details.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#include "dither.h"
|
11
|
+
|
12
|
+
ipog_handle dither_ipog_new(const unsigned int t) { return new dither::Ipog(t); }
|
13
|
+
|
14
|
+
void dither_ipog_delete(ipog_handle self) {
|
15
|
+
delete static_cast<dither::Ipog *>(self);
|
16
|
+
}
|
17
|
+
|
18
|
+
void dither_ipog_add_parameter_int(ipog_handle self, const int index,
|
19
|
+
const int *values, const int values_length) {
|
20
|
+
const std::string name = std::to_string(index);
|
21
|
+
static_cast<dither::Ipog *>(self)->add_parameter(name, values, values_length);
|
22
|
+
}
|
23
|
+
|
24
|
+
void dither_ipog_run(ipog_handle self) {
|
25
|
+
static_cast<dither::Ipog *>(self)->init_param_cache();
|
26
|
+
static_cast<dither::Ipog *>(self)->run();
|
27
|
+
}
|
28
|
+
|
29
|
+
int dither_ipog_size(ipog_handle self) {
|
30
|
+
return static_cast<dither::Ipog *>(self)->size();
|
31
|
+
}
|
32
|
+
|
33
|
+
void dither_ipog_display_raw_solution(ipog_handle self) {
|
34
|
+
static_cast<dither::Ipog *>(self)->display_raw_solution();
|
35
|
+
}
|
36
|
+
|
37
|
+
void dither_ipog_fill(ipog_handle self, int *solution) {
|
38
|
+
static_cast<dither::Ipog *>(self)->fill(solution);
|
39
|
+
}
|
40
|
+
|
41
|
+
void dither_ipog_add_constraint(ipog_handle self, const int constraint[], const int length) {
|
42
|
+
static_cast<dither::Ipog *>(self)->add_constraint(constraint, length);
|
43
|
+
}
|
44
|
+
|
45
|
+
void dither_ipog_add_previously_tested(ipog_handle self, const int tested[], const int length) {
|
46
|
+
static_cast<dither::Ipog *>(self)->add_previously_tested(tested, length);
|
47
|
+
}
|
data/ext/dither/dither.h
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright (C) 2015 Jason Gowan
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This software may be modified and distributed under the terms
|
7
|
+
* of the BSD license. See the LICENSE file for details.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#ifndef DITHER_H_
|
11
|
+
#define DITHER_H_
|
12
|
+
|
13
|
+
#include <string>
|
14
|
+
#include "ipog.h"
|
15
|
+
|
16
|
+
extern "C" {
|
17
|
+
|
18
|
+
typedef void* ipog_handle;
|
19
|
+
|
20
|
+
ipog_handle dither_ipog_new(const unsigned int);
|
21
|
+
void dither_ipog_add_parameter_int(ipog_handle, const int, const int[],
|
22
|
+
const int);
|
23
|
+
void dither_ipog_run(ipog_handle);
|
24
|
+
int dither_ipog_size(ipog_handle);
|
25
|
+
void dither_ipog_display_raw_solution(ipog_handle);
|
26
|
+
void dither_ipog_fill(ipog_handle, int[]);
|
27
|
+
void dither_ipog_delete(ipog_handle self);
|
28
|
+
void dither_ipog_add_constraint(ipog_handle self, const int[], const int );
|
29
|
+
void dither_ipog_add_previously_tested(ipog_handle self, const int[], const int );
|
30
|
+
}
|
31
|
+
#endif // DITHER_H_
|
@@ -0,0 +1,32 @@
|
|
1
|
+
/*
|
2
|
+
*
|
3
|
+
* Copyright (C) 2015 Jason Gowan
|
4
|
+
* All rights reserved.
|
5
|
+
*
|
6
|
+
* This software may be modified and distributed under the terms
|
7
|
+
* of the BSD license. See the LICENSE file for details.
|
8
|
+
*/
|
9
|
+
|
10
|
+
#ifndef DITHER_TYPES_H_
|
11
|
+
#define DITHER_TYPES_H_
|
12
|
+
|
13
|
+
#include <string>
|
14
|
+
|
15
|
+
namespace dither {
|
16
|
+
|
17
|
+
typedef signed char dval;
|
18
|
+
|
19
|
+
#define DITHER_BOOL_T 0
|
20
|
+
#define DITHER_INT_T 1
|
21
|
+
#define DITHER_STRING_T 2
|
22
|
+
|
23
|
+
struct param {
|
24
|
+
std::size_t first;
|
25
|
+
dval second;
|
26
|
+
std::string name;
|
27
|
+
unsigned char type;
|
28
|
+
};
|
29
|
+
typedef std::vector<dval> dtest_case;
|
30
|
+
}
|
31
|
+
|
32
|
+
#endif
|