gecoder-with-gecode 0.9.0-x86-mswin32-60

Sign up to get free protection for your applications and to get access to all the features.
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,106 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ describe Gecode::Int::Domain, ' (non-range)' do
4
+ before do
5
+ @model = Gecode::Model.new
6
+ @domain = 0..3
7
+ @x = @model.int_var(@domain)
8
+ @non_range_domain = [1, 3]
9
+
10
+ @types = [:int]
11
+ @invoke = lambda do |receiver, hash|
12
+ receiver.in(@non_range_domain, hash)
13
+ @model.solve!
14
+ end
15
+ @expect = lambda do |var, opts, reif_var|
16
+ if reif_var.nil?
17
+ Gecode::Raw.should_receive(:dom).once.with(
18
+ an_instance_of(Gecode::Raw::Space),
19
+ var, an_instance_of(Gecode::Raw::IntSet),
20
+ *opts)
21
+ else
22
+ Gecode::Raw.should_receive(:dom).once.with(
23
+ an_instance_of(Gecode::Raw::Space),
24
+ var, an_instance_of(Gecode::Raw::IntSet),
25
+ reif_var, *opts)
26
+ end
27
+ end
28
+ end
29
+
30
+ it 'should constrain the domain of the variable' do
31
+ @x.must_be.in @non_range_domain
32
+ @model.solve!
33
+
34
+ @x.should have_domain(@non_range_domain)
35
+ end
36
+
37
+ it 'should handle negation' do
38
+ @x.must_not_be.in @non_range_domain
39
+ @model.solve!
40
+
41
+ @x.should have_domain(@domain.to_a - @non_range_domain.to_a)
42
+ end
43
+
44
+ it_should_behave_like 'reifiable constraint'
45
+ end
46
+
47
+ describe Gecode::Int::Domain, ' (range)' do
48
+ before do
49
+ @model = Gecode::Model.new
50
+ @domain = 0..3
51
+ @operand = @x = @model.int_var(@domain)
52
+ @range_domain = 1..2
53
+ @three_dot_range_domain = 1...2
54
+
55
+ @types = [:int]
56
+ @invoke = lambda do |receiver, hash|
57
+ receiver.in(@range_domain, hash)
58
+ @model.solve!
59
+ end
60
+ @expect = lambda do |var, opts, reif_var|
61
+ @model.allow_space_access do
62
+ if reif_var.nil?
63
+ Gecode::Raw.should_receive(:dom).once.with(
64
+ an_instance_of(Gecode::Raw::Space),
65
+ var, @range_domain.first, @range_domain.last,
66
+ *opts)
67
+ else
68
+ Gecode::Raw.should_receive(:dom).once.with(
69
+ an_instance_of(Gecode::Raw::Space),
70
+ var, @range_domain.first, @range_domain.last,
71
+ reif_var, *opts)
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ it 'should constrain the domain of the variable' do
78
+ @x.must_be.in @range_domain
79
+ @model.solve!
80
+
81
+ @x.should have_domain(@range_domain)
82
+ end
83
+
84
+ it 'should handle negation' do
85
+ @x.must_not_be.in @range_domain
86
+ @model.solve!
87
+
88
+ @x.should have_domain(@domain.to_a - @range_domain.to_a)
89
+ end
90
+
91
+ it 'should treat three dot ranges correctly' do
92
+ @x.must_be.in @three_dot_range_domain
93
+ @model.solve!
94
+
95
+ @x.should have_domain(@three_dot_range_domain)
96
+ end
97
+
98
+ it 'should handle three dot range with negation' do
99
+ @x.must_not_be.in @three_dot_range_domain
100
+ @model.solve!
101
+
102
+ @x.should have_domain(@domain.to_a - @three_dot_range_domain.to_a)
103
+ end
104
+
105
+ it_should_behave_like 'reifiable constraint'
106
+ end
@@ -0,0 +1,183 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ # This is neither an operand or a constraint spec. It is mostly a sanity
4
+ # check.
5
+
6
+ class LinearSampleProblem < Gecode::Model
7
+ attr :x
8
+ attr :y
9
+ attr :z
10
+
11
+ def initialize(x_dom, y_dom, z_dom)
12
+ @x = self.int_var(x_dom)
13
+ @y = self.int_var(y_dom)
14
+ @z = self.int_var(z_dom)
15
+ branch_on wrap_enum([@x, @y, @z])
16
+ end
17
+ end
18
+
19
+ describe Gecode::Int::Linear do
20
+ before do
21
+ @x_dom = 0..2
22
+ @y_dom = -3..3
23
+ @z_dom = 0..10
24
+ @model = LinearSampleProblem.new(@x_dom, @y_dom, @z_dom)
25
+ @x = @model.x
26
+ @y = @model.y
27
+ @z = @model.z
28
+ @operand = @x + @y
29
+ end
30
+
31
+ it 'should handle addition with a variable' do
32
+ (@x + @y).must == 0
33
+ sol = @model.solve!
34
+ x = sol.x.value
35
+ y = sol.y.value
36
+ (x + y).should be_zero
37
+ end
38
+
39
+ it 'should handle reification (1)' do
40
+ bool = @model.bool_var
41
+ (@x + @y).must.equal(0, :reify => bool)
42
+ bool.must_be.false
43
+ sol = @model.solve!
44
+ x = sol.x.value
45
+ y = sol.y.value
46
+ (x + y).should_not be_zero
47
+ end
48
+
49
+ it 'should handle reification (2)' do
50
+ bool = @model.bool_var
51
+ (@x + @y).must.equal(0, :reify => bool)
52
+ bool.must_be.true
53
+ sol = @model.solve!
54
+ x = sol.x.value
55
+ y = sol.y.value
56
+ (x + y).should be_zero
57
+ end
58
+
59
+ it 'should handle addition with multiple variables' do
60
+ (@x + @y + @z).must == 0
61
+ sol = @model.solve!
62
+ x = sol.x.value
63
+ y = sol.y.value
64
+ z = sol.z.value
65
+ (x + y + z).should be_zero
66
+ end
67
+
68
+ it 'should handle subtraction with a variable' do
69
+ (@x - @y).must == 0
70
+ sol = @model.solve!
71
+ x = sol.x.value
72
+ y = sol.y.value
73
+ (x - y).should be_zero
74
+ end
75
+
76
+ it 'should handle non-zero constants as right hand side' do
77
+ (@x + @y).must == 1
78
+ sol = @model.solve!
79
+ x = sol.x.value
80
+ y = sol.y.value
81
+ (x + y).should equal(1)
82
+ end
83
+
84
+ it 'should handle variables as right hand side' do
85
+ (@x + @y).must == @z
86
+ sol = @model.solve!
87
+ x = sol.x.value
88
+ y = sol.y.value
89
+ z = sol.z.value
90
+ (x + y).should equal(z)
91
+ end
92
+
93
+ it 'should handle linear expressions as right hand side' do
94
+ (@x + @y).must == @z + @y
95
+ sol = @model.solve!
96
+ x = sol.x.value
97
+ y = sol.y.value
98
+ z = sol.z.value
99
+ (x + y).should equal(z + y)
100
+ end
101
+
102
+ it 'should handle linear expressions as right hand side with variable as left hand side' do
103
+ @x.must == @z + @y
104
+ sol = @model.solve!
105
+ x = sol.x.value
106
+ y = sol.y.value
107
+ z = sol.z.value
108
+ x.should equal(z + y)
109
+ end
110
+
111
+ it 'should raise error on invalid right hand sides' do
112
+ lambda{ ((@x + @y).must == 'z') }.should raise_error(TypeError)
113
+ end
114
+
115
+ it 'should handle coefficients other than 1' do
116
+ (@x * 2 + @y).must == 0
117
+ sol = @model.solve!
118
+ x = sol.x.value
119
+ y = sol.y.value
120
+ (2*x + y).should equal(0)
121
+ end
122
+
123
+ it 'should handle addition with constants' do
124
+ (@y + 2).must == 1
125
+ sol = @model.solve!
126
+ y = sol.y.value
127
+ (y + 2).should equal(1)
128
+ end
129
+
130
+ it 'should handle subtraction with a constant' do
131
+ (@x - 2).must == 0
132
+ sol = @model.solve!
133
+ x = sol.x.value
134
+ (x - 2).should be_zero
135
+ end
136
+
137
+ it 'should a single variable as left hande side' do
138
+ @x.must == @y + @z
139
+ sol = @model.solve!
140
+ x = sol.x.value
141
+ y = sol.y.value
142
+ z = sol.z.value
143
+ x.should equal(y + z)
144
+ end
145
+
146
+ it 'should handle parenthesis' do
147
+ (@x - (@y + @z)).must == 1
148
+ sol = @model.solve!
149
+ x = sol.x.value
150
+ y = sol.y.value
151
+ z = sol.z.value
152
+ (x - (y + z)).should equal(1)
153
+ end
154
+
155
+ it 'should handle multiplication of parenthesis' do
156
+ (((@x + @y*10)*10 + @z)*10).must == 0
157
+ sol = @model.solve!
158
+ x = sol.x.value
159
+ y = sol.y.value
160
+ z = sol.z.value
161
+ (((x + y*10)*10 + z)*10).should equal(0)
162
+ end
163
+
164
+ relations = ['>', '>=', '<', '<=', '==']
165
+
166
+ relations.each do |relation|
167
+ it "should handle #{relation} with constant integers" do
168
+ (@x + @y).must.send(relation, 1)
169
+ sol = @model.solve!
170
+ sol.should_not be_nil
171
+ (sol.x.value + sol.y.value).should.send(relation, 1)
172
+ end
173
+ end
174
+
175
+ relations.each do |relation|
176
+ it "should handle negated #{relation} with constant integers" do
177
+ (@x + @y).must_not.send(relation, 1)
178
+ sol = @model.solve!
179
+ sol.should_not be_nil
180
+ (sol.x.value + sol.y.value).should_not.send(relation, 1)
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,97 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ class LinearPropertySampleProblem < Gecode::Model
4
+ attr :x
5
+ attr :y
6
+ attr :z
7
+
8
+ def initialize
9
+ @x = self.int_var(0..2)
10
+ @y = self.int_var(-3..3)
11
+ @z = self.int_var(0..10)
12
+ branch_on wrap_enum([@x, @y, @z])
13
+ end
14
+ end
15
+
16
+ describe Gecode::Int::Linear, ' (+ property)' do
17
+ before do
18
+ @model = LinearPropertySampleProblem.new
19
+ @x = @model.x
20
+ @y = @model.y
21
+ @z = @model.z
22
+
23
+ # For int operand producing property spec.
24
+ @property_types = [:int, :int]
25
+ @select_property = lambda do |int1, int2|
26
+ int1 + int2
27
+ end
28
+ @selected_property = @x + @y
29
+ @constraint_class =
30
+ Gecode::Int::Linear::LinearRelationConstraint
31
+ end
32
+
33
+ it 'should constrain the sum' do
34
+ (@x + @y).must == 5
35
+ @model.solve!
36
+ (@x.value + @y.value).should == 5
37
+ end
38
+
39
+ it_should_behave_like(
40
+ 'property that produces int operand by short circuiting relations')
41
+ end
42
+
43
+ describe Gecode::Int::Linear, ' (- property)' do
44
+ before do
45
+ @model = LinearPropertySampleProblem.new
46
+ @x = @model.x
47
+ @y = @model.y
48
+ @z = @model.z
49
+
50
+ # For int operand producing property spec.
51
+ @property_types = [:int, :int]
52
+ @select_property = lambda do |int1, int2|
53
+ int1 - int2
54
+ end
55
+ @selected_property = @x - @y
56
+ @constraint_class =
57
+ Gecode::Int::Linear::LinearRelationConstraint
58
+ end
59
+
60
+ it 'should constrain the difference' do
61
+ (@x - @y).must == 1
62
+ @model.solve!
63
+ (@x.value - @y.value).should == 1
64
+ end
65
+
66
+ it_should_behave_like(
67
+ 'property that produces int operand by short circuiting relations')
68
+ end
69
+
70
+ describe Gecode::Int::Linear, ' (* property)' do
71
+ before do
72
+ @model = LinearPropertySampleProblem.new
73
+ @x = @model.x
74
+ @y = @model.y
75
+ @z = @model.z
76
+
77
+ # For int operand producing property spec.
78
+ @property_types = [:int]
79
+ @select_property = lambda do |int|
80
+ int * 17
81
+ end
82
+ @selected_property = @x * 2
83
+ @constraint_class =
84
+ Gecode::Int::Linear::LinearRelationConstraint
85
+ end
86
+
87
+ it 'should constrain the value times a constant' do
88
+ (@x * 2).must == 4
89
+ @model.solve!
90
+ (@x.value * 2).should == 4
91
+ end
92
+
93
+ it_should_behave_like(
94
+ 'property that produces int operand by short circuiting relations')
95
+ end
96
+
97
+
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
4
+ describe Gecode::Int::Relation, " (#{relation} with int op)" do
5
+ before do
6
+ @model = Gecode::Model.new
7
+
8
+ # For constraint spec.
9
+ @types = [:int, :int]
10
+ @invoke = lambda do |receiver, op, hash|
11
+ receiver.method(relation).call(op, hash)
12
+ @model.solve!
13
+ end
14
+ @expect = lambda do |var1, var2, opts, reif_var|
15
+ if reif_var.nil?
16
+ Gecode::Raw.should_receive(:rel).once.with(
17
+ an_instance_of(Gecode::Raw::Space),
18
+ var1, rel_value, var2, *opts)
19
+ else
20
+ Gecode::Raw.should_receive(:rel).once.with(
21
+ an_instance_of(Gecode::Raw::Space),
22
+ var1, rel_value, var2, reif_var, *opts)
23
+ end
24
+ end
25
+ end
26
+
27
+ it "should constrain the #{relation} with an int operand" do
28
+ ints = @model.int_var_array(2, -5..5)
29
+ @model.branch_on ints
30
+ int1, int2 = ints
31
+ int1.must.method(relation).call(int2)
32
+ @model.solve!
33
+ int1.value.should.method(relation).call(int2.value)
34
+ end
35
+
36
+ it "should constrain the negated #{relation} with an int operand" do
37
+ ints = @model.int_var_array(2, -5..5)
38
+ @model.branch_on ints
39
+ int1, int2 = ints
40
+ int1.must_not.method(relation).call(int2)
41
+ @model.solve!
42
+ int1.value.should_not.method(relation).call(int2.value)
43
+ end
44
+
45
+ it_should_behave_like 'reifiable constraint'
46
+ end
47
+ end
48
+
49
+ Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
50
+ describe Gecode::Int::Relation, " (#{relation} with fixnum)" do
51
+ before do
52
+ @model = Gecode::Model.new
53
+
54
+ # For constraint spec.
55
+ @types = [:int]
56
+ @invoke = lambda do |receiver, hash|
57
+ receiver.method(relation).call(17, hash)
58
+ @model.solve!
59
+ end
60
+ @expect = lambda do |var, opts, reif_var|
61
+ if reif_var.nil?
62
+ Gecode::Raw.should_receive(:rel).once.with(
63
+ an_instance_of(Gecode::Raw::Space),
64
+ var, rel_value, 17, *opts)
65
+ else
66
+ Gecode::Raw.should_receive(:rel).once.with(
67
+ an_instance_of(Gecode::Raw::Space),
68
+ var, rel_value, 17, reif_var, *opts)
69
+ end
70
+ end
71
+ end
72
+
73
+ it "should constrain the #{relation} with a fixnum" do
74
+ int = @model.int_var(-5..5)
75
+ @model.branch_on int
76
+ int.must.method(relation).call(3)
77
+ @model.solve!
78
+ int.value.should.method(relation).call(3)
79
+ end
80
+
81
+ it_should_behave_like 'reifiable constraint'
82
+ end
83
+ end
84
+