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,36 @@
1
+ module Gecode::Set
2
+ class SetConstraintReceiver
3
+ # Constrains this set to include the values of +int_enum+.
4
+ #
5
+ # The constraint has the side effect of sorting the integer operands in a
6
+ # non-descending order. It does not support reification nor negation.
7
+ #
8
+ # ==== Examples
9
+ #
10
+ # # Constrain +set+ to include the values of all operands in
11
+ # # +int_enum+.
12
+ # set.must.include int_enum
13
+ def include(int_enum)
14
+ unless int_enum.respond_to? :to_int_enum
15
+ raise TypeError, "Expected int var enum, got #{int_enum.class}."
16
+ end
17
+ if @params[:negate]
18
+ raise Gecode::MissingConstraintError, 'A negated include is not ' +
19
+ 'implemented.'
20
+ end
21
+
22
+ @params.update(:variables => int_enum)
23
+ @model.add_constraint Connection::IncludeConstraint.new(@model, @params)
24
+ end
25
+ end
26
+
27
+ module Connection #:nodoc:
28
+ class IncludeConstraint < Gecode::Constraint #:nodoc:
29
+ def post
30
+ set, variables = @params.values_at(:lhs, :variables)
31
+ Gecode::Raw::match(@model.active_space, set.to_set_var.bind,
32
+ variables.to_int_enum.bind_array)
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,118 @@
1
+ module Gecode::Set
2
+ module SetOperand
3
+ # Produces a new SetOperand representing the union between this operand
4
+ # and +set_operand_or_constant_set+.
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # The union between +set1+ and +set2+.
9
+ # set1.union set2
10
+ #
11
+ # # The union between +set+ and {1, 3, 5}.
12
+ # set.union [1,3,5]
13
+ def union(set_operand_or_constant_set)
14
+ set_operation(:union, set_operand_or_constant_set)
15
+ end
16
+
17
+ # Produces a new SetOperand representing the disjoint union between
18
+ # this operand and +set_operand_or_constant_set+. The disjoint union
19
+ # is the union of the disjoint parts of the sets.
20
+ #
21
+ # ==== Examples
22
+ #
23
+ # # The disjoint union between +set1+ and +set2+.
24
+ # set1.disjoint_union set2
25
+ #
26
+ # # The disjoint union between +set+ and {1, 3, 5}.
27
+ # set.disjoint_union [1,3,5]
28
+ def disjoint_union(set_operand_or_constant_set)
29
+ set_operation(:disjoint_union, set_operand_or_constant_set)
30
+ end
31
+
32
+ # Produces a new SetOperand representing the intersection between
33
+ # this operand and +set_operand_or_constant_set+.
34
+ #
35
+ # ==== Examples
36
+ #
37
+ # # The intersection between +set1+ and +set2+.
38
+ # set1.intersection set2
39
+ #
40
+ # # The intersection between +set+ and {1, 3, 5}.
41
+ # set.intersection [1,3,5]
42
+ def intersection(set_operand_or_constant_set)
43
+ set_operation(:intersection, set_operand_or_constant_set)
44
+ end
45
+
46
+ # Produces a new SetOperand representing this operand minus
47
+ # +set_operand_or_constant_set+.
48
+ #
49
+ # ==== Examples
50
+ #
51
+ # # +set1+ minus +set2+.
52
+ # set1.minus set2
53
+ #
54
+ # # +set+ minus {1, 3, 5}.
55
+ # set.minus [1,3,5]
56
+ def minus(set_operand_or_constant_set)
57
+ set_operation(:minus, set_operand_or_constant_set)
58
+ end
59
+
60
+ private
61
+
62
+ # Produces the SetOperand resulting from +operator+ applied to this
63
+ # operand and +operand2+.
64
+ def set_operation(operator, operand2)
65
+ unless operand2.respond_to? :to_set_var or
66
+ Gecode::Util::constant_set?(operand2)
67
+ raise TypeError, 'Expected set operand or constant set as ' +
68
+ "operand, got \#{operand2.class}."
69
+ end
70
+
71
+ return Operation::OperationSetOperand.new(model, self, operator,
72
+ operand2)
73
+ end
74
+ end
75
+
76
+ # A module that gathers the classes and modules used in operation constraints.
77
+ module Operation #:nodoc:
78
+ class OperationSetOperand < Gecode::Set::ShortCircuitRelationsOperand #:nodoc:
79
+ def initialize(model, op1, operator, op2)
80
+ super model
81
+ @op1 = op1
82
+ @op2 = op2
83
+ @operator = operator
84
+ end
85
+
86
+ def relation_constraint(relation, set_operand_or_constant_set, params)
87
+ relation_type =
88
+ Gecode::Util::SET_RELATION_TYPES[relation]
89
+
90
+ operation = Gecode::Util::SET_OPERATION_TYPES[@operator]
91
+ params.update(:rhs => set_operand_or_constant_set,
92
+ :relation_type => relation_type, :op1 => @op1, :op2 => @op2,
93
+ :operation => operation)
94
+ OperationConstraint.new(model, params)
95
+ end
96
+ end
97
+
98
+ class OperationConstraint < Gecode::Constraint #:nodoc:
99
+ def post
100
+ op1, op2, operation, relation, rhs, negate = @params.values_at(:op1,
101
+ :op2, :operation, :relation_type, :rhs, :negate)
102
+
103
+ op1, op2, rhs = [op1, op2, rhs].map do |expression|
104
+ # The expressions can either be set operands or constant sets,
105
+ # convert them appropriately.
106
+ if expression.respond_to? :to_set_var
107
+ expression.to_set_var.bind
108
+ else
109
+ Gecode::Util::constant_set_to_int_set(expression)
110
+ end
111
+ end
112
+
113
+ Gecode::Raw::rel(@model.active_space, op1, operation, op2,
114
+ relation, rhs)
115
+ end
116
+ end
117
+ end
118
+ end
@@ -0,0 +1,155 @@
1
+ module Gecode::Set
2
+ class SetConstraintReceiver
3
+ alias_method :pre_relation_equality, :==
4
+ # Constrains the set operand to equal +set_operand+.
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # +set1+ must equal +set2+
9
+ # set1.must == set2
10
+ #
11
+ # # +set1+ must equal +set2+. Reify the constraint with the
12
+ # # boolean operand +bool+.
13
+ # set1.must.equal(set2, :reify => bool)
14
+ def ==(set_operand, options = {})
15
+ if set_operand.respond_to? :to_set_var
16
+ add_relation_constraint(:==, set_operand, options)
17
+ else
18
+ pre_relation_equality(set_operand, options)
19
+ end
20
+ end
21
+
22
+ alias_method :pre_relation_superset, :superset
23
+ # Constrains the set operand to be a superset of +set_operand+.
24
+ #
25
+ # ==== Examples
26
+ #
27
+ # # +set1+ must be a superset of +set2+
28
+ # set1.must_be.superset_of set2
29
+ #
30
+ # # +set1+ must be a superset of +set2+. Reify the constraint
31
+ # # with the boolean operand +bool+.
32
+ # set1.must_be.superset(set2, :reify => bool)
33
+ def superset(set_operand, options = {})
34
+ if set_operand.respond_to? :to_set_var
35
+ add_relation_constraint(:superset, set_operand, options)
36
+ else
37
+ pre_relation_superset(set_operand, options)
38
+ end
39
+ end
40
+
41
+ alias_method :pre_relation_subset, :subset
42
+ # Constrains the set operand to be a subeset of +set_operand+.
43
+ #
44
+ # ==== Examples
45
+ #
46
+ # # +set1+ must be a subset of +set2+
47
+ # set1.must_be.subset_of == set2
48
+ #
49
+ # # +set1+ must be a subset of +set2+. Reify the constraint
50
+ # # with the boolean operand +bool+.
51
+ # set1.must_be.subset(set2, :reify => bool)
52
+ def subset(set_operand, options = {})
53
+ if set_operand.respond_to? :to_set_var
54
+ add_relation_constraint(:subset, set_operand, options)
55
+ else
56
+ pre_relation_subset(set_operand, options)
57
+ end
58
+ end
59
+
60
+ alias_method :pre_relation_disjoint, :disjoint
61
+ # Constrains the set operand to be disjoint with +set_operand+.
62
+ #
63
+ # ==== Examples
64
+ #
65
+ # # +set1+ must be disjoint with +set2+
66
+ # set1.must_be.disjoint_with set2
67
+ #
68
+ # # +set1+ must be disjoint with +set2+. Reify the constraint
69
+ # # with the boolean operand +bool+.
70
+ # set1.must_be.disjoint(set2, :reify => bool)
71
+ def disjoint(set_operand, options = {})
72
+ if set_operand.respond_to? :to_set_var
73
+ add_relation_constraint(:disjoint, set_operand, options)
74
+ else
75
+ pre_relation_disjoint(set_operand, options)
76
+ end
77
+ end
78
+
79
+ alias_method :pre_relation_complement, :complement
80
+ # Constrains the set operand to be the complement of +set_operand+.
81
+ #
82
+ # ==== Examples
83
+ #
84
+ # # +set1+ must be the complement of +set2+
85
+ # set1.must_be.complement_of set2
86
+ #
87
+ # # +set1+ must be the complement of +set2+. Reify the constraint
88
+ # # with the boolean operand +bool+.
89
+ # set1.must_be.complement(set2, :reify => bool)
90
+ def complement(set_operand, options = {})
91
+ if set_operand.respond_to? :to_set_var
92
+ add_relation_constraint(:complement, set_operand, options)
93
+ else
94
+ pre_relation_complement(set_operand, options)
95
+ end
96
+ end
97
+
98
+ alias_set_methods
99
+
100
+ private
101
+
102
+ # Adds a relation constraint for the specified relation name, set
103
+ # operand and options.
104
+ def add_relation_constraint(relation_name, set, options)
105
+ @params[:rhs] = set
106
+ @params[:relation] = relation_name
107
+ @params.update Gecode::Set::Util.decode_options(options)
108
+ if relation_name == :==
109
+ @model.add_constraint Relation::EqualityRelationConstraint.new(@model,
110
+ @params)
111
+ else
112
+ @model.add_constraint Relation::RelationConstraint.new(@model, @params)
113
+ end
114
+ end
115
+ end
116
+
117
+ # A module that gathers the classes and modules used in relation constraints.
118
+ module Relation #:nodoc:
119
+ class EqualityRelationConstraint < Gecode::ReifiableConstraint #:nodoc:
120
+ def post
121
+ lhs, rhs, reif_var, negate = @params.values_at(:lhs, :rhs, :reif,
122
+ :negate)
123
+ if negate
124
+ rel_type = Gecode::Util::NEGATED_SET_RELATION_TYPES[:==]
125
+ else
126
+ rel_type = Gecode::Util::SET_RELATION_TYPES[:==]
127
+ end
128
+
129
+ (params = []) << lhs.to_set_var.bind
130
+ params << rel_type
131
+ params << rhs.to_set_var.bind
132
+ if reif_var.respond_to? :to_bool_var
133
+ params << reif_var.to_bool_var.bind
134
+ end
135
+ Gecode::Raw::rel(@model.active_space, *params)
136
+ end
137
+ end
138
+
139
+ class RelationConstraint < Gecode::ReifiableConstraint #:nodoc:
140
+ def post
141
+ lhs, rhs, reif_var, relation = @params.values_at(:lhs, :rhs, :reif,
142
+ :relation)
143
+
144
+ (params = []) << lhs.to_set_var.bind
145
+ params << Gecode::Util::SET_RELATION_TYPES[relation]
146
+ params << rhs.to_set_var.bind
147
+ if reif_var.respond_to? :to_bool_var
148
+ params << reif_var.to_bool_var.bind
149
+ end
150
+ Gecode::Raw::rel(@model.active_space, *params)
151
+ end
152
+ negate_using_reification
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,116 @@
1
+ module Gecode::SetElements
2
+ class SetElementsConstraintReceiver
3
+ # Constrains the set elements to equal +operand+ (either a
4
+ # constant integer or an integer operand).
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # The elements of +set+ must equal +int+
9
+ # set.elements.must == int
10
+ #
11
+ # # The elements of +set+ must equal 17
12
+ # set.elements.must == 17
13
+ def ==(operand, options = {})
14
+ comparison(:==, operand, options)
15
+ end
16
+
17
+ # Constrains the set elements to be strictly greater than
18
+ # +operand+ (either a constant integer or an integer operand).
19
+ #
20
+ # ==== Examples
21
+ #
22
+ # # The elements of +set+ must be strictly greater than +int+
23
+ # set.elements.must > int
24
+ #
25
+ # # The elements of +set+ must be strictly greater than 17
26
+ # set.elements.must > 17
27
+ def >(operand, options = {})
28
+ comparison(:>, operand, options)
29
+ end
30
+
31
+ # Constrains the set elements to be greater than or equal to
32
+ # +operand+ (either a constant integer or an integer operand).
33
+ #
34
+ # ==== Examples
35
+ #
36
+ # # The elements of +set+ must be greater than or equal to +int+
37
+ # set.elements.must >= int
38
+ #
39
+ # # The elements of +set+ must be greater than or equal to 17
40
+ # set.elements.must >= 17
41
+ def >=(operand, options = {})
42
+ comparison(:>=, operand, options)
43
+ end
44
+
45
+ # Constrains the set elements to be strictly less than
46
+ # +operand+ (either a constant integer or an integer operand).
47
+ #
48
+ # ==== Examples
49
+ #
50
+ # # The elements of +set+ must be strictly less than +int+
51
+ # set.elements.must < int
52
+ #
53
+ # # The elements of +set+ must be strictly less than 17
54
+ # set.elements.must < 17
55
+ def <(operand, options = {})
56
+ comparison(:<, operand, options)
57
+ end
58
+
59
+ # Constrains the set elements to be less than or equal to
60
+ # +operand+ (either a constant integer or an integer operand).
61
+ #
62
+ # ==== Examples
63
+ #
64
+ # # The elements of +set+ must be less than or equal to +int+
65
+ # set.elements.must <= int
66
+ #
67
+ # # The elements of +set+ must be less than or equal to 17
68
+ # set.elements.must <= 17
69
+ def <=(operand, options = {})
70
+ comparison(:<=, operand, options)
71
+ end
72
+
73
+ alias_comparison_methods
74
+
75
+ private
76
+
77
+ # Helper for the comparison methods. The reason that they are not
78
+ # generated in a loop is that it would mess up the RDoc.
79
+ def comparison(name, operand, options)
80
+ unless operand.respond_to?(:to_int_var) or
81
+ operand.kind_of?(Fixnum)
82
+ raise TypeError, "Expected int operand or integer, got " +
83
+ "#{operand.class}."
84
+ end
85
+ unless options[:reify].nil?
86
+ raise ArgumentError, 'Reification is not supported by the elements ' +
87
+ 'relation constraint.'
88
+ end
89
+
90
+ unless @params[:negate]
91
+ relation_type = Gecode::Util::RELATION_TYPES[name]
92
+ else
93
+ relation_type = Gecode::Util::NEGATED_RELATION_TYPES[name]
94
+ end
95
+ @params.update Gecode::Set::Util.decode_options(options)
96
+ @model.add_constraint Relation::RelationConstraint.new(@model,
97
+ @params.update(:relation_type => relation_type, :rhs => operand))
98
+ end
99
+ end
100
+
101
+ module Relation #:nodoc:
102
+ class RelationConstraint < Gecode::Constraint #:nodoc:
103
+ def post
104
+ set_elements, rhs, type = @params.values_at(:lhs, :rhs, :relation_type)
105
+ set = set_elements.to_set_elements
106
+
107
+ if rhs.kind_of? Fixnum
108
+ # Use a proxy int variable to cover.
109
+ rhs = @model.int_var(rhs)
110
+ end
111
+ Gecode::Raw::rel(@model.active_space, set.to_set_var.bind,
112
+ type, rhs.to_int_var.bind)
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,97 @@
1
+ # A module containing constraints that have set.elements as left hand
2
+ # side.
3
+ module Gecode::SetElements #:nodoc:
4
+ # A SetElementsOperand is an uncommon operand that results from calling
5
+ # SetOperand#elements. It facilitates placing the constraints defined
6
+ # in SetElementsConstraintReceiver
7
+ #
8
+ # ==== Examples
9
+ #
10
+ # Producing a SetElementsOperand from +set_operand+:
11
+ #
12
+ # set_operand.elements
13
+ #
14
+ class SetElementsOperand
15
+ include Gecode::Operand
16
+
17
+ # Constructs a new set elements operand +set+.
18
+ def initialize(set) #:nodoc:
19
+ unless set.respond_to? :to_set_var
20
+ raise TypeError, "Expected set operand, got #{set.class}."
21
+ end
22
+
23
+ @set = set
24
+ end
25
+
26
+ # Returns the set operand that makes up the set elements operand.
27
+ def to_set_elements #:nodoc:
28
+ return @set
29
+ end
30
+
31
+ def model #:nodoc:
32
+ @set.model
33
+ end
34
+
35
+ private
36
+
37
+ def construct_receiver(params)
38
+ SetElementsConstraintReceiver.new(model, params)
39
+ end
40
+ end
41
+
42
+ # SetElementsConstraintReceiver contains all constraints that can be
43
+ # placed on a SetElementsOperand.
44
+ #
45
+ # Constraints are placed by calling SetElementsOperand#must (or any other
46
+ # of the variations defined in Operand), which produces a
47
+ # SetElementsConstraintReceiver from which the desired constraint can
48
+ # be used.
49
+ #
50
+ # Each constraint accepts a number of options. See ConstraintReceiver
51
+ # for more information.
52
+ #
53
+ # ==== Examples
54
+ #
55
+ # Constrains all elements in +set_operand+ to be strictly greater than 17
56
+ # using SetOperand#elements and SetElementsConstraintReceiver#>:
57
+ #
58
+ # set.elements.must > 17
59
+ #
60
+ # Constrains all elements in +set_operand+ to be strictly greater than
61
+ # +int_operand+ using SetOperand#elements and SetElementsConstraintReceiver#>:
62
+ #
63
+ # set.elements.must > int_operand
64
+ #
65
+ # The same as above, but specifying that strength :domain should be
66
+ # used and that the constraint should be reified with +bool_operand+:
67
+ #
68
+ # set.elements.must_be.greater_than(int_operand, :strength => :domain, :reify => bool_operand)
69
+ #
70
+ class SetElementsConstraintReceiver < Gecode::ConstraintReceiver
71
+ # Raises TypeError unless the left hand side is set elements operand.
72
+ def initialize(model, params) #:nodoc:
73
+ super
74
+
75
+ unless params[:lhs].respond_to? :to_set_elements
76
+ raise TypeError, 'Must have set elements operand as left hand side.'
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ module Gecode::Set #:nodoc:
83
+ module SetOperand
84
+ # Produces a SetElementsOperand on which relation constraints can be placed that
85
+ # constrain all elements in the set.
86
+ #
87
+ # ==== Examples
88
+ #
89
+ # # The elements of +set+.
90
+ # set.elements
91
+ def elements
92
+ Gecode::SetElements::SetElementsOperand.new(self)
93
+ end
94
+ end
95
+ end
96
+
97
+ require 'gecoder/interface/constraints/set_elements/relation.rb'