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.
Files changed (203) hide show
  1. data/CHANGES +137 -0
  2. data/COPYING +17 -0
  3. data/LGPL-LICENSE +458 -0
  4. data/README +58 -0
  5. data/Rakefile +14 -0
  6. data/example/equation_system.rb +15 -0
  7. data/example/example_helper.rb +1 -0
  8. data/example/magic_sequence.rb +43 -0
  9. data/example/money.rb +36 -0
  10. data/example/queens.rb +42 -0
  11. data/example/send_more_money.rb +43 -0
  12. data/example/send_most_money.rb +58 -0
  13. data/example/square_tiling.rb +84 -0
  14. data/example/sudoku-set.rb +106 -0
  15. data/example/sudoku.rb +56 -0
  16. data/lib/gecode.dll +0 -0
  17. data/lib/gecoder.rb +5 -0
  18. data/lib/gecoder/bindings.rb +96 -0
  19. data/lib/gecoder/bindings/bindings.rb +2029 -0
  20. data/lib/gecoder/interface.rb +9 -0
  21. data/lib/gecoder/interface/binding_changes.rb +9 -0
  22. data/lib/gecoder/interface/branch.rb +163 -0
  23. data/lib/gecoder/interface/constraints.rb +471 -0
  24. data/lib/gecoder/interface/constraints/bool/boolean.rb +251 -0
  25. data/lib/gecoder/interface/constraints/bool/channel.rb +7 -0
  26. data/lib/gecoder/interface/constraints/bool/linear.rb +200 -0
  27. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +68 -0
  28. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +106 -0
  29. data/lib/gecoder/interface/constraints/bool_enum/relation.rb +55 -0
  30. data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +84 -0
  31. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +155 -0
  32. data/lib/gecoder/interface/constraints/extensional_regexp.rb +101 -0
  33. data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
  34. data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
  35. data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
  36. data/lib/gecoder/interface/constraints/int/arithmetic.rb +150 -0
  37. data/lib/gecoder/interface/constraints/int/channel.rb +51 -0
  38. data/lib/gecoder/interface/constraints/int/domain.rb +80 -0
  39. data/lib/gecoder/interface/constraints/int/linear.rb +143 -0
  40. data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
  41. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +63 -0
  42. data/lib/gecoder/interface/constraints/int_enum/channel.rb +86 -0
  43. data/lib/gecoder/interface/constraints/int_enum/count.rb +66 -0
  44. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +64 -0
  45. data/lib/gecoder/interface/constraints/int_enum/element.rb +64 -0
  46. data/lib/gecoder/interface/constraints/int_enum/equality.rb +37 -0
  47. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +187 -0
  48. data/lib/gecoder/interface/constraints/int_enum/sort.rb +135 -0
  49. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +95 -0
  50. data/lib/gecoder/interface/constraints/int_var_constraints.rb +230 -0
  51. data/lib/gecoder/interface/constraints/reifiable_constraints.rb +78 -0
  52. data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
  53. data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
  54. data/lib/gecoder/interface/constraints/set/cardinality.rb +65 -0
  55. data/lib/gecoder/interface/constraints/set/channel.rb +51 -0
  56. data/lib/gecoder/interface/constraints/set/connection.rb +130 -0
  57. data/lib/gecoder/interface/constraints/set/domain.rb +156 -0
  58. data/lib/gecoder/interface/constraints/set/include.rb +36 -0
  59. data/lib/gecoder/interface/constraints/set/operation.rb +118 -0
  60. data/lib/gecoder/interface/constraints/set/relation.rb +155 -0
  61. data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
  62. data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
  63. data/lib/gecoder/interface/constraints/set_enum/channel.rb +45 -0
  64. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +43 -0
  65. data/lib/gecoder/interface/constraints/set_enum/operation.rb +69 -0
  66. data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
  67. data/lib/gecoder/interface/constraints/set_enum_constraints.rb +84 -0
  68. data/lib/gecoder/interface/constraints/set_var_constraints.rb +243 -0
  69. data/lib/gecoder/interface/enum_matrix.rb +64 -0
  70. data/lib/gecoder/interface/enum_wrapper.rb +205 -0
  71. data/lib/gecoder/interface/model.rb +453 -0
  72. data/lib/gecoder/interface/model_sugar.rb +84 -0
  73. data/lib/gecoder/interface/search.rb +197 -0
  74. data/lib/gecoder/interface/variables.rb +306 -0
  75. data/lib/gecoder/version.rb +4 -0
  76. data/specs/bool_var.rb +81 -0
  77. data/specs/branch.rb +185 -0
  78. data/specs/constraints/bool/boolean.rb +317 -0
  79. data/specs/constraints/bool/boolean_properties.rb +51 -0
  80. data/specs/constraints/bool/linear.rb +213 -0
  81. data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
  82. data/specs/constraints/bool_enum/channel.rb +102 -0
  83. data/specs/constraints/bool_enum/extensional.rb +225 -0
  84. data/specs/constraints/constraint_helper.rb +234 -0
  85. data/specs/constraints/constraint_receivers.rb +103 -0
  86. data/specs/constraints/constraints.rb +26 -0
  87. data/specs/constraints/fixnum_enum/element.rb +58 -0
  88. data/specs/constraints/fixnum_enum/operation.rb +67 -0
  89. data/specs/constraints/int/arithmetic.rb +149 -0
  90. data/specs/constraints/int/channel.rb +101 -0
  91. data/specs/constraints/int/domain.rb +106 -0
  92. data/specs/constraints/int/linear.rb +183 -0
  93. data/specs/constraints/int/linear_properties.rb +97 -0
  94. data/specs/constraints/int/relation.rb +84 -0
  95. data/specs/constraints/int_enum/arithmetic.rb +72 -0
  96. data/specs/constraints/int_enum/channel.rb +57 -0
  97. data/specs/constraints/int_enum/count.rb +72 -0
  98. data/specs/constraints/int_enum/distinct.rb +80 -0
  99. data/specs/constraints/int_enum/element.rb +61 -0
  100. data/specs/constraints/int_enum/equality.rb +29 -0
  101. data/specs/constraints/int_enum/extensional.rb +224 -0
  102. data/specs/constraints/int_enum/sort.rb +167 -0
  103. data/specs/constraints/operands.rb +264 -0
  104. data/specs/constraints/property_helper.rb +443 -0
  105. data/specs/constraints/reification_sugar.rb +69 -0
  106. data/specs/constraints/selected_set/select.rb +56 -0
  107. data/specs/constraints/selected_set/select_properties.rb +157 -0
  108. data/specs/constraints/set/cardinality.rb +58 -0
  109. data/specs/constraints/set/cardinality_properties.rb +46 -0
  110. data/specs/constraints/set/channel.rb +77 -0
  111. data/specs/constraints/set/connection.rb +176 -0
  112. data/specs/constraints/set/domain.rb +197 -0
  113. data/specs/constraints/set/include.rb +36 -0
  114. data/specs/constraints/set/operation.rb +132 -0
  115. data/specs/constraints/set/relation.rb +117 -0
  116. data/specs/constraints/set_elements/relation.rb +84 -0
  117. data/specs/constraints/set_enum/channel.rb +80 -0
  118. data/specs/constraints/set_enum/distinct.rb +59 -0
  119. data/specs/constraints/set_enum/operation.rb +111 -0
  120. data/specs/constraints/set_enum/select.rb +73 -0
  121. data/specs/distribution.rb +14 -0
  122. data/specs/enum_matrix.rb +43 -0
  123. data/specs/enum_wrapper.rb +179 -0
  124. data/specs/examples.rb +17 -0
  125. data/specs/int_var.rb +163 -0
  126. data/specs/logging.rb +24 -0
  127. data/specs/model.rb +325 -0
  128. data/specs/model_sugar.rb +30 -0
  129. data/specs/search.rb +383 -0
  130. data/specs/selected_set.rb +39 -0
  131. data/specs/set_elements.rb +34 -0
  132. data/specs/set_var.rb +82 -0
  133. data/specs/spec_helper.rb +265 -0
  134. data/tasks/all_tasks.rb +1 -0
  135. data/tasks/dependencies.txt +22 -0
  136. data/tasks/distribution.rake +194 -0
  137. data/tasks/rcov.rake +18 -0
  138. data/tasks/specs.rake +21 -0
  139. data/tasks/svn.rake +16 -0
  140. data/tasks/website.rake +51 -0
  141. data/vendor/gecode/win32/lib/libgecodeint.dll +0 -0
  142. data/vendor/gecode/win32/lib/libgecodekernel.dll +0 -0
  143. data/vendor/gecode/win32/lib/libgecodeminimodel.dll +0 -0
  144. data/vendor/gecode/win32/lib/libgecodesearch.dll +0 -0
  145. data/vendor/gecode/win32/lib/libgecodeset.dll +0 -0
  146. data/vendor/gecode/win32/lib/libgecodesupport.dll +0 -0
  147. data/vendor/rust/README +28 -0
  148. data/vendor/rust/bin/cxxgenerator.rb +93 -0
  149. data/vendor/rust/include/rust_checks.hh +116 -0
  150. data/vendor/rust/include/rust_conversions.hh +102 -0
  151. data/vendor/rust/rust.rb +67 -0
  152. data/vendor/rust/rust/attribute.rb +51 -0
  153. data/vendor/rust/rust/bindings.rb +172 -0
  154. data/vendor/rust/rust/class.rb +337 -0
  155. data/vendor/rust/rust/constants.rb +48 -0
  156. data/vendor/rust/rust/container.rb +110 -0
  157. data/vendor/rust/rust/cppifaceparser.rb +129 -0
  158. data/vendor/rust/rust/cwrapper.rb +72 -0
  159. data/vendor/rust/rust/cxxclass.rb +96 -0
  160. data/vendor/rust/rust/element.rb +81 -0
  161. data/vendor/rust/rust/enum.rb +63 -0
  162. data/vendor/rust/rust/function.rb +407 -0
  163. data/vendor/rust/rust/namespace.rb +61 -0
  164. data/vendor/rust/rust/templates/AttributeDefinition.rusttpl +17 -0
  165. data/vendor/rust/rust/templates/AttributeInitBinding.rusttpl +9 -0
  166. data/vendor/rust/rust/templates/BindingsHeader.rusttpl +24 -0
  167. data/vendor/rust/rust/templates/BindingsUnit.rusttpl +46 -0
  168. data/vendor/rust/rust/templates/CWrapperClassDefinitions.rusttpl +64 -0
  169. data/vendor/rust/rust/templates/ClassDeclarations.rusttpl +7 -0
  170. data/vendor/rust/rust/templates/ClassInitialize.rusttpl +6 -0
  171. data/vendor/rust/rust/templates/ConstructorStub.rusttpl +21 -0
  172. data/vendor/rust/rust/templates/CxxClassDefinitions.rusttpl +100 -0
  173. data/vendor/rust/rust/templates/CxxMethodStub.rusttpl +12 -0
  174. data/vendor/rust/rust/templates/CxxStandaloneClassDefinitions.rusttpl +26 -0
  175. data/vendor/rust/rust/templates/EnumDeclarations.rusttpl +3 -0
  176. data/vendor/rust/rust/templates/EnumDefinitions.rusttpl +29 -0
  177. data/vendor/rust/rust/templates/FunctionDefinition.rusttpl +9 -0
  178. data/vendor/rust/rust/templates/FunctionInitAlias.rusttpl +5 -0
  179. data/vendor/rust/rust/templates/FunctionInitBinding.rusttpl +9 -0
  180. data/vendor/rust/rust/templates/MethodInitBinding.rusttpl +9 -0
  181. data/vendor/rust/rust/templates/ModuleDeclarations.rusttpl +3 -0
  182. data/vendor/rust/rust/templates/ModuleDefinitions.rusttpl +3 -0
  183. data/vendor/rust/rust/templates/StandaloneClassDeclarations.rusttpl +7 -0
  184. data/vendor/rust/rust/templates/VariableFunctionCall.rusttpl +14 -0
  185. data/vendor/rust/rust/type.rb +98 -0
  186. data/vendor/rust/test/Makefile +4 -0
  187. data/vendor/rust/test/constants.rb +36 -0
  188. data/vendor/rust/test/cppclass.cc +45 -0
  189. data/vendor/rust/test/cppclass.hh +67 -0
  190. data/vendor/rust/test/cppclass.rb +59 -0
  191. data/vendor/rust/test/cwrapper.c +74 -0
  192. data/vendor/rust/test/cwrapper.h +41 -0
  193. data/vendor/rust/test/cwrapper.rb +56 -0
  194. data/vendor/rust/test/dummyclass.hh +31 -0
  195. data/vendor/rust/test/lib/extension-test.rb +98 -0
  196. data/vendor/rust/test/operators.cc +41 -0
  197. data/vendor/rust/test/operators.hh +39 -0
  198. data/vendor/rust/test/operators.rb +39 -0
  199. data/vendor/rust/test/test-constants.rb +43 -0
  200. data/vendor/rust/test/test-cppclass.rb +82 -0
  201. data/vendor/rust/test/test-cwrapper.rb +80 -0
  202. data/vendor/rust/test/test-operators.rb +42 -0
  203. metadata +393 -0
