gecoder 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +16 -3
- data/example/magic_sequence.rb +1 -1
- data/example/queens.rb +1 -1
- data/example/send_more_money.rb +1 -1
- data/example/sudoku.rb +1 -1
- data/ext/missing.cpp +18 -4
- data/ext/missing.h +8 -0
- data/lib/gecoder/bindings.rb +30 -3
- data/lib/gecoder/bindings/bindings.rb +22 -0
- data/lib/gecoder/interface/binding_changes.rb +81 -107
- data/lib/gecoder/interface/branch.rb +65 -14
- data/lib/gecoder/interface/constraints.rb +1 -0
- data/lib/gecoder/interface/constraints/bool_enum/boolean.rb +16 -12
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +7 -3
- data/lib/gecoder/interface/constraints/int/linear.rb +19 -16
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +8 -4
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +14 -6
- data/lib/gecoder/interface/constraints/int_enum/element.rb +7 -5
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +1 -4
- data/lib/gecoder/interface/constraints/set/cardinality.rb +6 -3
- data/lib/gecoder/interface/constraints/set/connection.rb +136 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +18 -0
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +61 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +32 -0
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +1 -0
- data/lib/gecoder/interface/enum_wrapper.rb +12 -3
- data/lib/gecoder/interface/model.rb +77 -56
- data/lib/gecoder/interface/search.rb +74 -5
- data/lib/gecoder/interface/variables.rb +117 -15
- data/lib/gecoder/version.rb +1 -1
- data/specs/binding_changes.rb +9 -5
- data/specs/bool_var.rb +8 -12
- data/specs/branch.rb +85 -19
- data/specs/constraints/arithmetic.rb +99 -71
- data/specs/constraints/bool_enum.rb +26 -18
- data/specs/constraints/boolean.rb +53 -49
- data/specs/constraints/cardinality.rb +33 -26
- data/specs/constraints/channel.rb +77 -6
- data/specs/constraints/connection.rb +352 -0
- data/specs/constraints/constraints.rb +10 -1
- data/specs/constraints/count.rb +79 -39
- data/specs/constraints/distinct.rb +128 -9
- data/specs/constraints/element.rb +26 -19
- data/specs/constraints/equality.rb +2 -1
- data/specs/constraints/int_domain.rb +19 -12
- data/specs/constraints/int_relation.rb +12 -6
- data/specs/constraints/linear.rb +30 -30
- data/specs/constraints/reification_sugar.rb +8 -4
- data/specs/constraints/set_domain.rb +24 -18
- data/specs/constraints/set_relation.rb +38 -23
- data/specs/constraints/sort.rb +12 -10
- data/specs/enum_wrapper.rb +9 -3
- data/specs/int_var.rb +8 -4
- data/specs/logging.rb +24 -0
- data/specs/model.rb +25 -7
- data/specs/search.rb +41 -1
- data/specs/set_var.rb +36 -7
- data/specs/spec_helper.rb +3 -10
- data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +1 -1
- metadata +12 -3
- data/specs/tmp +0 -22
@@ -3,9 +3,12 @@ require File.dirname(__FILE__) + '/constraint_helper'
|
|
3
3
|
|
4
4
|
class DistinctSampleProblem < Gecode::Model
|
5
5
|
attr :vars
|
6
|
+
attr :sets
|
6
7
|
|
7
8
|
def initialize
|
8
9
|
@vars = int_var_array(2, 1)
|
10
|
+
@sets = set_var_array(2, [], 0..2)
|
11
|
+
branch_on wrap_enum(@sets)
|
9
12
|
end
|
10
13
|
end
|
11
14
|
|
@@ -17,13 +20,15 @@ describe Gecode::Constraints::IntEnum::Distinct do
|
|
17
20
|
@model.solve!
|
18
21
|
end
|
19
22
|
@expect_options = lambda do |strength, reif_var|
|
20
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
23
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
24
|
+
an_instance_of(Gecode::Raw::Space),
|
21
25
|
an_instance_of(Gecode::Raw::IntVarArray), strength)
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
25
29
|
it 'should translate into a distinct constraint' do
|
26
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
30
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
31
|
+
an_instance_of(Gecode::Raw::Space),
|
27
32
|
anything, Gecode::Raw::ICL_DEF)
|
28
33
|
@invoke_options.call({})
|
29
34
|
end
|
@@ -53,10 +58,12 @@ describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
|
|
53
58
|
end
|
54
59
|
@expect_options = lambda do |strength, reif_var|
|
55
60
|
if reif_var.nil?
|
56
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
61
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
62
|
+
an_instance_of(Gecode::Raw::Space),
|
57
63
|
anything, an_instance_of(Gecode::Raw::IntVarArray), strength)
|
58
64
|
else
|
59
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
65
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
66
|
+
an_instance_of(Gecode::Raw::Space),
|
60
67
|
anything, an_instance_of(Gecode::Raw::IntVarArray), strength,
|
61
68
|
an_instance_of(Gecode::Raw::BoolVar))
|
62
69
|
end
|
@@ -64,7 +71,8 @@ describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
|
|
64
71
|
end
|
65
72
|
|
66
73
|
it 'should translate into a distinct constraint with offsets' do
|
67
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
74
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
75
|
+
an_instance_of(Gecode::Raw::Space),
|
68
76
|
anything, anything, Gecode::Raw::ICL_DEF)
|
69
77
|
@invoke_options.call({})
|
70
78
|
end
|
@@ -72,8 +80,8 @@ describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
|
|
72
80
|
it 'should consider offsets when making variables distinct' do
|
73
81
|
@model.vars.with_offsets(-1,0).must_be.distinct
|
74
82
|
x,y = @model.solve!.vars
|
75
|
-
x.
|
76
|
-
y.
|
83
|
+
x.value.should equal(1)
|
84
|
+
y.value.should equal(1)
|
77
85
|
end
|
78
86
|
|
79
87
|
# This tests two distinct in conjunction. It's here because of a bug found.
|
@@ -86,8 +94,8 @@ describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
|
|
86
94
|
it 'should accept an array as offsets' do
|
87
95
|
@model.vars.with_offsets([-1,0]).must_be.distinct
|
88
96
|
x,y = @model.solve!.vars
|
89
|
-
x.
|
90
|
-
y.
|
97
|
+
x.value.should equal(1)
|
98
|
+
y.value.should equal(1)
|
91
99
|
end
|
92
100
|
|
93
101
|
it 'should not allow negation' do
|
@@ -96,4 +104,115 @@ describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
|
|
96
104
|
end
|
97
105
|
|
98
106
|
it_should_behave_like 'constraint with strength option'
|
107
|
+
end
|
108
|
+
|
109
|
+
describe Gecode::Constraints::SetEnum::Distinct do
|
110
|
+
before do
|
111
|
+
@model = DistinctSampleProblem.new
|
112
|
+
@sets = @model.sets
|
113
|
+
@size = 1
|
114
|
+
|
115
|
+
@invoke_options = lambda do |hash|
|
116
|
+
@sets.must_be.distinct(hash.update(:size => @size))
|
117
|
+
@model.solve!
|
118
|
+
end
|
119
|
+
@expect_options = lambda do |strength, reif_var|
|
120
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
121
|
+
an_instance_of(Gecode::Raw::Space),
|
122
|
+
an_instance_of(Gecode::Raw::SetVarArray), @size)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
126
|
+
it 'should translate into a distinct constraint' do
|
127
|
+
Gecode::Raw.should_receive(:distinct).once.with(
|
128
|
+
an_instance_of(Gecode::Raw::Space),
|
129
|
+
an_instance_of(Gecode::Raw::SetVarArray), @size)
|
130
|
+
@sets.must_be.distinct(:size => @size)
|
131
|
+
@model.solve!
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'should constrain sets to be distinct' do
|
135
|
+
@sets.must_be.distinct(:size => @size)
|
136
|
+
@sets[0].must_be.superset_of 0
|
137
|
+
solution = @model.solve!
|
138
|
+
solution.should_not be_nil
|
139
|
+
set1, set2 = solution.sets
|
140
|
+
set1.value.size.should == @size
|
141
|
+
set2.value.size.should == @size
|
142
|
+
set1.value.should_not == set2.value
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'should not allow negation' do
|
146
|
+
lambda{ @sets.must_not_be.distinct(:size => @size) }.should raise_error(
|
147
|
+
Gecode::MissingConstraintError)
|
148
|
+
end
|
149
|
+
|
150
|
+
it 'should not allow options other than :size' do
|
151
|
+
lambda do
|
152
|
+
@sets.must_be.distinct(:size => @size, :foo => 17)
|
153
|
+
end.should raise_error(ArgumentError)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'should raise error if :size is not specified' do
|
157
|
+
lambda{ @sets.must_be.distinct }.should raise_error(ArgumentError)
|
158
|
+
end
|
159
|
+
|
160
|
+
it_should_behave_like 'non-reifiable set constraint'
|
161
|
+
end
|
162
|
+
|
163
|
+
describe Gecode::Constraints::SetEnum::Distinct, ' (at most one)' do
|
164
|
+
before do
|
165
|
+
@model = DistinctSampleProblem.new
|
166
|
+
@sets = @model.sets
|
167
|
+
@size = 2
|
168
|
+
|
169
|
+
@invoke_options = lambda do |hash|
|
170
|
+
@sets.must.at_most_share_one_element hash.update(:size => @size)
|
171
|
+
@model.solve!
|
172
|
+
end
|
173
|
+
@expect_options = lambda do |strength, reif_var|
|
174
|
+
Gecode::Raw.should_receive(:atmostOne).once.with(
|
175
|
+
an_instance_of(Gecode::Raw::Space),
|
176
|
+
an_instance_of(Gecode::Raw::SetVarArray), @size)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
it 'should translate into a atmostOne constraint' do
|
181
|
+
Gecode::Raw.should_receive(:atmostOne).once.with(
|
182
|
+
an_instance_of(Gecode::Raw::Space),
|
183
|
+
an_instance_of(Gecode::Raw::SetVarArray), @size)
|
184
|
+
@sets.must.at_most_share_one_element(:size => @size)
|
185
|
+
@model.solve!
|
186
|
+
end
|
187
|
+
|
188
|
+
it 'should constrain sets to have at most one element in common' do
|
189
|
+
@sets.must.at_most_share_one_element(:size => @size)
|
190
|
+
@sets[0].must_not_be.superset_of 0
|
191
|
+
solution = @model.solve!
|
192
|
+
solution.should_not be_nil
|
193
|
+
set1, set2 = solution.sets
|
194
|
+
set1.value.size.should == @size
|
195
|
+
set2.value.size.should == @size
|
196
|
+
(set1.value.to_a & set2.value.to_a).size.should <= 1
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'should not allow negation' do
|
200
|
+
lambda do
|
201
|
+
@sets.must_not.at_most_share_one_element(:size => @size)
|
202
|
+
end.should raise_error(Gecode::MissingConstraintError)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should not allow options other than :size' do
|
206
|
+
lambda do
|
207
|
+
@sets.must.at_most_share_one_element(:size => @size, :foo => 17)
|
208
|
+
end.should raise_error(ArgumentError)
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'should raise error if :size is not specified' do
|
212
|
+
lambda do
|
213
|
+
@sets.must.at_most_share_one_element
|
214
|
+
end.should raise_error(ArgumentError)
|
215
|
+
end
|
216
|
+
|
217
|
+
it_should_behave_like 'non-reifiable set constraint'
|
99
218
|
end
|
@@ -27,28 +27,35 @@ describe Gecode::Constraints::IntEnum::Element do
|
|
27
27
|
|
28
28
|
# Creates an expectation corresponding to the specified input.
|
29
29
|
@expect = lambda do |element, relation, target, strength, reif_var, negated|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
if
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
30
|
+
@model.allow_space_access do
|
31
|
+
target = target.bind if target.respond_to? :bind
|
32
|
+
element = element.bind if element.respond_to? :bind
|
33
|
+
if reif_var.nil?
|
34
|
+
if !negated and relation == Gecode::Raw::IRT_EQ and
|
35
|
+
target.kind_of? Gecode::Raw::IntVar
|
36
|
+
Gecode::Raw.should_receive(:element).once.with(
|
37
|
+
an_instance_of(Gecode::Raw::Space),
|
38
|
+
an_instance_of(Gecode::Raw::IntVarArray),
|
39
|
+
element, target, strength)
|
40
|
+
else
|
41
|
+
Gecode::Raw.should_receive(:element).once.with(
|
42
|
+
an_instance_of(Gecode::Raw::Space),
|
43
|
+
an_instance_of(Gecode::Raw::IntVarArray),
|
44
|
+
element, an_instance_of(Gecode::Raw::IntVar), strength)
|
45
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
46
|
+
an_instance_of(Gecode::Raw::Space),
|
47
|
+
an_instance_of(Gecode::Raw::IntVar), relation, target, strength)
|
48
|
+
end
|
38
49
|
else
|
39
|
-
Gecode::Raw.should_receive(:element).once.with(
|
50
|
+
Gecode::Raw.should_receive(:element).once.with(
|
51
|
+
an_instance_of(Gecode::Raw::Space),
|
40
52
|
an_instance_of(Gecode::Raw::IntVarArray),
|
41
53
|
element, an_instance_of(Gecode::Raw::IntVar), strength)
|
42
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
43
|
-
an_instance_of(Gecode::Raw::
|
54
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
55
|
+
an_instance_of(Gecode::Raw::Space),
|
56
|
+
an_instance_of(Gecode::Raw::IntVar), relation, target,
|
57
|
+
an_instance_of(Gecode::Raw::BoolVar), strength)
|
44
58
|
end
|
45
|
-
else
|
46
|
-
Gecode::Raw.should_receive(:element).once.with(@model.active_space,
|
47
|
-
an_instance_of(Gecode::Raw::IntVarArray),
|
48
|
-
element, an_instance_of(Gecode::Raw::IntVar), strength)
|
49
|
-
Gecode::Raw.should_receive(:rel).once.with(@model.active_space,
|
50
|
-
an_instance_of(Gecode::Raw::IntVar), relation, target,
|
51
|
-
an_instance_of(Gecode::Raw::BoolVar), strength)
|
52
59
|
end
|
53
60
|
end
|
54
61
|
|
@@ -83,7 +90,7 @@ describe Gecode::Constraints::IntEnum::Element do
|
|
83
90
|
|
84
91
|
it 'should handle fixnum enums as enumeration' do
|
85
92
|
@fixnum_prices[@store].must == @fixnum_prices[2]
|
86
|
-
@model.solve!.store.
|
93
|
+
@model.solve!.store.value.should equal(2)
|
87
94
|
end
|
88
95
|
|
89
96
|
it 'should translate reification when using equality' do
|
@@ -10,7 +10,8 @@ describe Gecode::Constraints::IntEnum::Equality do
|
|
10
10
|
@model.solve!
|
11
11
|
end
|
12
12
|
@expect_options = lambda do |strength, reif_var|
|
13
|
-
Gecode::Raw.should_receive(:eq).once.with(
|
13
|
+
Gecode::Raw.should_receive(:eq).once.with(
|
14
|
+
an_instance_of(Gecode::Raw::Space),
|
14
15
|
anything, strength)
|
15
16
|
end
|
16
17
|
end
|
@@ -15,28 +15,35 @@ describe Gecode::Constraints::Int::Domain do
|
|
15
15
|
@model.solve!
|
16
16
|
end
|
17
17
|
@expect_options = lambda do |strength, reif_var|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
18
|
+
@model.allow_space_access do
|
19
|
+
if reif_var.nil?
|
20
|
+
Gecode::Raw.should_receive(:dom).once.with(
|
21
|
+
an_instance_of(Gecode::Raw::Space),
|
22
|
+
@x.bind, an_instance_of(Gecode::Raw::IntSet), strength)
|
23
|
+
else
|
24
|
+
Gecode::Raw.should_receive(:dom).once.with(
|
25
|
+
an_instance_of(Gecode::Raw::Space),
|
26
|
+
@x.bind, an_instance_of(Gecode::Raw::IntSet),
|
27
|
+
an_instance_of(Gecode::Raw::BoolVar), strength)
|
28
|
+
end
|
25
29
|
end
|
26
30
|
end
|
27
31
|
end
|
28
32
|
|
29
33
|
it 'should translate domain constraints with range domains' do
|
30
|
-
Gecode::Raw.should_receive(:dom).once.with(
|
31
|
-
|
34
|
+
Gecode::Raw.should_receive(:dom).once.with(
|
35
|
+
an_instance_of(Gecode::Raw::Space),
|
36
|
+
an_instance_of(Gecode::Raw::IntVar), @range_domain.first,
|
37
|
+
@range_domain.last, Gecode::Raw::ICL_DEF)
|
32
38
|
@x.must_be.in @range_domain
|
33
39
|
@model.solve!
|
34
40
|
end
|
35
41
|
|
36
42
|
it 'should translate domain constraints with three dot range domains' do
|
37
|
-
Gecode::Raw.should_receive(:dom).once.with(
|
38
|
-
|
39
|
-
Gecode::Raw::
|
43
|
+
Gecode::Raw.should_receive(:dom).once.with(
|
44
|
+
an_instance_of(Gecode::Raw::Space),
|
45
|
+
an_instance_of(Gecode::Raw::IntVar), @three_dot_range_domain.first,
|
46
|
+
@three_dot_range_domain.last, Gecode::Raw::ICL_DEF)
|
40
47
|
@x.must_be.in @three_dot_range_domain
|
41
48
|
@model.solve!
|
42
49
|
end
|
@@ -15,11 +15,13 @@ describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
|
|
15
15
|
end
|
16
16
|
@expect_options = lambda do |strength, reif_var|
|
17
17
|
if reif_var.nil?
|
18
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
18
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
19
|
+
an_instance_of(Gecode::Raw::Space),
|
19
20
|
anything, Gecode::Raw::IRT_GR, anything,
|
20
21
|
strength)
|
21
22
|
else
|
22
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
23
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
24
|
+
an_instance_of(Gecode::Raw::Space),
|
23
25
|
an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_GR, anything,
|
24
26
|
an_instance_of(Gecode::Raw::BoolVar), strength)
|
25
27
|
end
|
@@ -28,7 +30,8 @@ describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
|
|
28
30
|
|
29
31
|
Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
|
30
32
|
it "should translate #{relation} with constant to simple relation" do
|
31
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
33
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
34
|
+
an_instance_of(Gecode::Raw::Space),
|
32
35
|
an_instance_of(Gecode::Raw::IntVar), type, @int, Gecode::Raw::ICL_DEF)
|
33
36
|
@x.must.send(relation, @int)
|
34
37
|
@model.solve!
|
@@ -37,7 +40,8 @@ describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
|
|
37
40
|
|
38
41
|
Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
|
39
42
|
it "should translate negated #{relation} with constant to simple relation" do
|
40
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
43
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
44
|
+
an_instance_of(Gecode::Raw::Space),
|
41
45
|
an_instance_of(Gecode::Raw::IntVar), type, @int, Gecode::Raw::ICL_DEF)
|
42
46
|
@x.must_not.send(relation, @int)
|
43
47
|
@model.solve!
|
@@ -46,7 +50,8 @@ describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
|
|
46
50
|
|
47
51
|
Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
|
48
52
|
it "should translate #{relation} with variables to simple relation" do
|
49
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
53
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
54
|
+
an_instance_of(Gecode::Raw::Space),
|
50
55
|
an_instance_of(Gecode::Raw::IntVar), type,
|
51
56
|
an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::ICL_DEF)
|
52
57
|
@x.must.send(relation, @y)
|
@@ -56,7 +61,8 @@ describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
|
|
56
61
|
|
57
62
|
Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
|
58
63
|
it "should translate negated #{relation} with variable to simple relation" do
|
59
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
64
|
+
Gecode::Raw.should_receive(:rel).once.with(
|
65
|
+
an_instance_of(Gecode::Raw::Space),
|
60
66
|
an_instance_of(Gecode::Raw::IntVar), type,
|
61
67
|
an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::ICL_DEF)
|
62
68
|
@x.must_not.send(relation, @y)
|
data/specs/constraints/linear.rb
CHANGED
@@ -37,51 +37,51 @@ describe Gecode::Constraints::Int::Linear do
|
|
37
37
|
it 'should handle addition with a variable' do
|
38
38
|
(@x + @y).must == 0
|
39
39
|
sol = @model.solve!
|
40
|
-
x = sol.x.
|
41
|
-
y = sol.y.
|
40
|
+
x = sol.x.value
|
41
|
+
y = sol.y.value
|
42
42
|
(x + y).should be_zero
|
43
43
|
end
|
44
44
|
|
45
45
|
it 'should handle addition with multiple variables' do
|
46
46
|
(@x + @y + @z).must == 0
|
47
47
|
sol = @model.solve!
|
48
|
-
x = sol.x.
|
49
|
-
y = sol.y.
|
50
|
-
z = sol.z.
|
48
|
+
x = sol.x.value
|
49
|
+
y = sol.y.value
|
50
|
+
z = sol.z.value
|
51
51
|
(x + y + z).should be_zero
|
52
52
|
end
|
53
53
|
|
54
54
|
it 'should handle subtraction with a variable' do
|
55
55
|
(@x - @y).must == 0
|
56
56
|
sol = @model.solve!
|
57
|
-
x = sol.x.
|
58
|
-
y = sol.y.
|
57
|
+
x = sol.x.value
|
58
|
+
y = sol.y.value
|
59
59
|
(x - y).should be_zero
|
60
60
|
end
|
61
61
|
|
62
62
|
it 'should handle non-zero constants as right hand side' do
|
63
63
|
(@x + @y).must == 1
|
64
64
|
sol = @model.solve!
|
65
|
-
x = sol.x.
|
66
|
-
y = sol.y.
|
65
|
+
x = sol.x.value
|
66
|
+
y = sol.y.value
|
67
67
|
(x + y).should equal(1)
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'should handle variables as right hand side' do
|
71
71
|
(@x + @y).must == @z
|
72
72
|
sol = @model.solve!
|
73
|
-
x = sol.x.
|
74
|
-
y = sol.y.
|
75
|
-
z = sol.z.
|
73
|
+
x = sol.x.value
|
74
|
+
y = sol.y.value
|
75
|
+
z = sol.z.value
|
76
76
|
(x + y).should equal(z)
|
77
77
|
end
|
78
78
|
|
79
79
|
it 'should handle linear expressions as right hand side' do
|
80
80
|
(@x + @y).must == @z + @y
|
81
81
|
sol = @model.solve!
|
82
|
-
x = sol.x.
|
83
|
-
y = sol.y.
|
84
|
-
z = sol.z.
|
82
|
+
x = sol.x.value
|
83
|
+
y = sol.y.value
|
84
|
+
z = sol.z.value
|
85
85
|
(x + y).should equal(z + y)
|
86
86
|
end
|
87
87
|
|
@@ -92,49 +92,49 @@ describe Gecode::Constraints::Int::Linear do
|
|
92
92
|
it 'should handle coefficients other than 1' do
|
93
93
|
(@x * 2 + @y).must == 0
|
94
94
|
sol = @model.solve!
|
95
|
-
x = sol.x.
|
96
|
-
y = sol.y.
|
95
|
+
x = sol.x.value
|
96
|
+
y = sol.y.value
|
97
97
|
(2*x + y).should equal(0)
|
98
98
|
end
|
99
99
|
|
100
100
|
it 'should handle addition with constants' do
|
101
101
|
(@y + 2).must == 1
|
102
102
|
sol = @model.solve!
|
103
|
-
y = sol.y.
|
103
|
+
y = sol.y.value
|
104
104
|
(y + 2).should equal(1)
|
105
105
|
end
|
106
106
|
|
107
107
|
it 'should handle subtraction with a constant' do
|
108
108
|
(@x - 2).must == 0
|
109
109
|
sol = @model.solve!
|
110
|
-
x = sol.x.
|
110
|
+
x = sol.x.value
|
111
111
|
(x - 2).should be_zero
|
112
112
|
end
|
113
113
|
|
114
114
|
it 'should a single variable as left hande side' do
|
115
115
|
@x.must == @y + @z
|
116
116
|
sol = @model.solve!
|
117
|
-
x = sol.x.
|
118
|
-
y = sol.y.
|
119
|
-
z = sol.z.
|
117
|
+
x = sol.x.value
|
118
|
+
y = sol.y.value
|
119
|
+
z = sol.z.value
|
120
120
|
x.should equal(y + z)
|
121
121
|
end
|
122
122
|
|
123
123
|
it 'should handle parenthesis' do
|
124
124
|
(@x - (@y + @z)).must == 1
|
125
125
|
sol = @model.solve!
|
126
|
-
x = sol.x.
|
127
|
-
y = sol.y.
|
128
|
-
z = sol.z.
|
126
|
+
x = sol.x.value
|
127
|
+
y = sol.y.value
|
128
|
+
z = sol.z.value
|
129
129
|
(x - (y + z)).should equal(1)
|
130
130
|
end
|
131
131
|
|
132
132
|
it 'should handle multiplication of parenthesis' do
|
133
133
|
(((@x + @y*10)*10 + @z)*10).must == 0
|
134
134
|
sol = @model.solve!
|
135
|
-
x = sol.x.
|
136
|
-
y = sol.y.
|
137
|
-
z = sol.z.
|
135
|
+
x = sol.x.value
|
136
|
+
y = sol.y.value
|
137
|
+
z = sol.z.value
|
138
138
|
(((x + y*10)*10 + z)*10).should equal(0)
|
139
139
|
end
|
140
140
|
|
@@ -145,7 +145,7 @@ describe Gecode::Constraints::Int::Linear do
|
|
145
145
|
(@x + @y).must.send(relation, 1)
|
146
146
|
sol = @model.solve!
|
147
147
|
sol.should_not be_nil
|
148
|
-
(sol.x.
|
148
|
+
(sol.x.value + sol.y.value).should.send(relation, 1)
|
149
149
|
end
|
150
150
|
end
|
151
151
|
|
@@ -154,7 +154,7 @@ describe Gecode::Constraints::Int::Linear do
|
|
154
154
|
(@x + @y).must_not.send(relation, 1)
|
155
155
|
sol = @model.solve!
|
156
156
|
sol.should_not be_nil
|
157
|
-
(sol.x.
|
157
|
+
(sol.x.value + sol.y.value).should_not.send(relation, 1)
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|