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,176 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ describe Gecode::Set::Connection, ' (min)' do
4
+ before do
5
+ @model = Gecode::Model.new
6
+ @set = @model.set_var([], 0..9)
7
+ @var = @model.int_var(0..10)
8
+ @model.branch_on @model.wrap_enum([@set])
9
+
10
+ @property_types = [:set]
11
+ @select_property = lambda do |set|
12
+ set.min
13
+ end
14
+ @selected_property = @set.min
15
+ @constraint_class = Gecode::BlockConstraint
16
+ end
17
+
18
+ it 'should constrain the min of a set' do
19
+ @set.min.must == 3
20
+ @model.solve!
21
+ @set.lower_bound.min.should == 3
22
+ end
23
+
24
+ it 'should translate into a min constraint' do
25
+ Gecode::Raw.should_receive(:min)
26
+ @set.min.must == 5
27
+ @model.solve!
28
+ end
29
+
30
+ it_should_behave_like(
31
+ 'property that produces int operand by short circuiting equality')
32
+ end
33
+
34
+ describe Gecode::Set::Connection, ' (max)' do
35
+ before do
36
+ @model = Gecode::Model.new
37
+ @set = @model.set_var([], 0..9)
38
+ @var = @model.int_var(0..10)
39
+ @model.branch_on @model.wrap_enum([@set])
40
+
41
+ @property_types = [:set]
42
+ @select_property = lambda do |set|
43
+ set.max
44
+ end
45
+ @selected_property = @set.max
46
+ @constraint_class = Gecode::BlockConstraint
47
+ end
48
+
49
+ it 'should constrain the max of a set' do
50
+ @set.max.must == 3
51
+ @model.solve!
52
+ @set.lower_bound.max.should == 3
53
+ end
54
+
55
+ it 'should translate into a max constraint' do
56
+ Gecode::Raw.should_receive(:max)
57
+ @set.max.must == 5
58
+ @model.solve!
59
+ end
60
+
61
+ it_should_behave_like(
62
+ 'property that produces int operand by short circuiting equality')
63
+ end
64
+
65
+ describe Gecode::Set::Connection, ' (sum)' do
66
+ before do
67
+ @model = Gecode::Model.new
68
+ @set = @model.set_var([], 0..9)
69
+ @target = @var = @model.int_var(0..20)
70
+ @model.branch_on @model.wrap_enum([@set])
71
+
72
+ @property_types = [:set]
73
+ @select_property = lambda do |set|
74
+ set.sum
75
+ end
76
+ @selected_property = @set.sum
77
+ @constraint_class = Gecode::BlockConstraint
78
+ end
79
+
80
+ it 'should constrain the sum of a set' do
81
+ @set.sum.must == 7
82
+ @model.solve!.should_not be_nil
83
+ @set.value.inject(0){ |x, y| x + y }.should == 7
84
+ end
85
+
86
+ it 'should translate into a weights constraint' do
87
+ Gecode::Raw.should_receive(:weights)
88
+ @set.sum.must == 5
89
+ @model.solve!
90
+ end
91
+
92
+ it 'should raise error if unsupported options is given' do
93
+ lambda do
94
+ @set.sum(:does_not_exist => :foo).must == @var
95
+ end.should raise_error(ArgumentError)
96
+ end
97
+
98
+ it 'should raise error if multiple options are given' do
99
+ lambda do
100
+ @set.sum(:weights => {}, :substitutions => {}).must == @var
101
+ end.should raise_error(ArgumentError)
102
+ end
103
+
104
+ it_should_behave_like(
105
+ 'property that produces int operand by short circuiting equality')
106
+ end
107
+
108
+ describe Gecode::Set::Connection, ' (sum with weights)' do
109
+ before do
110
+ @model = Gecode::Model.new
111
+ @set = @model.set_var([], 0..9)
112
+ @target = @var = @model.int_var(-20..20)
113
+ @model.branch_on @model.wrap_enum([@set])
114
+ @weights = Hash[*(0..9).zip((-9..-0).to_a.reverse).flatten]
115
+
116
+ @property_types = [:set]
117
+ @select_property = lambda do |set|
118
+ set.sum(:weights => @weights)
119
+ end
120
+ @selected_property = @set.sum(:weights => @weights)
121
+ @constraint_class = Gecode::BlockConstraint
122
+ end
123
+
124
+ it 'should constrain the sum of a set' do
125
+ @set.sum(:weights => @weights).must_be.in(-10..-1)
126
+ @model.solve!.should_not be_nil
127
+ weighted_sum = @set.value.inject(0){ |sum, x| sum - x**2 }
128
+ weighted_sum.should >= -10
129
+ weighted_sum.should <= -1
130
+ end
131
+
132
+ it 'should remove any elements not in the weight hash' do
133
+ @set.must_be.superset_of 0
134
+ @set.sum(:weights => {}).must_be == 0
135
+ lambda do
136
+ @model.solve!
137
+ end.should raise_error(Gecode::NoSolutionError)
138
+ end
139
+
140
+ it_should_behave_like(
141
+ 'property that produces int operand by short circuiting equality')
142
+ end
143
+
144
+ describe Gecode::Set::Connection, ' (sum with substitutions)' do
145
+ before do
146
+ @model = Gecode::Model.new
147
+ @set = @model.set_var([], 0..9)
148
+ @target = @var = @model.int_var(-20..20)
149
+ @model.branch_on @model.wrap_enum([@set])
150
+ @subs = Hash[*(0..9).zip((-9..-0).to_a.reverse).flatten]
151
+
152
+ @property_types = [:set]
153
+ @select_property = lambda do |set|
154
+ set.sum(:substitutions => @subs)
155
+ end
156
+ @selected_property = @set.sum(:substitutions => @subs)
157
+ @constraint_class = Gecode::BlockConstraint
158
+ end
159
+
160
+ it 'should constrain the sum of a set' do
161
+ @set.sum(:substitutions => @subs).must_be.in(-10..-1)
162
+ @model.solve!.should_not be_nil
163
+ substituted_sum = @set.value.inject{ |sum, x| sum + @subs[x] }
164
+ substituted_sum.should >= -10
165
+ substituted_sum.should <= -1
166
+ end
167
+
168
+ it 'should not be allowed together with :weights option' do
169
+ lambda do
170
+ @set.sum(:substitutions => @subs, :weights => [1]*20).must_be.in(-10..-1)
171
+ end.should raise_error(ArgumentError)
172
+ end
173
+
174
+ it_should_behave_like(
175
+ 'property that produces int operand by short circuiting equality')
176
+ end
@@ -0,0 +1,197 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ Gecode::Util::SET_RELATION_TYPES.each_pair do |relation, type|
4
+ next if relation == :==
5
+
6
+ describe Gecode::Set::Domain, " (#{relation})" do
7
+ include GecodeR::Specs::SetHelper
8
+
9
+ before do
10
+ @model = Gecode::Model.new
11
+ @glb = []
12
+ @lub = 0..3
13
+ @set = @model.set_var(@glb, @lub)
14
+ @model.branch_on @set
15
+ @range = 0..1
16
+ @non_range = [0, 2]
17
+ @singleton = 0
18
+
19
+ @types = [:set]
20
+ @invoke = lambda do |receiver, hash|
21
+ receiver.method(relation).call(@non_range, hash)
22
+ @model.solve!
23
+ end
24
+ @expect = lambda do |var, opts, reif_var|
25
+ @expect_with_rhs.call(var, opts, reif_var, @non_range)
26
+ end
27
+ @expect_with_rhs = lambda do |var, opts, reif_var, rhs|
28
+ if reif_var.nil?
29
+ Gecode::Raw.should_receive(:dom).once.with(
30
+ an_instance_of(Gecode::Raw::Space),
31
+ var, type,
32
+ *expect_constant_set(rhs))
33
+ else
34
+ params = [an_instance_of(Gecode::Raw::Space),
35
+ var, type]
36
+ params << expect_constant_set(rhs)
37
+ params << reif_var
38
+ Gecode::Raw.should_receive(:dom).once.with(*params.flatten)
39
+ end
40
+ end
41
+ end
42
+
43
+ it "should translate #{relation} with constant range to domain constraint" do
44
+ @expect_with_rhs.call(@model.allow_space_access{ @set.bind },
45
+ nil, nil, @range)
46
+ @set.must.send(relation, @range)
47
+ @model.solve!
48
+ end
49
+
50
+ it "should translate #{relation} with constant non-range to domain constraint" do
51
+ @expect_with_rhs.call(@model.allow_space_access{ @set.bind },
52
+ nil, nil, @non_range)
53
+ @set.must.send(relation, @non_range)
54
+ @model.solve!
55
+ end
56
+
57
+ it "should translate #{relation} with constant singleton to domain constraint" do
58
+ @expect_with_rhs.call(@model.allow_space_access{ @set.bind },
59
+ nil, nil, @singleton)
60
+ @set.must.send(relation, @singleton)
61
+ @model.solve!
62
+ end
63
+
64
+ it 'should raise error if the right hand side is not a constant set' do
65
+ lambda do
66
+ @set.must.send(relation, 'not a constant set')
67
+ end.should raise_error(TypeError)
68
+ end
69
+
70
+ it "should constrain the domain when #{relation} is used" do
71
+ @set = @model.set_var if relation == :complement
72
+ @set.must.method(relation).call(@non_range)
73
+ @model.solve!
74
+ @set.should be_assigned
75
+ case relation
76
+ when :superset
77
+ (@non_range - @set.value.to_a).should be_empty
78
+ when :subset
79
+ (@set.value.to_a - @non_range).should be_empty
80
+ when :complement
81
+ val = @set.value
82
+ val.min.should == Gecode::Model::SET_MIN_INT
83
+ val.max.should == Gecode::Model::SET_MAX_INT
84
+ @non_range.each do |element|
85
+ @set.not_in_upper_bound?(element).should be_true
86
+ end
87
+ when :disjoint
88
+ (@non_range & @set.value.to_a).should be_empty
89
+ end
90
+ end
91
+
92
+ it "should constrain the domain when negated #{relation} is used" do
93
+ @set.must_not.method(relation).call(@non_range)
94
+ @model.solve!
95
+ @set.should be_assigned
96
+ case relation
97
+ when :superset
98
+ (@non_range - @set.value.to_a).should_not be_empty
99
+ when :subset
100
+ (@set.value.to_a - @non_range).should_not be_empty
101
+ when :complement
102
+ val = @set.value
103
+ ((val.min != Gecode::Model::SET_MIN_INT) ||
104
+ (val.max != Gecode::Model::SET_MAX_INT) ||
105
+ @non_range.any?{ |element| @set.in_lower_bound?(element) }
106
+ ).should be_true
107
+ when :disjoint
108
+ (@non_range & @set.value.to_a).should_not be_empty
109
+ end
110
+ end
111
+
112
+ it_should_behave_like 'reifiable set constraint'
113
+ end
114
+ end
115
+
116
+ describe Gecode::Set::Domain, ' (equality)' do
117
+ include GecodeR::Specs::SetHelper
118
+
119
+ before do
120
+ @model = Gecode::Model.new
121
+ @glb = [0]
122
+ @lub = 0..3
123
+ @set = @model.set_var(@glb, @lub)
124
+ @range = 0..1
125
+ @non_range = [0, 2]
126
+ @singleton = 0
127
+ @model.branch_on @model.wrap_enum([@set])
128
+
129
+ @types = [:set]
130
+ @invoke = lambda do |receiver, hash|
131
+ receiver.equal(@non_range, hash)
132
+ @model.solve!
133
+ end
134
+ @expect = lambda do |var, opts, reif_var|
135
+ @expect_with_rhs.call(var, opts, reif_var, @non_range)
136
+ end
137
+ @expect_with_rhs = lambda do |var, opts, reif_var, rhs|
138
+ if reif_var.nil?
139
+ Gecode::Raw.should_receive(:dom).once.with(
140
+ an_instance_of(Gecode::Raw::Space),
141
+ var, Gecode::Raw::SRT_EQ,
142
+ *expect_constant_set(rhs))
143
+ else
144
+ params = [an_instance_of(Gecode::Raw::Space),
145
+ var, Gecode::Raw::SRT_EQ]
146
+ params << expect_constant_set(rhs)
147
+ params << reif_var
148
+ Gecode::Raw.should_receive(:dom).once.with(*params.flatten)
149
+ end
150
+ end
151
+ end
152
+
153
+ it 'should translate equality with constant range to domain constraint' do
154
+ @expect_with_rhs.call(@model.allow_space_access{ @set.bind },
155
+ nil, nil, @range)
156
+ @set.must == @range
157
+ @model.solve!
158
+ end
159
+
160
+ it 'should translate equality with constant non-range to domain constraint' do
161
+ @expect_with_rhs.call(@model.allow_space_access{ @set.bind },
162
+ nil, nil, @non_range)
163
+ @set.must == @non_range
164
+ @model.solve!
165
+ end
166
+
167
+ it 'should translate equality with constant singleton to domain constraint' do
168
+ @expect_with_rhs.call(@model.allow_space_access{ @set.bind },
169
+ nil, nil, @singleton)
170
+ @set.must == @singleton
171
+ @model.solve!
172
+ end
173
+
174
+ it 'should constrain the domain with equality' do
175
+ @set.must == @singleton
176
+ @model.solve!
177
+ @set.should be_assigned
178
+ @set.value.should include(@singleton)
179
+ @set.value.size.should == 1
180
+ end
181
+
182
+ it 'should constrain the domain with inequality' do
183
+ @set.must_not == @singleton
184
+ @model.solve!
185
+ @set.should be_assigned
186
+ @set.value.should include(@singleton)
187
+ ((@set.value.size > 1) || (@set.value != [@singleton])).should be_true
188
+ end
189
+
190
+ it 'should raise error if the right hand side is not a constant set' do
191
+ lambda do
192
+ @set.must == 'not a constant set'
193
+ end.should raise_error(TypeError)
194
+ end
195
+
196
+ it_should_behave_like 'reifiable set constraint'
197
+ end
@@ -0,0 +1,36 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ describe Gecode::Set::Connection, ' (include)' do
4
+ before do
5
+ @model = Gecode::Model.new
6
+ @set = @model.set_var([], 2..5)
7
+ @array = @model.int_var_array(4, 0..9)
8
+ @array.must_be.distinct
9
+ @model.branch_on @array
10
+ #@model.branch_on @model.wrap_enum([@set])
11
+
12
+ @types = [:set, :int_enum]
13
+ @invoke = lambda do |receiver, int_enum, hash|
14
+ if hash.empty?
15
+ receiver.include(int_enum)
16
+ else
17
+ receiver.include(int_enum, hash)
18
+ end
19
+ @model.solve!
20
+ end
21
+ @expect = lambda do |var1, var2, opts, reif_var|
22
+ Gecode::Raw.should_receive(:match).once.with(
23
+ an_instance_of(Gecode::Raw::Space),
24
+ var1, var2)
25
+ end
26
+ end
27
+
28
+ it 'should constrain the variables to be included in the set' do
29
+ @set.must.include @array
30
+ @model.solve!.should_not be_nil
31
+ @array.all?{ |x| @set.lower_bound.include? x.value }.should be_true
32
+ end
33
+
34
+ it_should_behave_like 'non-reifiable set constraint'
35
+ it_should_behave_like 'non-negatable constraint'
36
+ end
@@ -0,0 +1,132 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ Gecode::Util::SET_OPERATION_TYPES.each_pair do |operation, type|
4
+ describe Gecode::Set::Operation, " (#{operation} with set variable)" do
5
+ before do
6
+ @model = Gecode::Model.new
7
+ @set1 = @model.set_var([0], 0..20)
8
+ @set2 = @model.set_var([1], 0..20)
9
+ @constant_set = [2, 3, 5]
10
+ @rhs = @model.set_var([], 0..20)
11
+ @model.branch_on @model.wrap_enum([@set1, @set2, @rhs])
12
+
13
+ @property_types = [:set, :set]
14
+ @select_property = lambda do |set1, set2|
15
+ set1.method(operation).call(set2)
16
+ end
17
+ @selected_property = @set1.method(operation).call(@set2)
18
+ @constraint_class =
19
+ Gecode::Set::Operation::OperationConstraint
20
+ end
21
+
22
+ it "should translate #{operation} into an operation constraint" do
23
+ @model.allow_space_access do
24
+ Gecode::Raw.should_receive(:rel).once.with(
25
+ an_instance_of(Gecode::Raw::Space), @set1.bind, type, @set2.bind,
26
+ Gecode::Raw::SRT_EQ, @rhs.bind)
27
+ end
28
+ @set1.method(operation).call(@set2).must == @rhs
29
+ @model.solve!
30
+ end
31
+
32
+ it "should constrain the #{operation} of the sets with variable rhs" do
33
+ @set1.method(operation).call(@set2).must == @rhs
34
+ @model.solve!
35
+
36
+ s1 = @set1.value.to_a
37
+ s2 = @set2.value.to_a
38
+ rhs = @rhs.value.to_a
39
+ case operation
40
+ when :union
41
+ (s1 | s2).should == rhs
42
+ when :disjoint_union
43
+ (s1 | s2).sort.should == rhs.sort
44
+ when :intersection
45
+ (s1 & s2).should == rhs
46
+ when :minus
47
+ (s1 - s2).should == rhs
48
+ end
49
+ end
50
+
51
+ it "should constrain the #{operation} of the sets when used with constant rhs" do
52
+ if operation == :union || operation == :disjoint_union
53
+ @constant_set << 0 << 1 # Or there will not be any solution.
54
+ end
55
+ @set1.method(operation).call(@set2).must == @constant_set
56
+ @model.solve!
57
+
58
+ s1 = @set1.value.to_a
59
+ s2 = @set2.value.to_a
60
+ rhs = @constant_set
61
+ case operation
62
+ when :union
63
+ (s1 | s2).sort.should == rhs.sort
64
+ when :disjoint_union
65
+ (s1 | s2).sort.should == rhs.sort
66
+ when :intersection
67
+ (s1 & s2).should == rhs
68
+ when :minus
69
+ (s1 - s2).should == rhs
70
+ end
71
+ end
72
+
73
+ it_should_behave_like(
74
+ 'property that produces set operand by short circuiting set relations')
75
+ end
76
+ end
77
+
78
+ Gecode::Util::SET_OPERATION_TYPES.each_pair do |operation, type|
79
+ describe Gecode::Set::Operation, " (#{operation} with constant set)" do
80
+ before do
81
+ @model = Gecode::Model.new
82
+ @set = @model.set_var([0], 0..20)
83
+ @constant_set = [1, 3, 5]
84
+ @rhs = @model.set_var([], 0..20)
85
+ @model.branch_on @model.wrap_enum([@set, @rhs])
86
+
87
+ @property_types = [:set, :set]
88
+ @select_property = lambda do |set1, set2|
89
+ set1.method(operation).call(set2)
90
+ end
91
+ @selected_property = @set.method(operation).call(@constant_set)
92
+ @constraint_class =
93
+ Gecode::Set::Operation::OperationConstraint
94
+ end
95
+
96
+ it "should translate #{operation} into an operation constraint" do
97
+ @model.allow_space_access do
98
+ Gecode::Raw.should_receive(:rel).once.with(
99
+ an_instance_of(Gecode::Raw::Space), @set.bind, type,
100
+ an_instance_of(Gecode::Raw::IntSet),
101
+ Gecode::Raw::SRT_EQ, @rhs.bind)
102
+ end
103
+ @set.method(operation).call(@constant_set).must == @rhs
104
+ @model.solve!
105
+ end
106
+
107
+ it "should constrain the #{operation} of the sets with a variable rhs" do
108
+ @set.method(operation).call(@constant_set).must == @rhs
109
+ @model.solve!
110
+
111
+ s1 = @set.value.to_a
112
+ s2 = @constant_set
113
+ rhs = @rhs.value.to_a
114
+ case operation
115
+ when :union
116
+ (s1 | s2).should == rhs
117
+ when :disjoint_union
118
+ (s1 | s2).sort.should == rhs.sort
119
+ when :intersection
120
+ (s1 & s2).should == rhs
121
+ when :minus
122
+ (s1 - s2).should == rhs
123
+ end
124
+ end
125
+
126
+ # We do not test with a constant rhs since we do not have enough
127
+ # degrees of freedom to always find a solution.
128
+
129
+ it_should_behave_like(
130
+ 'property that produces set operand by short circuiting set relations')
131
+ end
132
+ end