@@ -0,0 +1,4 @@
1
+ module GecodeR #:nodoc:
2
+ # A string representation of the Gecode/R version.
3
+ VERSION = '0.9.0'
4
+ end
data/specs/bool_var.rb ADDED
@@ -0,0 +1,81 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+ require File.dirname(__FILE__) + '/constraints/property_helper'
3
+
4
+ describe 'non-empty bool variable', :shared => true do
5
+ it 'should give a NoMethodError when calling a method that doesn\'t exist' do
6
+ lambda{ @var.this_method_does_not_exists }.should raise_error(NoMethodError)
7
+ end
8
+ end
9
+
10
+ describe Gecode::BoolVar, '(not assigned)' do
11
+ before do
12
+ @model = Gecode::Model.new
13
+ @operand = @var = @model.bool_var
14
+ end
15
+
16
+ it_should_behave_like 'non-empty bool variable'
17
+
18
+ it 'should not be assigned' do
19
+ @var.should_not be_assigned
20
+ end
21
+
22
+ it "should say that it's not assigned when inspecting" do
23
+ @var.inspect.should include('unassigned')
24
+ end
25
+
26
+ it 'should raise error when trying to access assigned value' do
27
+ lambda{ @var.value }.should raise_error(RuntimeError)
28
+ end
29
+
30
+ it_should_behave_like 'bool var operand'
31
+ end
32
+
33
+ describe Gecode::BoolVar, '(assigned true)' do
34
+ before do
35
+ @model = Gecode::Model.new
36
+ @operand = @var = @model.bool_var
37
+ @var.must_be.true
38
+ @model.solve!
39
+ end
40
+
41
+ it_should_behave_like 'non-empty bool variable'
42
+
43
+ it 'should be assigned' do
44
+ @var.should be_assigned
45
+ end
46
+
47
+ it 'should have valye true' do
48
+ @var.value.should be_true
49
+ end
50
+
51
+ it "should say that it's true when inspecting" do
52
+ @var.inspect.should include('true')
53
+ end
54
+
55
+ it_should_behave_like 'bool var operand'
56
+ end
57
+
58
+ describe Gecode::BoolVar, '(assigned false)' do
59
+ before do
60
+ @model = Gecode::Model.new
61
+ @operand = @var = @model.bool_var
62
+ @var.must_be.false
63
+ @model.solve!
64
+ end
65
+
66
+ it_should_behave_like 'non-empty bool variable'
67
+
68
+ it 'should be assigned' do
69
+ @var.should be_assigned
70
+ end
71
+
72
+ it 'should have value false ' do
73
+ @var.value.should_not be_true
74
+ end
75
+
76
+ it "should say that it's false when inspecting" do
77
+ @var.inspect.should include('false')
78
+ end
79
+
80
+ it_should_behave_like 'bool var operand'
81
+ end
data/specs/branch.rb ADDED
@@ -0,0 +1,185 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ class BranchSampleProblem < Gecode::Model
4
+ attr :vars
5
+ attr :bools
6
+ attr :sets
7
+
8
+ def initialize
9
+ @vars = int_var_array(2, 0..3)
10
+ @sets = set_var_array(2, [], 0..4)
11
+ @bools = bool_var_array(2)
12
+ end
13
+ end
14
+
15
+ describe Gecode::Model, ' (integer branch)' do
16
+ before do
17
+ @model = BranchSampleProblem.new
18
+ @vars = @model.vars
19
+ @bools = @model.bools
20
+ end
21
+
22
+ it 'should default to :none and :min' do
23
+ Gecode::Raw.should_receive(:branch).once.with(
24
+ an_instance_of(Gecode::Raw::Space),
25
+ anything, Gecode::Raw::INT_VAR_NONE, Gecode::Raw::INT_VAL_MIN)
26
+ @model.branch_on @vars
27
+ @model.solve!
28
+ end
29
+
30
+ it 'should ensure that branched int variables are assigned in a solution' do
31
+ @model.branch_on @vars
32
+ @model.solve!.vars.each{ |var| var.should be_assigned }
33
+ end
34
+
35
+ it 'should ensure that branched bool variables are assigned in a solution' do
36
+ @model.branch_on @bools
37
+ @model.solve!.bools.each{ |var| var.should be_assigned }
38
+ end
39
+
40
+ it 'should allow branching on a single integer variable' do
41
+ @model.branch_on @vars.first
42
+ @model.solve!.vars.first.should be_assigned
43
+ end
44
+
45
+ it 'should allow branching on a single boolean variable' do
46
+ @model.branch_on @bools.first
47
+ @model.solve!.bools.first.should be_assigned
48
+ end
49
+
50
+ supported_var_selectors = {
51
+ :none => Gecode::Raw::INT_VAR_NONE,
52
+ :smallest_min => Gecode::Raw::INT_VAR_MIN_MIN,
53
+ :largest_min => Gecode::Raw::INT_VAR_MIN_MAX,
54
+ :smallest_max => Gecode::Raw::INT_VAR_MAX_MIN,
55
+ :largest_max => Gecode::Raw::INT_VAR_MAX_MAX,
56
+ :smallest_size => Gecode::Raw::INT_VAR_SIZE_MIN,
57
+ :largest_size => Gecode::Raw::INT_VAR_SIZE_MAX,
58
+ :smallest_degree => Gecode::Raw::INT_VAR_DEGREE_MIN,
59
+ :largest_degree => Gecode::Raw::INT_VAR_DEGREE_MAX,
60
+ :smallest_min_regret => Gecode::Raw::INT_VAR_REGRET_MIN_MIN,
61
+ :largest_min_regret => Gecode::Raw::INT_VAR_REGRET_MIN_MAX,
62
+ :smallest_max_regret => Gecode::Raw::INT_VAR_REGRET_MAX_MIN,
63
+ :largest_max_regret => Gecode::Raw::INT_VAR_REGRET_MAX_MAX
64
+ }.each_pair do |name, gecode_const|
65
+ it "should support #{name} as variable selection strategy" do
66
+ Gecode::Raw.should_receive(:branch).once.with(
67
+ an_instance_of(Gecode::Raw::Space),
68
+ anything, gecode_const, an_instance_of(Numeric))
69
+ @model.branch_on @vars, :variable => name
70
+ @model.solve!
71
+ end
72
+ end
73
+
74
+ supported_val_selectors = {
75
+ :min => Gecode::Raw::INT_VAL_MIN,
76
+ :med => Gecode::Raw::INT_VAL_MED,
77
+ :max => Gecode::Raw::INT_VAL_MAX,
78
+ :split_min => Gecode::Raw::INT_VAL_SPLIT_MIN,
79
+ :split_max => Gecode::Raw::INT_VAL_SPLIT_MAX
80
+ }.each_pair do |name, gecode_const|
81
+ it "should support #{name} as value selection strategy" do
82
+ Gecode::Raw.should_receive(:branch).once.with(
83
+ an_instance_of(Gecode::Raw::Space),
84
+ anything, an_instance_of(Numeric), gecode_const)
85
+ @model.branch_on @vars, :value => name
86
+ @model.solve!
87
+ end
88
+ end
89
+
90
+ it 'should raise errors for unrecognized var selection strategies' do
91
+ lambda do
92
+ @model.branch_on @vars, :variable => :foo
93
+ end.should raise_error(ArgumentError)
94
+ end
95
+
96
+ it 'should raise errors for unrecognized val selection strategies' do
97
+ lambda do
98
+ @model.branch_on @vars, :value => :foo
99
+ end.should raise_error(ArgumentError)
100
+ end
101
+
102
+ it 'should raise errors for unrecognized options' do
103
+ lambda do
104
+ @model.branch_on @vars, :foo => 5
105
+ end.should raise_error(ArgumentError)
106
+ end
107
+
108
+ it 'should raise errors for unrecognized enumerations' do
109
+ lambda do
110
+ @model.branch_on [1,2,3]
111
+ end.should raise_error(TypeError)
112
+ end
113
+ end
114
+
115
+ describe Gecode::Model, ' (set branch)' do
116
+ before do
117
+ @model = BranchSampleProblem.new
118
+ @sets = @model.sets
119
+ end
120
+
121
+ it 'should default to :none and :min' do
122
+ Gecode::Raw.should_receive(:branch).once.with(
123
+ an_instance_of(Gecode::Raw::Space),
124
+ anything, Gecode::Raw::SET_VAR_NONE, Gecode::Raw::SET_VAL_MIN)
125
+ @model.branch_on @sets
126
+ @model.solve!
127
+ end
128
+
129
+ it 'should ensure that branched set variables are assigned in a solution' do
130
+ @model.branch_on @sets
131
+ @model.solve!.sets.each{ |var| var.should be_assigned }
132
+ end
133
+
134
+ it 'should allow branching on a single set variable' do
135
+ @model.branch_on @sets.first
136
+ @model.solve!.sets.first.should be_assigned
137
+ end
138
+
139
+ supported_var_selectors = {
140
+ :none => Gecode::Raw::SET_VAR_NONE,
141
+ :smallest_cardinality => Gecode::Raw::SET_VAR_MIN_CARD,
142
+ :largest_cardinality => Gecode::Raw::SET_VAR_MAX_CARD,
143
+ :smallest_unknown => Gecode::Raw::SET_VAR_MIN_UNKNOWN_ELEM,
144
+ :largest_unknown => Gecode::Raw::SET_VAR_MAX_UNKNOWN_ELEM
145
+ }.each_pair do |name, gecode_const|
146
+ it "should support #{name} as variable selection strategy" do
147
+ Gecode::Raw.should_receive(:branch).once.with(
148
+ an_instance_of(Gecode::Raw::Space),
149
+ anything, gecode_const, an_instance_of(Numeric))
150
+ @model.branch_on @sets, :variable => name
151
+ @model.solve!
152
+ end
153
+ end
154
+
155
+ supported_val_selectors = {
156
+ :min => Gecode::Raw::SET_VAL_MIN,
157
+ :max => Gecode::Raw::SET_VAL_MAX
158
+ }.each_pair do |name, gecode_const|
159
+ it "should support #{name} as value selection strategy" do
160
+ Gecode::Raw.should_receive(:branch).once.with(
161
+ an_instance_of(Gecode::Raw::Space),
162
+ anything, an_instance_of(Numeric), gecode_const)
163
+ @model.branch_on @sets, :value => name
164
+ @model.solve!
165
+ end
166
+ end
167
+
168
+ it 'should raise errors for unrecognized var selection strategies' do
169
+ lambda do
170
+ @model.branch_on @sets, :variable => :foo
171
+ end.should raise_error(ArgumentError)
172
+ end
173
+
174
+ it 'should raise errors for unrecognized val selection strategies' do
175
+ lambda do
176
+ @model.branch_on @sets, :value => :foo
177
+ end.should raise_error(ArgumentError)
178
+ end
179
+
180
+ it 'should raise errors for unrecognized options' do
181
+ lambda do
182
+ @model.branch_on @sets, :foo => 5
183
+ end.should raise_error(ArgumentError)
184
+ end
185
+ end
@@ -0,0 +1,317 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ class BoolSampleProblem < Gecode::Model
4
+ attr :b1
5
+ attr :b2
6
+ attr :b3
7
+
8
+ def initialize
9
+ @b1 = self.bool_var
10
+ @b2 = self.bool_var
11
+ @b3 = self.bool_var
12
+ end
13
+ end
14
+
15
+ [:true, :false].each do |type|
16
+ describe Gecode::Bool, " (must be #{type})" do
17
+ before do
18
+ @model = Gecode::Model.new
19
+ @bool = @model.bool_var
20
+
21
+ @types = [:bool]
22
+ @invoke = lambda do |receiver, hash|
23
+ receiver.method(type).call(hash)
24
+ @model.solve!
25
+ end
26
+ @expect = lambda do |var, opts, reif_var|
27
+ # We only test the non-MiniModel parts.
28
+ unless reif_var.nil?
29
+ Gecode::Raw.should_receive(:rel).once.with(
30
+ an_instance_of(Gecode::Raw::Space),
31
+ an_instance_of(Gecode::Raw::BoolVar),
32
+ (type == :true) ? Gecode::Raw::IRT_EQ : Gecode::Raw::IRT_NQ,
33
+ reif_var, *opts)
34
+ end
35
+ end
36
+ end
37
+
38
+ it "should constrain variables to be #{type}" do
39
+ @bool.must.method(type).call
40
+ @model.solve!
41
+ @bool.value.should == (type == :true)
42
+ end
43
+
44
+ it "should make negation constrain variables to not be #{type}" do
45
+ @bool.must_not.method(type).call
46
+ @model.solve!
47
+ @bool.value.should == (type != :true)
48
+ end
49
+
50
+ it_should_behave_like 'reifiable constraint'
51
+ end
52
+ end
53
+
54
+ describe Gecode::Bool, " (implies)" do
55
+ before do
56
+ @model = Gecode::Model.new
57
+ @b1 = @model.bool_var
58
+ @b2 = @model.bool_var
59
+ @model.branch_on @model.wrap_enum([@b1, @b2])
60
+
61
+ @types = [:bool, :bool]
62
+ @invoke = lambda do |receiver, op, hash|
63
+ receiver.imply(op, hash)
64
+ @model.solve!
65
+ end
66
+ @expect = lambda do |var1, var2, opts, reif_var|
67
+ end
68
+ end
69
+
70
+ it "should constrain variables to imply each other" do
71
+ @b1.must.imply @b2
72
+ @model.solve!
73
+ (!@b1.value || @b2.value).should be_true
74
+ end
75
+
76
+ it "should, when negated, constrain variables to not imply each other" do
77
+ @b1.must_not.imply @b2
78
+ @model.solve!
79
+ @b1.value.should be_true
80
+ @b2.value.should_not be_true
81
+ end
82
+
83
+ it_should_behave_like 'reifiable constraint'
84
+ end
85
+
86
+ describe Gecode::Bool, " (equality)" do
87
+ before do
88
+ @model = Gecode::Model.new
89
+ @b1 = @model.bool_var
90
+ @b2 = @model.bool_var
91
+ @model.branch_on @model.wrap_enum([@b1, @b2])
92
+
93
+ @types = [:bool, :bool]
94
+ @invoke = lambda do |receiver, op, hash|
95
+ receiver.equal(op, hash)
96
+ @model.solve!
97
+ end
98
+ @expect = lambda do |var1, var2, opts, reif_var|
99
+ end
100
+ end
101
+
102
+ it "should constrain variables to equal each other" do
103
+ @b1.must == @b2
104
+ @model.solve!
105
+ @b1.value.should == @b2.value
106
+ end
107
+
108
+ it "should, when negated, constrain variables to not equal each other" do
109
+ @b1.must_not == @b2
110
+ @model.solve!
111
+ @b1.value.should_not == @b2.value
112
+ end
113
+
114
+ it_should_behave_like 'reifiable constraint'
115
+ end
116
+
117
+ describe Gecode::Bool do
118
+ before do
119
+ @model = BoolSampleProblem.new
120
+ @b1 = @model.b1
121
+ @b2 = @model.b2
122
+ @b3 = @model.b3
123
+ end
124
+
125
+ it 'should handle single variables constrainted to be true' do
126
+ @b1.must_be.true
127
+ b1 = @model.solve!.b1
128
+ b1.should be_assigned
129
+ b1.value.should be_true
130
+ end
131
+
132
+ it 'should handle single variables constrainted to be false' do
133
+ @b1.must_be.false
134
+ b1 = @model.solve!.b1
135
+ b1.should be_assigned
136
+ b1.value.should_not be_true
137
+ end
138
+
139
+ it 'should handle single variables constrainted not to be false' do
140
+ @b1.must_not_be.false
141
+ b1 = @model.solve!.b1
142
+ b1.should be_assigned
143
+ b1.value.should be_true
144
+ end
145
+
146
+ it 'should handle single variables constrainted not to be true' do
147
+ @b1.must_not_be.true
148
+ b1 = @model.solve!.b1
149
+ b1.should be_assigned
150
+ b1.value.should_not be_true
151
+ end
152
+
153
+ it 'should handle disjunction' do
154
+ @b1.must_be.false
155
+ (@b1 | @b2).must_be.true
156
+ sol = @model.solve!
157
+ sol.b1.value.should_not be_true
158
+ sol.b2.value.should be_true
159
+ end
160
+
161
+ it 'should handle negated disjunction' do
162
+ @b1.must_be.false
163
+ (@b1 | @b2).must_not_be.true
164
+ sol = @model.solve!
165
+ sol.b1.value.should_not be_true
166
+ sol.b2.value.should_not be_true
167
+ end
168
+
169
+ it 'should handle conjunction' do
170
+ (@b1 & @b2).must_be.true
171
+ sol = @model.solve!
172
+ sol.b1.value.should be_true
173
+ sol.b2.value.should be_true
174
+ end
175
+
176
+ it 'should handle negated conjunction' do
177
+ @b1.must_be.true
178
+ (@b1 & @b2).must_not_be.true
179
+ sol = @model.solve!
180
+ sol.b1.value.should be_true
181
+ sol.b2.value.should_not be_true
182
+ end
183
+
184
+ it 'should handle exclusive or' do
185
+ @b1.must_be.false
186
+ (@b1 ^ @b2).must_be.true
187
+ sol = @model.solve!
188
+ sol.b1.value.should_not be_true
189
+ sol.b2.value.should be_true
190
+ end
191
+
192
+ it 'should handle negated exclusive or' do
193
+ @b1.must_be.true
194
+ (@b1 ^ @b2).must_not_be.true
195
+ sol = @model.solve!
196
+ sol.b1.value.should be_true
197
+ sol.b2.value.should be_true
198
+ end
199
+
200
+ it 'should handle implication' do
201
+ @b2.must_be.false
202
+ (@b1.implies @b2).must_be.true
203
+ sol = @model.solve!
204
+ sol.b1.value.should_not be_true
205
+ sol.b2.value.should_not be_true
206
+ end
207
+
208
+ it 'should handle negated implication' do
209
+ @b1.must_be.true
210
+ ((@b1 | @b2).implies @b2).must_not_be.true
211
+ sol = @model.solve!
212
+ sol.b1.value.should be_true
213
+ sol.b2.value.should_not be_true
214
+ end
215
+
216
+ it 'should handle imply after must' do
217
+ @b2.must_be.false
218
+ @b1.must.imply @b2
219
+ sol = @model.solve!
220
+ sol.b1.value.should_not be_true
221
+ sol.b2.value.should_not be_true
222
+ end
223
+
224
+ it 'should handle imply after must_not' do
225
+ @b1.must_be.true
226
+ @b1.must_not.imply @b2
227
+ sol = @model.solve!
228
+ sol.b1.value.should be_true
229
+ sol.b2.value.should_not be_true
230
+ end
231
+
232
+ it 'should handle single variables as right hand side' do
233
+ @b1.must == @b2
234
+ @b2.must_be.false
235
+ sol = @model.solve!
236
+ sol.b1.value.should_not be_true
237
+ sol.b2.value.should_not be_true
238
+ end
239
+
240
+ it 'should handle single variables with negation as right hand side' do
241
+ @b1.must_not == @b2
242
+ @b2.must_be.false
243
+ sol = @model.solve!
244
+ sol.b1.value.should be_true
245
+ sol.b2.value.should_not be_true
246
+ end
247
+
248
+ it 'should handle expressions as right hand side' do
249
+ @b1.must == (@b2 | @b3)
250
+ @b2.must_be.true
251
+ sol = @model.solve!
252
+ sol.b1.value.should be_true
253
+ sol.b2.value.should be_true
254
+ end
255
+
256
+ it 'should handle nested expressions as left hand side' do
257
+ ((@b1 & @b2) | @b3 | (@b1 & @b3)).must_be.true
258
+ @b1.must_be.false
259
+ sol = @model.solve!
260
+ sol.b1.value.should_not be_true
261
+ sol.b3.value.should be_true
262
+ end
263
+
264
+ it 'should handle nested expressions on both side' do
265
+ ((@b1 & @b1) | @b3).must == ((@b1 & @b3) & @b2)
266
+ @b1.must_be.true
267
+ sol = @model.solve!
268
+ sol.b1.value.should be_true
269
+ sol.b2.value.should be_true
270
+ sol.b3.value.should be_true
271
+ end
272
+
273
+ it 'should handle nested expressions with implication' do
274
+ ((@b1 & @b1) | @b3).must.imply(@b1 ^ @b2)
275
+ @b1.must_be.true
276
+ sol = @model.solve!
277
+ sol.b1.value.should be_true
278
+ sol.b2.value.should be_false
279
+ end
280
+
281
+ it 'should handle nested expressions containing exclusive or' do
282
+ ((@b1 ^ @b1) & @b3).must == ((@b2 | @b3) ^ @b2)
283
+ @b1.must_be.true
284
+ @b2.must_be.false
285
+ sol = @model.solve!
286
+ sol.b1.value.should be_true
287
+ sol.b2.value.should_not be_true
288
+ sol.b3.value.should_not be_true
289
+ end
290
+
291
+ it 'should handle nested expressions on both sides with negation' do
292
+ ((@b1 & @b1) | @b3).must_not == ((@b1 | @b3) & @b2)
293
+ @b1.must_be.true
294
+ @b3.must_be.true
295
+ sol = @model.solve!
296
+ sol.b1.value.should be_true
297
+ sol.b2.value.should_not be_true
298
+ sol.b3.value.should be_true
299
+ end
300
+
301
+ it 'should translate reification with a variable right hand side' do
302
+ @b1.must_be.equal_to(@b2, :reify => @b3)
303
+ @b1.must_be.true
304
+ @b2.must_be.false
305
+ sol = @model.solve!
306
+ sol.b3.value.should_not be_true
307
+ end
308
+
309
+ it 'should translate reification with a variable right hand side and negation' do
310
+ @b1.must_not_be.equal_to(@b2, :reify => @b3)
311
+ @b1.must_be.true
312
+ @b2.must_be.false
313
+ sol = @model.solve!
314
+ sol.b3.value.should be_true
315
+ end
316
+ end
317
+