gecoder 0.8.3 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +15 -0
- data/README +6 -2
- data/example/equation_system.rb +15 -0
- data/example/magic_sequence.rb +7 -7
- data/example/money.rb +36 -0
- data/example/queens.rb +7 -8
- data/example/send_most_money.rb +1 -1
- data/example/square_tiling.rb +2 -2
- data/example/sudoku-set.rb +11 -12
- data/example/sudoku.rb +40 -45
- data/ext/extconf.rb +0 -0
- data/lib/gecoder/bindings.rb +42 -0
- data/lib/gecoder/bindings/bindings.rb +16 -0
- data/lib/gecoder/interface.rb +2 -1
- data/lib/gecoder/interface/branch.rb +16 -9
- data/lib/gecoder/interface/constraints.rb +410 -451
- data/lib/gecoder/interface/constraints/bool/boolean.rb +205 -213
- data/lib/gecoder/interface/constraints/bool/channel.rb +4 -5
- data/lib/gecoder/interface/constraints/bool/linear.rb +192 -21
- data/lib/gecoder/interface/constraints/bool_enum/channel.rb +43 -39
- data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +43 -49
- data/lib/gecoder/interface/constraints/bool_enum/relation.rb +38 -71
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +73 -22
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +140 -61
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +4 -4
- data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
- data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
- data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +131 -130
- data/lib/gecoder/interface/constraints/int/channel.rb +21 -31
- data/lib/gecoder/interface/constraints/int/domain.rb +45 -42
- data/lib/gecoder/interface/constraints/int/linear.rb +85 -239
- data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +55 -64
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +35 -37
- data/lib/gecoder/interface/constraints/int_enum/count.rb +53 -78
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +36 -46
- data/lib/gecoder/interface/constraints/int_enum/element.rb +39 -57
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +15 -19
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +65 -72
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +42 -45
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +79 -22
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +215 -44
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +14 -14
- data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
- data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
- data/lib/gecoder/interface/constraints/set/cardinality.rb +43 -53
- data/lib/gecoder/interface/constraints/set/channel.rb +26 -29
- data/lib/gecoder/interface/constraints/set/connection.rb +89 -152
- data/lib/gecoder/interface/constraints/set/domain.rb +112 -65
- data/lib/gecoder/interface/constraints/set/include.rb +36 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +96 -110
- data/lib/gecoder/interface/constraints/set/relation.rb +114 -137
- data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
- data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +23 -27
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +18 -19
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +62 -53
- data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +73 -23
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +222 -57
- data/lib/gecoder/interface/enum_matrix.rb +4 -4
- data/lib/gecoder/interface/enum_wrapper.rb +71 -22
- data/lib/gecoder/interface/model.rb +167 -12
- data/lib/gecoder/interface/model_sugar.rb +84 -0
- data/lib/gecoder/interface/search.rb +30 -18
- data/lib/gecoder/interface/variables.rb +103 -33
- data/lib/gecoder/version.rb +2 -2
- data/specs/bool_var.rb +19 -12
- data/specs/constraints/{boolean.rb → bool/boolean.rb} +103 -28
- data/specs/constraints/bool/boolean_properties.rb +51 -0
- data/specs/constraints/bool/linear.rb +213 -0
- data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
- data/specs/constraints/bool_enum/channel.rb +102 -0
- data/specs/constraints/{extensional.rb → bool_enum/extensional.rb} +32 -101
- data/specs/constraints/constraint_helper.rb +149 -179
- data/specs/constraints/constraint_receivers.rb +103 -0
- data/specs/constraints/constraints.rb +6 -63
- data/specs/constraints/fixnum_enum/element.rb +58 -0
- data/specs/constraints/fixnum_enum/operation.rb +67 -0
- data/specs/constraints/int/arithmetic.rb +149 -0
- data/specs/constraints/int/channel.rb +101 -0
- data/specs/constraints/int/domain.rb +106 -0
- data/specs/constraints/int/linear.rb +183 -0
- data/specs/constraints/int/linear_properties.rb +97 -0
- data/specs/constraints/int/relation.rb +84 -0
- data/specs/constraints/int_enum/arithmetic.rb +72 -0
- data/specs/constraints/int_enum/channel.rb +57 -0
- data/specs/constraints/int_enum/count.rb +72 -0
- data/specs/constraints/int_enum/distinct.rb +80 -0
- data/specs/constraints/int_enum/element.rb +61 -0
- data/specs/constraints/int_enum/equality.rb +29 -0
- data/specs/constraints/int_enum/extensional.rb +224 -0
- data/specs/constraints/int_enum/sort.rb +167 -0
- data/specs/constraints/operands.rb +264 -0
- data/specs/constraints/property_helper.rb +443 -0
- data/specs/constraints/reification_sugar.rb +4 -5
- data/specs/constraints/selected_set/select.rb +56 -0
- data/specs/constraints/selected_set/select_properties.rb +157 -0
- data/specs/constraints/set/cardinality.rb +58 -0
- data/specs/constraints/set/cardinality_properties.rb +46 -0
- data/specs/constraints/set/channel.rb +77 -0
- data/specs/constraints/set/connection.rb +176 -0
- data/specs/constraints/set/domain.rb +197 -0
- data/specs/constraints/set/include.rb +36 -0
- data/specs/constraints/set/operation.rb +132 -0
- data/specs/constraints/set/relation.rb +117 -0
- data/specs/constraints/set_elements/relation.rb +84 -0
- data/specs/constraints/set_enum/channel.rb +80 -0
- data/specs/constraints/set_enum/distinct.rb +59 -0
- data/specs/constraints/set_enum/operation.rb +111 -0
- data/specs/constraints/set_enum/select.rb +73 -0
- data/specs/enum_wrapper.rb +53 -3
- data/specs/int_var.rb +44 -25
- data/specs/model.rb +58 -1
- data/specs/model_sugar.rb +30 -0
- data/specs/search.rb +24 -5
- data/specs/selected_set.rb +39 -0
- data/specs/set_elements.rb +34 -0
- data/specs/set_var.rb +22 -8
- data/specs/spec_helper.rb +206 -6
- data/tasks/distribution.rake +22 -7
- data/tasks/svn.rake +3 -1
- metadata +218 -134
- data/lib/gecoder/interface/constraints/set_enum/selection.rb +0 -217
- data/specs/constraints/arithmetic.rb +0 -351
- data/specs/constraints/bool_enum_relation.rb +0 -160
- data/specs/constraints/cardinality.rb +0 -157
- data/specs/constraints/channel.rb +0 -454
- data/specs/constraints/connection.rb +0 -369
- data/specs/constraints/count.rb +0 -146
- data/specs/constraints/distinct.rb +0 -164
- data/specs/constraints/element.rb +0 -108
- data/specs/constraints/equality.rb +0 -31
- data/specs/constraints/int_domain.rb +0 -70
- data/specs/constraints/int_relation.rb +0 -82
- data/specs/constraints/linear.rb +0 -340
- data/specs/constraints/selection.rb +0 -292
- data/specs/constraints/set_domain.rb +0 -185
- data/specs/constraints/set_operation.rb +0 -285
- data/specs/constraints/set_relation.rb +0 -197
- data/specs/constraints/sort.rb +0 -179
@@ -1,197 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
describe Gecode::Constraints::Set::Relation do
|
5
|
-
include GecodeR::Specs::SetHelper
|
6
|
-
|
7
|
-
before do
|
8
|
-
@model = Gecode::Model.new
|
9
|
-
@set = @model.set_var([0], 0..3)
|
10
|
-
@set2 = @model.set_var([1], 0..3)
|
11
|
-
|
12
|
-
@expect = lambda do |relation_type, rhs, reif_var, negated|
|
13
|
-
@model.allow_space_access do
|
14
|
-
if reif_var.nil? and !negated
|
15
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
16
|
-
an_instance_of(Gecode::Raw::Space),
|
17
|
-
an_instance_of(Gecode::Raw::SetVar), relation_type,
|
18
|
-
an_instance_of(Gecode::Raw::SetVar))
|
19
|
-
else
|
20
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
21
|
-
an_instance_of(Gecode::Raw::Space),
|
22
|
-
an_instance_of(Gecode::Raw::SetVar), relation_type,
|
23
|
-
an_instance_of(Gecode::Raw::SetVar),
|
24
|
-
an_instance_of(Gecode::Raw::BoolVar))
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
# For options spec.
|
30
|
-
@invoke_options = lambda do |hash|
|
31
|
-
@set.must_be.superset_of(@set2, hash)
|
32
|
-
@model.solve!
|
33
|
-
end
|
34
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
35
|
-
@expect.call(Gecode::Raw::SRT_SUP, @set2, reif_var, false)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
Gecode::Constraints::Util::SET_RELATION_TYPES.each_pair do |relation, type|
|
40
|
-
next if relation == :==
|
41
|
-
|
42
|
-
it "should translate #{relation} with set to relation constraint" do
|
43
|
-
@expect.call(type, @set2, nil, false)
|
44
|
-
@set.must.send(relation, @set2)
|
45
|
-
@model.solve!
|
46
|
-
end
|
47
|
-
|
48
|
-
it "should translate negated #{relation} with set to relation constraint" do
|
49
|
-
@expect.call(type, @set2, nil, true)
|
50
|
-
@set.must_not.send(relation, @set2)
|
51
|
-
@model.solve!
|
52
|
-
end
|
53
|
-
end
|
54
|
-
it_should_behave_like 'reifiable set constraint'
|
55
|
-
end
|
56
|
-
|
57
|
-
describe Gecode::Constraints::Set::Relation, ' (equality)' do
|
58
|
-
include GecodeR::Specs::SetHelper
|
59
|
-
|
60
|
-
before do
|
61
|
-
@model = Gecode::Model.new
|
62
|
-
@set = @model.set_var([0], 0..1)
|
63
|
-
@set2 = @model.set_var([1], 0..1)
|
64
|
-
|
65
|
-
@expect = lambda do |relation_type, rhs, reif_var|
|
66
|
-
@model.allow_space_access do
|
67
|
-
if reif_var.nil?
|
68
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
69
|
-
an_instance_of(Gecode::Raw::Space),
|
70
|
-
an_instance_of(Gecode::Raw::SetVar), relation_type,
|
71
|
-
an_instance_of(Gecode::Raw::SetVar))
|
72
|
-
else
|
73
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
74
|
-
an_instance_of(Gecode::Raw::Space),
|
75
|
-
an_instance_of(Gecode::Raw::SetVar), relation_type,
|
76
|
-
an_instance_of(Gecode::Raw::SetVar),
|
77
|
-
an_instance_of(Gecode::Raw::BoolVar))
|
78
|
-
end
|
79
|
-
end
|
80
|
-
end
|
81
|
-
|
82
|
-
# For options spec.
|
83
|
-
@invoke_options = lambda do |hash|
|
84
|
-
@set.must_be.equal_to(@set2, hash)
|
85
|
-
@model.solve!
|
86
|
-
end
|
87
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
88
|
-
@expect.call(Gecode::Raw::SRT_EQ, @set2, reif_var)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'should translate equality with set to relation constraint' do
|
93
|
-
@expect.call(Gecode::Raw::SRT_EQ, @set2, nil)
|
94
|
-
@set.must == @set2
|
95
|
-
@model.solve!
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should translate negated equality with set to domain constraint' do
|
99
|
-
@expect.call(Gecode::Raw::SRT_NQ, @set2, nil)
|
100
|
-
@set.must_not == @set2
|
101
|
-
@model.solve!
|
102
|
-
end
|
103
|
-
|
104
|
-
it 'should constrain sets to be equality when not negated' do
|
105
|
-
@set.must == @set2
|
106
|
-
@model.solve!
|
107
|
-
@set.should have_bounds(0..1, 0..1)
|
108
|
-
@set2.should have_bounds(0..1, 0..1)
|
109
|
-
end
|
110
|
-
|
111
|
-
it 'should constrain sets to not be equal when negated' do
|
112
|
-
@set.must_not == @set2
|
113
|
-
union = @model.set_var([0, 1], [0, 1])
|
114
|
-
@set.must_not == union
|
115
|
-
@set2.must_not == union
|
116
|
-
@model.solve!
|
117
|
-
@set.should have_bounds([0], [0])
|
118
|
-
@set2.should have_bounds([1], [1])
|
119
|
-
end
|
120
|
-
|
121
|
-
it_should_behave_like 'reifiable set constraint'
|
122
|
-
end
|
123
|
-
|
124
|
-
describe Gecode::Constraints::Set::Relation, ' (elements)' do
|
125
|
-
include GecodeR::Specs::SetHelper
|
126
|
-
|
127
|
-
before do
|
128
|
-
@model = Gecode::Model.new
|
129
|
-
@set = @model.set_var([0], 0..2)
|
130
|
-
@int_var = @model.int_var(0..2)
|
131
|
-
@int_constant = 2
|
132
|
-
@model.branch_on @model.wrap_enum([@set])
|
133
|
-
@expect = lambda do |relation_type, rhs|
|
134
|
-
@model.allow_space_access do
|
135
|
-
if rhs.kind_of? Fixnum
|
136
|
-
rhs = an_instance_of(Gecode::Raw::IntVar)
|
137
|
-
end
|
138
|
-
rhs = rhs.bind if rhs.respond_to? :bind
|
139
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
140
|
-
an_instance_of(Gecode::Raw::Space),
|
141
|
-
an_instance_of(Gecode::Raw::SetVar), relation_type,
|
142
|
-
an_instance_of(Gecode::Raw::IntVar))
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
@invoke_options = lambda do |hash|
|
147
|
-
@set.elements.must_be.equal_to(@int_var, hash)
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
|
152
|
-
it "should translate #{relation} with variable to relation constraint" do
|
153
|
-
@expect.call(type, @int_var)
|
154
|
-
@set.elements.must.send(relation, @int_var)
|
155
|
-
@model.solve!
|
156
|
-
end
|
157
|
-
|
158
|
-
it "should translate #{relation} with constant to relation constraint" do
|
159
|
-
@expect.call(type, @int_constant)
|
160
|
-
@set.elements.must.send(relation, @int_constant)
|
161
|
-
@model.solve!
|
162
|
-
end
|
163
|
-
end
|
164
|
-
|
165
|
-
Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
|
166
|
-
it "should translate negated #{relation} with variable to relation constraint" do
|
167
|
-
@expect.call(type, @int_var)
|
168
|
-
@set.elements.must_not.send(relation, @int_var)
|
169
|
-
@model.solve!
|
170
|
-
end
|
171
|
-
|
172
|
-
it "should translate negated #{relation} with constant to relation constraint" do
|
173
|
-
@expect.call(type, @int_constant)
|
174
|
-
@set.elements.must_not.send(relation, @int_constant)
|
175
|
-
@model.solve!
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'should constrain the elements of the set' do
|
180
|
-
@set.elements.must <= @int_var
|
181
|
-
@int_var.must == 0
|
182
|
-
@model.solve!
|
183
|
-
@set.should be_assigned
|
184
|
-
@set.value.should include(0)
|
185
|
-
@set.value.should_not include(1,2)
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should constrain the elements of the set (constant parameter)' do
|
189
|
-
@set.elements.must <= 0
|
190
|
-
@model.solve!
|
191
|
-
@set.should be_assigned
|
192
|
-
@set.value.should include(0)
|
193
|
-
@set.value.should_not include(1,2)
|
194
|
-
end
|
195
|
-
|
196
|
-
it_should_behave_like 'non-reifiable set constraint'
|
197
|
-
end
|
data/specs/constraints/sort.rb
DELETED
@@ -1,179 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
class SortSampleProblem < Gecode::Model
|
5
|
-
attr :vars
|
6
|
-
attr :sorted
|
7
|
-
attr :indices
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@vars = int_var_array(4, 10..19)
|
11
|
-
@sorted = int_var_array(4, 10..19)
|
12
|
-
@indices = int_var_array(4, 0..9)
|
13
|
-
|
14
|
-
# To make it more interesting
|
15
|
-
@vars.must_be.distinct
|
16
|
-
|
17
|
-
branch_on @vars
|
18
|
-
end
|
19
|
-
end
|
20
|
-
|
21
|
-
describe Gecode::Constraints::IntEnum::Sort, ' (without :as and :order)' do
|
22
|
-
before do
|
23
|
-
@model = SortSampleProblem.new
|
24
|
-
@vars = @model.vars
|
25
|
-
@sorted = @model.sorted
|
26
|
-
|
27
|
-
@invoke_options = lambda do |hash|
|
28
|
-
@vars.must_be.sorted(hash)
|
29
|
-
@model.solve!
|
30
|
-
end
|
31
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
32
|
-
if reif_var.nil?
|
33
|
-
Gecode::Raw.should_receive(:rel).exactly(@vars.size - 1).times.with(
|
34
|
-
an_instance_of(Gecode::Raw::Space),
|
35
|
-
an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_LQ,
|
36
|
-
an_instance_of(Gecode::Raw::IntVar), strength, kind)
|
37
|
-
else
|
38
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
39
|
-
an_instance_of(Gecode::Raw::Space), anything,
|
40
|
-
an_instance_of(Gecode::Raw::BoolVarArray),
|
41
|
-
anything, anything, anything)
|
42
|
-
Gecode::Raw.should_receive(:rel).exactly(@vars.size - 1).times.with(
|
43
|
-
an_instance_of(Gecode::Raw::Space),
|
44
|
-
an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_LQ,
|
45
|
-
an_instance_of(Gecode::Raw::IntVar),
|
46
|
-
an_instance_of(Gecode::Raw::BoolVar), strength, kind)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'should translate into n relation constraints' do
|
52
|
-
@expect_options.call({})
|
53
|
-
@invoke_options.call({})
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'should constraint variables to be sorted' do
|
57
|
-
@vars.must_be.sorted
|
58
|
-
values = @model.solve!.vars.values
|
59
|
-
values.should == values.sort
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'should allow negation' do
|
63
|
-
@vars.must_not_be.sorted
|
64
|
-
@model.solve!
|
65
|
-
values = @vars.values
|
66
|
-
values.should_not == values.sort
|
67
|
-
end
|
68
|
-
|
69
|
-
it_should_behave_like 'reifiable constraint'
|
70
|
-
end
|
71
|
-
|
72
|
-
describe Gecode::Constraints::IntEnum::Sort, ' (with :as)' do
|
73
|
-
before do
|
74
|
-
@model = SortSampleProblem.new
|
75
|
-
@vars = @model.vars
|
76
|
-
@sorted = @model.sorted
|
77
|
-
|
78
|
-
# Make it a bit more interesting.
|
79
|
-
@vars[0].must > @vars[3] + 1
|
80
|
-
|
81
|
-
@invoke_options = lambda do |hash|
|
82
|
-
@vars.must_be.sorted hash.update(:as => @sorted)
|
83
|
-
@model.solve!
|
84
|
-
end
|
85
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
86
|
-
Gecode::Raw.should_receive(:sorted).once.with(
|
87
|
-
an_instance_of(Gecode::Raw::Space),
|
88
|
-
an_instance_of(Gecode::Raw::IntVarArray),
|
89
|
-
an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should translate into a sortedness constraints' do
|
94
|
-
@expect_options.call({})
|
95
|
-
@invoke_options.call({})
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should constraint variables to be sorted' do
|
99
|
-
@vars.must_be.sorted(:as => @sorted)
|
100
|
-
@model.solve!
|
101
|
-
values = @sorted.values
|
102
|
-
values.should == values.sort
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'should not allow targets that are not int var enums' do
|
106
|
-
lambda{ @vars.must_be.sorted(:as => 'hello') }.should raise_error(TypeError)
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'should not allow negation' do
|
110
|
-
lambda{ @vars.must_not_be.sorted(:as => @sorted) }.should raise_error(
|
111
|
-
Gecode::MissingConstraintError)
|
112
|
-
end
|
113
|
-
|
114
|
-
it_should_behave_like 'non-reifiable constraint'
|
115
|
-
end
|
116
|
-
|
117
|
-
describe Gecode::Constraints::IntEnum::Sort, ' (with :order)' do
|
118
|
-
before do
|
119
|
-
@model = SortSampleProblem.new
|
120
|
-
@vars = @model.vars
|
121
|
-
@sorted = @model.sorted
|
122
|
-
@indices = @model.indices
|
123
|
-
|
124
|
-
# Make it a bit more interesting.
|
125
|
-
@vars[0].must > @vars[3] + 1
|
126
|
-
|
127
|
-
@invoke_options = lambda do |hash|
|
128
|
-
@vars.must_be.sorted hash.update(:order => @indices, :as => @sorted)
|
129
|
-
@model.solve!
|
130
|
-
end
|
131
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
132
|
-
Gecode::Raw.should_receive(:sorted).once.with(
|
133
|
-
an_instance_of(Gecode::Raw::Space),
|
134
|
-
an_instance_of(Gecode::Raw::IntVarArray),
|
135
|
-
an_instance_of(Gecode::Raw::IntVarArray),
|
136
|
-
an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
|
140
|
-
it 'should translate into a sortedness constraints' do
|
141
|
-
@expect_options.call({})
|
142
|
-
@invoke_options.call({})
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should translate into a sortedness constraints, even without a target' do
|
146
|
-
@expect_options.call({})
|
147
|
-
@vars.must_be.sorted(:order => @indices)
|
148
|
-
@model.solve!
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should constraint variables to be sorted with the specified indices' do
|
152
|
-
@vars.must_be.sorted(:as => @sorted, :order => @indices)
|
153
|
-
@model.solve!
|
154
|
-
sorted_values = @sorted.values
|
155
|
-
sorted_values.should == sorted_values.sort
|
156
|
-
expected_indices = @vars.map{ |v| sorted_values.index(v.value) }
|
157
|
-
@indices.values.should == expected_indices
|
158
|
-
end
|
159
|
-
|
160
|
-
it 'should not allow targets that are not int var enums' do
|
161
|
-
lambda do
|
162
|
-
@vars.must_be.sorted(:as => 'hello', :order => @indices)
|
163
|
-
end.should raise_error(TypeError)
|
164
|
-
end
|
165
|
-
|
166
|
-
it 'should not allow order that are not int var enums' do
|
167
|
-
lambda do
|
168
|
-
@vars.must_be.sorted(:as => @sorted, :order => 'hello')
|
169
|
-
end.should raise_error(TypeError)
|
170
|
-
end
|
171
|
-
|
172
|
-
it 'should not allow negation' do
|
173
|
-
lambda do
|
174
|
-
@vars.must_not_be.sorted(:as => @sorted, :order => @indices)
|
175
|
-
end.should raise_error(Gecode::MissingConstraintError)
|
176
|
-
end
|
177
|
-
|
178
|
-
it_should_behave_like 'non-reifiable constraint'
|
179
|
-
end
|