gecoder-with-gecode 0.9.0-x86-mswin32-60
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 +137 -0
- data/COPYING +17 -0
- data/LGPL-LICENSE +458 -0
- data/README +58 -0
- data/Rakefile +14 -0
- data/example/equation_system.rb +15 -0
- data/example/example_helper.rb +1 -0
- data/example/magic_sequence.rb +43 -0
- data/example/money.rb +36 -0
- data/example/queens.rb +42 -0
- data/example/send_more_money.rb +43 -0
- data/example/send_most_money.rb +58 -0
- data/example/square_tiling.rb +84 -0
- data/example/sudoku-set.rb +106 -0
- data/example/sudoku.rb +56 -0
- data/lib/gecode.dll +0 -0
- data/lib/gecoder.rb +5 -0
- data/lib/gecoder/bindings.rb +96 -0
- data/lib/gecoder/bindings/bindings.rb +2029 -0
- data/lib/gecoder/interface.rb +9 -0
- data/lib/gecoder/interface/binding_changes.rb +9 -0
- data/lib/gecoder/interface/branch.rb +163 -0
- data/lib/gecoder/interface/constraints.rb +471 -0
- data/lib/gecoder/interface/constraints/bool/boolean.rb +251 -0
- data/lib/gecoder/interface/constraints/bool/channel.rb +7 -0
- data/lib/gecoder/interface/constraints/bool/linear.rb +200 -0
- data/lib/gecoder/interface/constraints/bool_enum/channel.rb +68 -0
- data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +106 -0
- data/lib/gecoder/interface/constraints/bool_enum/relation.rb +55 -0
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +84 -0
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +155 -0
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
- 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 +150 -0
- data/lib/gecoder/interface/constraints/int/channel.rb +51 -0
- data/lib/gecoder/interface/constraints/int/domain.rb +80 -0
- data/lib/gecoder/interface/constraints/int/linear.rb +143 -0
- data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +63 -0
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +86 -0
- data/lib/gecoder/interface/constraints/int_enum/count.rb +66 -0
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +64 -0
- data/lib/gecoder/interface/constraints/int_enum/element.rb +64 -0
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +37 -0
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +187 -0
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +135 -0
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +95 -0
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +230 -0
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
- 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 +65 -0
- data/lib/gecoder/interface/constraints/set/channel.rb +51 -0
- data/lib/gecoder/interface/constraints/set/connection.rb +130 -0
- data/lib/gecoder/interface/constraints/set/domain.rb +156 -0
- data/lib/gecoder/interface/constraints/set/include.rb +36 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +118 -0
- data/lib/gecoder/interface/constraints/set/relation.rb +155 -0
- 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 +45 -0
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +43 -0
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +69 -0
- data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +84 -0
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +243 -0
- data/lib/gecoder/interface/enum_matrix.rb +64 -0
- data/lib/gecoder/interface/enum_wrapper.rb +205 -0
- data/lib/gecoder/interface/model.rb +453 -0
- data/lib/gecoder/interface/model_sugar.rb +84 -0
- data/lib/gecoder/interface/search.rb +197 -0
- data/lib/gecoder/interface/variables.rb +306 -0
- data/lib/gecoder/version.rb +4 -0
- data/specs/bool_var.rb +81 -0
- data/specs/branch.rb +185 -0
- data/specs/constraints/bool/boolean.rb +317 -0
- 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/bool_enum/extensional.rb +225 -0
- data/specs/constraints/constraint_helper.rb +234 -0
- data/specs/constraints/constraint_receivers.rb +103 -0
- data/specs/constraints/constraints.rb +26 -0
- 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 +69 -0
- 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/distribution.rb +14 -0
- data/specs/enum_matrix.rb +43 -0
- data/specs/enum_wrapper.rb +179 -0
- data/specs/examples.rb +17 -0
- data/specs/int_var.rb +163 -0
- data/specs/logging.rb +24 -0
- data/specs/model.rb +325 -0
- data/specs/model_sugar.rb +30 -0
- data/specs/search.rb +383 -0
- data/specs/selected_set.rb +39 -0
- data/specs/set_elements.rb +34 -0
- data/specs/set_var.rb +82 -0
- data/specs/spec_helper.rb +265 -0
- data/tasks/all_tasks.rb +1 -0
- data/tasks/dependencies.txt +22 -0
- data/tasks/distribution.rake +194 -0
- data/tasks/rcov.rake +18 -0
- data/tasks/specs.rake +21 -0
- data/tasks/svn.rake +16 -0
- data/tasks/website.rake +51 -0
- data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
- data/vendor/gecode/win32/lib/libgecodesupport.dll +0 -0
- data/vendor/rust/README +28 -0
- data/vendor/rust/bin/cxxgenerator.rb +93 -0
- data/vendor/rust/include/rust_checks.hh +116 -0
- data/vendor/rust/include/rust_conversions.hh +102 -0
- data/vendor/rust/rust.rb +67 -0
- data/vendor/rust/rust/attribute.rb +51 -0
- data/vendor/rust/rust/bindings.rb +172 -0
- data/vendor/rust/rust/class.rb +337 -0
- data/vendor/rust/rust/constants.rb +48 -0
- data/vendor/rust/rust/container.rb +110 -0
- data/vendor/rust/rust/cppifaceparser.rb +129 -0
- data/vendor/rust/rust/cwrapper.rb +72 -0
- data/vendor/rust/rust/cxxclass.rb +96 -0
- data/vendor/rust/rust/element.rb +81 -0
- data/vendor/rust/rust/enum.rb +63 -0
- data/vendor/rust/rust/function.rb +407 -0
- data/vendor/rust/rust/namespace.rb +61 -0
- data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
- data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
- data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
- data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
- data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
- data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
- data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +100 -0
- data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
- data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
- data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
- data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
- data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
- data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
- data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
- data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
- data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
- data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
- data/vendor/rust/rust/type.rb +98 -0
- data/vendor/rust/test/Makefile +4 -0
- data/vendor/rust/test/constants.rb +36 -0
- data/vendor/rust/test/cppclass.cc +45 -0
- data/vendor/rust/test/cppclass.hh +67 -0
- data/vendor/rust/test/cppclass.rb +59 -0
- data/vendor/rust/test/cwrapper.c +74 -0
- data/vendor/rust/test/cwrapper.h +41 -0
- data/vendor/rust/test/cwrapper.rb +56 -0
- data/vendor/rust/test/dummyclass.hh +31 -0
- data/vendor/rust/test/lib/extension-test.rb +98 -0
- data/vendor/rust/test/operators.cc +41 -0
- data/vendor/rust/test/operators.hh +39 -0
- data/vendor/rust/test/operators.rb +39 -0
- data/vendor/rust/test/test-constants.rb +43 -0
- data/vendor/rust/test/test-cppclass.rb +82 -0
- data/vendor/rust/test/test-cwrapper.rb +80 -0
- data/vendor/rust/test/test-operators.rb +42 -0
- metadata +393 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
[:&, :|, :^].each do |property|
|
4
|
+
describe Gecode::Bool, " (#{property} property)" do
|
5
|
+
before do
|
6
|
+
@model = Gecode::Model.new
|
7
|
+
@b1 = @model.bool_var
|
8
|
+
@b2 = @model.bool_var
|
9
|
+
@model.branch_on @model.wrap_enum([@b1, @b2])
|
10
|
+
|
11
|
+
# For bool operand producing property spec.
|
12
|
+
@property_types = [:bool, :bool]
|
13
|
+
@select_property = lambda do |bool1, bool2|
|
14
|
+
bool1.method(property).call bool2
|
15
|
+
end
|
16
|
+
@selected_property = @b1.method(property).call @b2
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'should constrain the conjunction/disjunction/exclusive disjunction' do
|
20
|
+
(@b1.method(property).call @b2).must_be.true
|
21
|
+
@model.solve!
|
22
|
+
@b1.value.method(property).call(@b2.value).should be_true
|
23
|
+
end
|
24
|
+
|
25
|
+
it_should_behave_like 'property that produces bool operand'
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe Gecode::Bool, ' (#implies property)' do
|
30
|
+
before do
|
31
|
+
@model = Gecode::Model.new
|
32
|
+
@b1 = @model.bool_var
|
33
|
+
@b2 = @model.bool_var
|
34
|
+
@model.branch_on @model.wrap_enum([@b1, @b2])
|
35
|
+
|
36
|
+
# For bool operand producing property spec.
|
37
|
+
@property_types = [:bool, :bool]
|
38
|
+
@select_property = lambda do |bool1, bool2|
|
39
|
+
bool1.implies bool2
|
40
|
+
end
|
41
|
+
@selected_property = @b1.implies @b2
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should constrain the implication' do
|
45
|
+
(@b1.implies @b2).must_be.true
|
46
|
+
@model.solve!
|
47
|
+
(!@b1.value | @b2.value).should be_true
|
48
|
+
end
|
49
|
+
|
50
|
+
it_should_behave_like 'property that produces bool operand'
|
51
|
+
end
|
@@ -0,0 +1,213 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class BoolLinearSampleProblem < Gecode::Model
|
4
|
+
attr :x
|
5
|
+
attr :y
|
6
|
+
attr :z
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@x = self.bool_var
|
10
|
+
@y = self.bool_var
|
11
|
+
@z = self.bool_var
|
12
|
+
branch_on wrap_enum([@x, @y, @z])
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class TrueClass
|
17
|
+
def to_i
|
18
|
+
1
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class FalseClass
|
23
|
+
def to_i
|
24
|
+
0
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe Gecode::Int::Linear, '(with booleans)' do
|
29
|
+
before do
|
30
|
+
@model = BoolLinearSampleProblem.new
|
31
|
+
@x = @model.x
|
32
|
+
@y = @model.y
|
33
|
+
@z = @model.z
|
34
|
+
@operand = @x + @y
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should handle addition with a variable' do
|
38
|
+
(@x + @y).must == 0
|
39
|
+
sol = @model.solve!
|
40
|
+
x = sol.x.value.to_i
|
41
|
+
y = sol.y.value.to_i
|
42
|
+
(x + y).should be_zero
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should handle reification (1)' do
|
46
|
+
bool = @model.bool_var
|
47
|
+
(@x + @y).must.equal(0, :reify => bool)
|
48
|
+
bool.must_be.false
|
49
|
+
sol = @model.solve!
|
50
|
+
x = sol.x.value.to_i
|
51
|
+
y = sol.y.value.to_i
|
52
|
+
(x + y).should_not be_zero
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'should handle reification (2)' do
|
56
|
+
bool = @model.bool_var
|
57
|
+
(@x + @y).must.equal(0, :reify => bool)
|
58
|
+
bool.must_be.true
|
59
|
+
sol = @model.solve!
|
60
|
+
x = sol.x.value.to_i
|
61
|
+
y = sol.y.value.to_i
|
62
|
+
(x + y).should be_zero
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'should handle addition with multiple variables' do
|
66
|
+
(@x + @y + @z).must == 0
|
67
|
+
sol = @model.solve!
|
68
|
+
x = sol.x.value.to_i
|
69
|
+
y = sol.y.value.to_i
|
70
|
+
z = sol.z.value.to_i
|
71
|
+
(x + y + z).should be_zero
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'should handle subtraction with a variable' do
|
75
|
+
(@x - @y).must == 0
|
76
|
+
sol = @model.solve!
|
77
|
+
x = sol.x.value.to_i
|
78
|
+
y = sol.y.value.to_i
|
79
|
+
(x - y).should be_zero
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should handle non-zero constants as right hand side' do
|
83
|
+
(@x + @y).must == 1
|
84
|
+
sol = @model.solve!
|
85
|
+
x = sol.x.value.to_i
|
86
|
+
y = sol.y.value.to_i
|
87
|
+
(x + y).should equal(1)
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'should handle single booleans as left hand side' do
|
91
|
+
@x.must == @y + 1
|
92
|
+
sol = @model.solve!
|
93
|
+
x = sol.x.value.to_i
|
94
|
+
y = sol.y.value.to_i
|
95
|
+
x.should equal(y + 1)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should handle single booleans as left hand side (2)' do
|
99
|
+
@x.must == @y + @z
|
100
|
+
sol = @model.solve!
|
101
|
+
x = sol.x.value.to_i
|
102
|
+
y = sol.y.value.to_i
|
103
|
+
z = sol.z.value.to_i
|
104
|
+
x.should equal(y + z)
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should handle single booleans as left hand side (3)' do
|
108
|
+
bool = @model.bool_var
|
109
|
+
@x.must.equal(@y + @z, :reify => bool)
|
110
|
+
bool.must_be.false
|
111
|
+
sol = @model.solve!
|
112
|
+
x = sol.x.value.to_i
|
113
|
+
y = sol.y.value.to_i
|
114
|
+
z = sol.z.value.to_i
|
115
|
+
x.should_not equal(y + z)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should handle variables as right hand side' do
|
119
|
+
(@x + @y).must == @z
|
120
|
+
sol = @model.solve!
|
121
|
+
x = sol.x.value.to_i
|
122
|
+
y = sol.y.value.to_i
|
123
|
+
z = sol.z.value.to_i
|
124
|
+
(x + y).should equal(z)
|
125
|
+
end
|
126
|
+
|
127
|
+
it 'should handle linear expressions as right hand side' do
|
128
|
+
(@x + @y).must == @z + @y
|
129
|
+
sol = @model.solve!
|
130
|
+
x = sol.x.value.to_i
|
131
|
+
y = sol.y.value.to_i
|
132
|
+
z = sol.z.value.to_i
|
133
|
+
(x + y).should equal(z + y)
|
134
|
+
end
|
135
|
+
|
136
|
+
it 'should raise error on invalid right hand sides' do
|
137
|
+
lambda do
|
138
|
+
(@x + @y).must == 'z'
|
139
|
+
end.should raise_error(TypeError)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should raise error if a fixnum is not used in multiplication' do
|
143
|
+
lambda do
|
144
|
+
(@x * @y).must == 0
|
145
|
+
end.should raise_error(TypeError)
|
146
|
+
end
|
147
|
+
|
148
|
+
it 'should raise error if bools are combined with integer variables' do
|
149
|
+
lambda do
|
150
|
+
(@x + @model.int_var).must == 0
|
151
|
+
end.should raise_error(TypeError)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should handle coefficients other than 1' do
|
155
|
+
(@x * 2 + @y).must == 0
|
156
|
+
sol = @model.solve!
|
157
|
+
x = sol.x.value.to_i
|
158
|
+
y = sol.y.value.to_i
|
159
|
+
(2*x + y).should equal(0)
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'should handle addition with constants' do
|
163
|
+
(@y + 1).must == 1
|
164
|
+
sol = @model.solve!
|
165
|
+
y = sol.y.value.to_i
|
166
|
+
(y + 1).should equal(1)
|
167
|
+
end
|
168
|
+
|
169
|
+
it 'should handle subtraction with a constant' do
|
170
|
+
(@x - 1).must == 0
|
171
|
+
sol = @model.solve!
|
172
|
+
x = sol.x.value.to_i
|
173
|
+
(x - 1).should be_zero
|
174
|
+
end
|
175
|
+
|
176
|
+
it 'should handle parenthesis' do
|
177
|
+
(@x - (@y + @z)).must == 1
|
178
|
+
sol = @model.solve!
|
179
|
+
x = sol.x.value.to_i
|
180
|
+
y = sol.y.value.to_i
|
181
|
+
z = sol.z.value.to_i
|
182
|
+
(x - (y + z)).should equal(1)
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should handle multiplication of parenthesis' do
|
186
|
+
(((@x + @y*10)*10 + @z)*10).must == 0
|
187
|
+
sol = @model.solve!
|
188
|
+
x = sol.x.value.to_i
|
189
|
+
y = sol.y.value.to_i
|
190
|
+
z = sol.z.value.to_i
|
191
|
+
(((x + y*10)*10 + z)*10).should equal(0)
|
192
|
+
end
|
193
|
+
|
194
|
+
relations = ['>', '>=', '<', '<=', '==']
|
195
|
+
|
196
|
+
relations.each do |relation|
|
197
|
+
it "should handle #{relation} with constant integers" do
|
198
|
+
(@x + @y).must.send(relation, 1)
|
199
|
+
sol = @model.solve!
|
200
|
+
sol.should_not be_nil
|
201
|
+
(sol.x.value.to_i + sol.y.value.to_i).should.send(relation, 1)
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
relations.each do |relation|
|
206
|
+
it "should handle negated #{relation} with constant integers" do
|
207
|
+
(@x + @y).must_not.send(relation, 1)
|
208
|
+
sol = @model.solve!
|
209
|
+
sol.should_not be_nil
|
210
|
+
(sol.x.value.to_i + sol.y.value.to_i).should_not.send(relation, 1)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end
|
@@ -0,0 +1,117 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../property_helper'
|
2
|
+
|
3
|
+
class BoolEnumSampleProblem < Gecode::Model
|
4
|
+
attr :bools
|
5
|
+
attr :b1
|
6
|
+
attr :b2
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@bools = bool_var_array(4)
|
10
|
+
@b1 = bool_var
|
11
|
+
@b2 = bool_var
|
12
|
+
branch_on @bools
|
13
|
+
branch_on wrap_enum([@b1, @b2])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
# Expects @stub, which contains the started constraint and @compute_result
|
18
|
+
# which computes whether the left hand side is true or not.
|
19
|
+
describe 'bool enum relation constraint', :shared => true do
|
20
|
+
it 'should handle being constrained to be true' do
|
21
|
+
@stub.must_be.true
|
22
|
+
@model.solve!
|
23
|
+
@compute_result.call.should be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'should handle being constrained to be negated true' do
|
27
|
+
@stub.must_not_be.true
|
28
|
+
@model.solve!
|
29
|
+
@compute_result.call.should_not be_true
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'should handle being constrained to be false' do
|
33
|
+
@stub.must_be.false
|
34
|
+
@model.solve!
|
35
|
+
@compute_result.call.should_not be_true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'should handle being constrained to be negated false' do
|
39
|
+
@stub.must_not_be.false
|
40
|
+
@model.solve!
|
41
|
+
@compute_result.call.should be_true
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should handle being constrained to be equal to a variable' do
|
45
|
+
@stub.must_be == @b1
|
46
|
+
@model.solve!
|
47
|
+
@compute_result.call.should == @b1.value
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'should handle being constrained to not be equal to a variable' do
|
51
|
+
@stub.must_not_be == @b1
|
52
|
+
@model.solve!
|
53
|
+
@compute_result.call.should_not == @b1.value
|
54
|
+
end
|
55
|
+
|
56
|
+
it 'should handle being constrained to be equal to be a nested expression' do
|
57
|
+
@stub.must_be == (@b1 | @b2) & @b1
|
58
|
+
@model.solve!
|
59
|
+
@compute_result.call.should == (@b1.value | @b2.value) & @b1.value
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should handle being constrained to not be equal to be a nested expression' do
|
63
|
+
@stub.must_not_be == (@b1 | @b2) & @b1
|
64
|
+
@model.solve!
|
65
|
+
@compute_result.call.should_not == (@b1.value | @b2.value) & @b1.value
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe Gecode::BoolEnum::Relation, ' (conjunction)' do
|
70
|
+
before do
|
71
|
+
@model = BoolEnumSampleProblem.new
|
72
|
+
@bools = @model.bools
|
73
|
+
@b1 = @model.b1
|
74
|
+
@b2 = @model.b2
|
75
|
+
|
76
|
+
# For property spec.
|
77
|
+
@property_types = [:bool_enum]
|
78
|
+
@select_property = lambda do |bool_enum|
|
79
|
+
bool_enum.conjunction
|
80
|
+
end
|
81
|
+
@selected_property = @bools.conjunction
|
82
|
+
@constraint_class = Gecode::BlockConstraint
|
83
|
+
|
84
|
+
# For bool enum spec.
|
85
|
+
@stub = @selected_property
|
86
|
+
@compute_result = lambda{ @bools.all?{ |b| b.value } }
|
87
|
+
end
|
88
|
+
|
89
|
+
it_should_behave_like 'bool enum relation constraint'
|
90
|
+
it_should_behave_like(
|
91
|
+
'property that produces bool operand by short circuiting equality')
|
92
|
+
end
|
93
|
+
|
94
|
+
describe Gecode::BoolEnum::Relation, ' (disjunction)' do
|
95
|
+
before do
|
96
|
+
@model = BoolEnumSampleProblem.new
|
97
|
+
@bools = @model.bools
|
98
|
+
@b1 = @model.b1
|
99
|
+
@b2 = @model.b2
|
100
|
+
|
101
|
+
# For constraint option spec.
|
102
|
+
@property_types = [:bool_enum]
|
103
|
+
@select_property = lambda do |bool_enum|
|
104
|
+
bool_enum.disjunction
|
105
|
+
end
|
106
|
+
@selected_property = @bools.disjunction
|
107
|
+
@constraint_class = Gecode::BlockConstraint
|
108
|
+
|
109
|
+
# For bool enum spec.
|
110
|
+
@stub = @selected_property
|
111
|
+
@compute_result = lambda{ @bools.any?{ |b| b.value } }
|
112
|
+
end
|
113
|
+
|
114
|
+
it_should_behave_like 'bool enum relation constraint'
|
115
|
+
it_should_behave_like(
|
116
|
+
'property that produces bool operand by short circuiting equality')
|
117
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/../constraint_helper'
|
2
|
+
|
3
|
+
class BoolChannelSampleProblem < Gecode::Model
|
4
|
+
attr :bool_enum
|
5
|
+
attr :bool
|
6
|
+
attr :int
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
@bool_enum = bool_var_array(4)
|
10
|
+
@int = int_var(0..3)
|
11
|
+
@bool = bool_var
|
12
|
+
|
13
|
+
branch_on @int
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe Gecode::BoolEnum::Channel, ' (bool enum as lhs with int variable)' do
|
18
|
+
before do
|
19
|
+
@model = BoolChannelSampleProblem.new
|
20
|
+
@bools = @model.bool_enum
|
21
|
+
@int = @model.int
|
22
|
+
|
23
|
+
@types = [:bool_enum, :int]
|
24
|
+
@invoke = lambda do |receiver, int, hash|
|
25
|
+
receiver.channel(int, hash)
|
26
|
+
@model.solve!
|
27
|
+
end
|
28
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
29
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
30
|
+
an_instance_of(Gecode::Raw::Space),
|
31
|
+
var1, var2, 0, *opts)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'should channel the bool enum with the integer variable' do
|
36
|
+
@int.must > 2
|
37
|
+
@bools.must.channel @int
|
38
|
+
@model.solve!.should_not be_nil
|
39
|
+
int_val = @int.value
|
40
|
+
@bools.values.each_with_index do |bool, index|
|
41
|
+
bool.should == (index == int_val)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'should take the offset into account when channeling' do
|
46
|
+
@int.must > 2
|
47
|
+
offset = 1
|
48
|
+
@bools.must.channel(@int, :offset => offset)
|
49
|
+
@model.solve!.should_not be_nil
|
50
|
+
int_val = @int.value
|
51
|
+
@bools.values.each_with_index do |bool, index|
|
52
|
+
bool.should == (index + offset == int_val)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it_should_behave_like 'non-reifiable constraint'
|
57
|
+
it_should_behave_like 'non-negatable constraint'
|
58
|
+
end
|
59
|
+
|
60
|
+
|
61
|
+
describe Gecode::BoolEnum::Channel, ' (int variable as lhs with bool enum)' do
|
62
|
+
before do
|
63
|
+
@model = BoolChannelSampleProblem.new
|
64
|
+
@bools = @model.bool_enum
|
65
|
+
@int = @model.int
|
66
|
+
|
67
|
+
@types = [:int, :bool_enum]
|
68
|
+
@invoke = lambda do |receiver, bool_enum, hash|
|
69
|
+
receiver.channel(bool_enum, hash)
|
70
|
+
@model.solve!
|
71
|
+
end
|
72
|
+
@expect = lambda do |var1, var2, opts, reif_var|
|
73
|
+
Gecode::Raw.should_receive(:channel).once.with(
|
74
|
+
an_instance_of(Gecode::Raw::Space),
|
75
|
+
var2, var1, 0, *opts)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'should channel the bool enum with the integer variable' do
|
80
|
+
@int.must > 2
|
81
|
+
@int.must.channel @bools
|
82
|
+
@model.solve!.should_not be_nil
|
83
|
+
int_val = @int.value
|
84
|
+
@bools.values.each_with_index do |bool, index|
|
85
|
+
bool.should == (index == int_val)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should take the offset into account when channeling' do
|
90
|
+
@int.must > 2
|
91
|
+
offset = 1
|
92
|
+
@int.must.channel(@bools, :offset => offset)
|
93
|
+
@model.solve!.should_not be_nil
|
94
|
+
int_val = @int.value
|
95
|
+
@bools.values.each_with_index do |bool, index|
|
96
|
+
bool.should == (index + offset == int_val)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
it_should_behave_like 'non-reifiable constraint'
|
101
|
+
it_should_behave_like 'non-negatable constraint'
|
102
|
+
end
|