gecoder 0.8.3 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,164 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
class DistinctSampleProblem < Gecode::Model
|
5
|
-
attr :vars
|
6
|
-
attr :sets
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
@vars = int_var_array(2, 1)
|
10
|
-
@sets = set_var_array(2, [], 0..2)
|
11
|
-
branch_on @sets
|
12
|
-
end
|
13
|
-
end
|
14
|
-
|
15
|
-
describe Gecode::Constraints::IntEnum::Distinct do
|
16
|
-
before do
|
17
|
-
@model = DistinctSampleProblem.new
|
18
|
-
@invoke_options = lambda do |hash|
|
19
|
-
@model.vars.must_be.distinct(hash)
|
20
|
-
@model.solve!
|
21
|
-
end
|
22
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
23
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
24
|
-
an_instance_of(Gecode::Raw::Space),
|
25
|
-
an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'should translate into a distinct constraint' do
|
30
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
31
|
-
an_instance_of(Gecode::Raw::Space),
|
32
|
-
anything, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
33
|
-
@invoke_options.call({})
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should constrain variables to be distinct' do
|
37
|
-
# This won't work well without branching or propagation strengths. So this
|
38
|
-
# just shows that the distinct constraint will cause trivially unsolvable
|
39
|
-
# problems to directly fail.
|
40
|
-
@model.vars.must_be.distinct
|
41
|
-
@model.solve!.should be_nil
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'should not allow negation' do
|
45
|
-
lambda{ @model.vars.must_not_be.distinct }.should raise_error(
|
46
|
-
Gecode::MissingConstraintError)
|
47
|
-
end
|
48
|
-
|
49
|
-
it_should_behave_like 'non-reifiable constraint'
|
50
|
-
end
|
51
|
-
|
52
|
-
describe Gecode::Constraints::IntEnum::Distinct, ' (with offsets)' do
|
53
|
-
before do
|
54
|
-
@model = DistinctSampleProblem.new
|
55
|
-
@invoke_options = lambda do |hash|
|
56
|
-
@model.vars.with_offsets(1,2).must_be.distinct(hash)
|
57
|
-
@model.solve!
|
58
|
-
end
|
59
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
60
|
-
if reif_var.nil?
|
61
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
62
|
-
an_instance_of(Gecode::Raw::Space),
|
63
|
-
anything, an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
|
64
|
-
else
|
65
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
66
|
-
an_instance_of(Gecode::Raw::Space),
|
67
|
-
anything, an_instance_of(Gecode::Raw::IntVarArray),
|
68
|
-
strength, kind, reif_var)
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
it 'should translate into a distinct constraint with offsets' do
|
74
|
-
Gecode::Raw.should_receive(:distinct).once.with(
|
75
|
-
an_instance_of(Gecode::Raw::Space),
|
76
|
-
anything, anything, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
77
|
-
@invoke_options.call({})
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'should consider offsets when making variables distinct' do
|
81
|
-
@model.vars.with_offsets(-1,0).must_be.distinct
|
82
|
-
x,y = @model.solve!.vars
|
83
|
-
x.value.should equal(1)
|
84
|
-
y.value.should equal(1)
|
85
|
-
end
|
86
|
-
|
87
|
-
# This tests two distinct in conjunction. It's here because of a bug found.
|
88
|
-
it 'should play nice with normal distinct' do
|
89
|
-
@model.vars.with_offsets(-1,0).must_be.distinct
|
90
|
-
@model.vars.must_be.distinct
|
91
|
-
@model.solve!.should be_nil
|
92
|
-
end
|
93
|
-
|
94
|
-
it 'should accept an array as offsets' do
|
95
|
-
@model.vars.with_offsets([-1,0]).must_be.distinct
|
96
|
-
x,y = @model.solve!.vars
|
97
|
-
x.value.should equal(1)
|
98
|
-
y.value.should equal(1)
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'should not allow negation' do
|
102
|
-
lambda{ @model.vars.with_offsets(1,2).must_not_be.distinct }.should
|
103
|
-
raise_error(Gecode::MissingConstraintError)
|
104
|
-
end
|
105
|
-
|
106
|
-
it_should_behave_like 'non-reifiable constraint'
|
107
|
-
end
|
108
|
-
|
109
|
-
describe Gecode::Constraints::SetEnum::Distinct, ' (at most one)' do
|
110
|
-
before do
|
111
|
-
@model = DistinctSampleProblem.new
|
112
|
-
@sets = @model.sets
|
113
|
-
@size = 2
|
114
|
-
|
115
|
-
@invoke_options = lambda do |hash|
|
116
|
-
@sets.must.at_most_share_one_element hash.update(:size => @size)
|
117
|
-
@model.solve!
|
118
|
-
end
|
119
|
-
@expect_options = lambda do |strength, reif_var|
|
120
|
-
Gecode::Raw.should_receive(:atmostOne).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 atmostOne constraint' do
|
127
|
-
Gecode::Raw.should_receive(:atmostOne).once.with(
|
128
|
-
an_instance_of(Gecode::Raw::Space),
|
129
|
-
an_instance_of(Gecode::Raw::SetVarArray), @size)
|
130
|
-
@sets.must.at_most_share_one_element(:size => @size)
|
131
|
-
@model.solve!
|
132
|
-
end
|
133
|
-
|
134
|
-
it 'should constrain sets to have at most one element in common' do
|
135
|
-
@sets.must.at_most_share_one_element(:size => @size)
|
136
|
-
@sets[0].must_not_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.to_a & set2.value.to_a).size.should <= 1
|
143
|
-
end
|
144
|
-
|
145
|
-
it 'should not allow negation' do
|
146
|
-
lambda do
|
147
|
-
@sets.must_not.at_most_share_one_element(:size => @size)
|
148
|
-
end.should raise_error(Gecode::MissingConstraintError)
|
149
|
-
end
|
150
|
-
|
151
|
-
it 'should not allow options other than :size' do
|
152
|
-
lambda do
|
153
|
-
@sets.must.at_most_share_one_element(:size => @size, :foo => 17)
|
154
|
-
end.should raise_error(ArgumentError)
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'should raise error if :size is not specified' do
|
158
|
-
lambda do
|
159
|
-
@sets.must.at_most_share_one_element
|
160
|
-
end.should raise_error(ArgumentError)
|
161
|
-
end
|
162
|
-
|
163
|
-
it_should_behave_like 'non-reifiable set constraint'
|
164
|
-
end
|
@@ -1,108 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
class ElementSampleProblem < Gecode::Model
|
5
|
-
attr :prices
|
6
|
-
attr :store
|
7
|
-
attr :price
|
8
|
-
attr :fixnum_prices
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
prices = [17, 63, 45, 63]
|
12
|
-
@fixnum_prices = wrap_enum(prices)
|
13
|
-
@prices = int_var_array(4, prices)
|
14
|
-
@store = int_var(0...prices.size)
|
15
|
-
@price = int_var(prices)
|
16
|
-
branch_on wrap_enum([@store])
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
describe Gecode::Constraints::IntEnum::Element do
|
21
|
-
before do
|
22
|
-
@model = ElementSampleProblem.new
|
23
|
-
@prices = @model.prices
|
24
|
-
@target = @price = @model.price
|
25
|
-
@store = @model.store
|
26
|
-
@fixnum_prices = @model.fixnum_prices
|
27
|
-
|
28
|
-
# Creates an expectation corresponding to the specified input.
|
29
|
-
@expect = lambda do |element, relation, target, strength, kind, reif_var, negated|
|
30
|
-
@model.allow_space_access do
|
31
|
-
target = an_instance_of(Gecode::Raw::IntVar) if target.respond_to? :bind
|
32
|
-
element = an_instance_of(Gecode::Raw::IntVar) if element.respond_to? :bind
|
33
|
-
if reif_var.nil?
|
34
|
-
if !negated and relation == Gecode::Raw::IRT_EQ and
|
35
|
-
!target.kind_of? Fixnum
|
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, kind)
|
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, kind)
|
45
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
46
|
-
an_instance_of(Gecode::Raw::Space),
|
47
|
-
an_instance_of(Gecode::Raw::IntVar),
|
48
|
-
relation, target, strength, kind)
|
49
|
-
end
|
50
|
-
else
|
51
|
-
Gecode::Raw.should_receive(:element).once.with(
|
52
|
-
an_instance_of(Gecode::Raw::Space),
|
53
|
-
an_instance_of(Gecode::Raw::IntVarArray),
|
54
|
-
element, an_instance_of(Gecode::Raw::IntVar), strength, kind)
|
55
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
56
|
-
an_instance_of(Gecode::Raw::Space),
|
57
|
-
an_instance_of(Gecode::Raw::IntVar), relation, target,
|
58
|
-
an_instance_of(Gecode::Raw::BoolVar), strength, kind)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# For constraint option spec.
|
64
|
-
@invoke_options = lambda do |hash|
|
65
|
-
@prices[@store].must_be.greater_than(@price, hash)
|
66
|
-
@model.solve!
|
67
|
-
end
|
68
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
69
|
-
@expect.call(@store, Gecode::Raw::IRT_GR, @price, strength, kind,
|
70
|
-
reif_var, false)
|
71
|
-
end
|
72
|
-
|
73
|
-
# For composite spec.
|
74
|
-
@invoke_relation = lambda do |relation, target, negated|
|
75
|
-
if negated
|
76
|
-
@prices[@store].must_not.send(relation, target)
|
77
|
-
else
|
78
|
-
@prices[@store].must.send(relation, target)
|
79
|
-
end
|
80
|
-
@model.solve!
|
81
|
-
end
|
82
|
-
@expect_relation = lambda do |relation, target, negated|
|
83
|
-
@expect.call(@store, relation, target, Gecode::Raw::ICL_DEF,
|
84
|
-
Gecode::Raw::PK_DEF, nil, negated)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'should not disturb normal array access' do
|
89
|
-
@fixnum_prices[2].should_not be_nil
|
90
|
-
@prices[2].should_not be_nil
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'should handle fixnum enums as enumeration' do
|
94
|
-
@fixnum_prices[@store].must == @fixnum_prices[2]
|
95
|
-
@model.solve!.store.value.should equal(2)
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'should translate reification when using equality' do
|
99
|
-
bool_var = @model.bool_var
|
100
|
-
@expect.call(@store, Gecode::Raw::IRT_EQ, @target, Gecode::Raw::ICL_DEF,
|
101
|
-
Gecode::Raw::PK_DEF, bool_var, false)
|
102
|
-
@prices[@store].must_be.equal_to(@target, :reify => bool_var)
|
103
|
-
@model.solve!
|
104
|
-
end
|
105
|
-
|
106
|
-
it_should_behave_like 'composite constraint'
|
107
|
-
it_should_behave_like 'reifiable constraint'
|
108
|
-
end
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
describe Gecode::Constraints::IntEnum::Equality do
|
5
|
-
before do
|
6
|
-
@model = Gecode::Model.new
|
7
|
-
@vars = @model.int_var_array(4, -2..2)
|
8
|
-
@invoke_options = lambda do |hash|
|
9
|
-
@vars.must_be.equal(hash)
|
10
|
-
@model.solve!
|
11
|
-
end
|
12
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
13
|
-
Gecode::Raw.should_receive(:eq).once.with(
|
14
|
-
an_instance_of(Gecode::Raw::Space),
|
15
|
-
anything, strength, kind)
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
it 'should translate equality constraints' do
|
20
|
-
@expect_options.call({})
|
21
|
-
@invoke_options.call({})
|
22
|
-
@vars.must_be.equal
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'should not allow negation' do
|
26
|
-
lambda{ @vars.must_not_be.equal }.should raise_error(
|
27
|
-
Gecode::MissingConstraintError)
|
28
|
-
end
|
29
|
-
|
30
|
-
it_should_behave_like 'non-reifiable constraint'
|
31
|
-
end
|
@@ -1,70 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
describe Gecode::Constraints::Int::Domain do
|
5
|
-
before do
|
6
|
-
@model = Gecode::Model.new
|
7
|
-
@domain = 0..3
|
8
|
-
@x = @model.int_var(@domain)
|
9
|
-
@range_domain = 1..2
|
10
|
-
@three_dot_range_domain = 1...2
|
11
|
-
@non_range_domain = [1, 3]
|
12
|
-
|
13
|
-
@invoke_options = lambda do |hash|
|
14
|
-
@x.must_be.in(@non_range_domain, hash)
|
15
|
-
@model.solve!
|
16
|
-
end
|
17
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
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
|
-
an_instance_of(Gecode::Raw::IntVar),
|
23
|
-
an_instance_of(Gecode::Raw::IntSet),
|
24
|
-
strength, kind)
|
25
|
-
else
|
26
|
-
Gecode::Raw.should_receive(:dom).once.with(
|
27
|
-
an_instance_of(Gecode::Raw::Space),
|
28
|
-
an_instance_of(Gecode::Raw::IntVar),
|
29
|
-
an_instance_of(Gecode::Raw::IntSet),
|
30
|
-
reif_var, strength, kind)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'should translate domain constraints with range domains' do
|
37
|
-
Gecode::Raw.should_receive(:dom).once.with(
|
38
|
-
an_instance_of(Gecode::Raw::Space),
|
39
|
-
an_instance_of(Gecode::Raw::IntVar), @range_domain.first,
|
40
|
-
@range_domain.last, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
41
|
-
@x.must_be.in @range_domain
|
42
|
-
@model.solve!
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'should translate domain constraints with three dot range domains' do
|
46
|
-
Gecode::Raw.should_receive(:dom).once.with(
|
47
|
-
an_instance_of(Gecode::Raw::Space),
|
48
|
-
an_instance_of(Gecode::Raw::IntVar), @three_dot_range_domain.first,
|
49
|
-
@three_dot_range_domain.last, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
50
|
-
@x.must_be.in @three_dot_range_domain
|
51
|
-
@model.solve!
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'should translate domain constraints with non-range domains' do
|
55
|
-
@expect_options.call({})
|
56
|
-
@invoke_options.call({})
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'should handle negation' do
|
60
|
-
@x.must_not_be.in @range_domain
|
61
|
-
@model.solve!
|
62
|
-
@x.should have_domain(@domain.to_a - @range_domain.to_a)
|
63
|
-
end
|
64
|
-
|
65
|
-
it 'should raise error if the right hand side is not an enumeration' do
|
66
|
-
lambda{ @x.must_be.in 'hello' }.should raise_error(TypeError)
|
67
|
-
end
|
68
|
-
|
69
|
-
it_should_behave_like 'reifiable constraint'
|
70
|
-
end
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../spec_helper'
|
2
|
-
require File.dirname(__FILE__) + '/constraint_helper'
|
3
|
-
|
4
|
-
describe Gecode::Constraints::Int::Linear, ' (simple ones)' do
|
5
|
-
before do
|
6
|
-
@model = Gecode::Model.new
|
7
|
-
@x = @model.int_var(1..2)
|
8
|
-
@int = 4
|
9
|
-
@y = @model.int_var(1..2)
|
10
|
-
|
11
|
-
# For constraint option spec.
|
12
|
-
@invoke_options = lambda do |hash|
|
13
|
-
@x.must_be.greater_than(3, hash)
|
14
|
-
@model.solve!
|
15
|
-
end
|
16
|
-
@expect_options = option_expectation do |strength, kind, reif_var|
|
17
|
-
if reif_var.nil?
|
18
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
19
|
-
an_instance_of(Gecode::Raw::Space),
|
20
|
-
anything, Gecode::Raw::IRT_GR, anything,
|
21
|
-
strength, kind)
|
22
|
-
else
|
23
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
24
|
-
an_instance_of(Gecode::Raw::Space),
|
25
|
-
an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_GR, anything,
|
26
|
-
reif_var, strength, kind)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
|
32
|
-
it "should translate #{relation} with constant to simple relation" do
|
33
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
34
|
-
an_instance_of(Gecode::Raw::Space),
|
35
|
-
an_instance_of(Gecode::Raw::IntVar),
|
36
|
-
type, @int, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
37
|
-
@x.must.send(relation, @int)
|
38
|
-
@model.solve!
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
|
43
|
-
it "should translate negated #{relation} with constant to simple relation" do
|
44
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
45
|
-
an_instance_of(Gecode::Raw::Space),
|
46
|
-
an_instance_of(Gecode::Raw::IntVar),
|
47
|
-
type, @int, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
48
|
-
@x.must_not.send(relation, @int)
|
49
|
-
@model.solve!
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
|
54
|
-
it "should translate #{relation} with variables to simple relation" do
|
55
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
56
|
-
an_instance_of(Gecode::Raw::Space),
|
57
|
-
an_instance_of(Gecode::Raw::IntVar), type,
|
58
|
-
an_instance_of(Gecode::Raw::IntVar),
|
59
|
-
Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
60
|
-
@x.must.send(relation, @y)
|
61
|
-
@model.solve!
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
|
66
|
-
it "should translate negated #{relation} with variable to simple relation" do
|
67
|
-
Gecode::Raw.should_receive(:rel).once.with(
|
68
|
-
an_instance_of(Gecode::Raw::Space),
|
69
|
-
an_instance_of(Gecode::Raw::IntVar), type,
|
70
|
-
an_instance_of(Gecode::Raw::IntVar),
|
71
|
-
Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
|
72
|
-
@x.must_not.send(relation, @y)
|
73
|
-
@model.solve!
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'should raise error on arguments of the wrong type' do
|
78
|
-
lambda{ @x.must == 'hello' }.should raise_error(TypeError)
|
79
|
-
end
|
80
|
-
|
81
|
-
it_should_behave_like 'reifiable constraint'
|
82
|
-
end
|