gecoder-with-gecode 0.8.3 → 0.9.0

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 (337) hide show
  1. data/CHANGES +15 -0
  2. data/README +6 -2
  3. data/example/equation_system.rb +15 -0
  4. data/example/magic_sequence.rb +7 -7
  5. data/example/money.rb +36 -0
  6. data/example/queens.rb +7 -8
  7. data/example/send_most_money.rb +1 -1
  8. data/example/square_tiling.rb +2 -2
  9. data/example/sudoku-set.rb +11 -12
  10. data/example/sudoku.rb +40 -45
  11. data/ext/extconf.rb +0 -0
  12. data/ext/gecode-2.1.1/LICENSE +0 -0
  13. data/ext/gecode-2.1.1/configure +0 -0
  14. data/ext/gecode-2.1.1/contribs/qecode/SDFVariableHeuristic.cc +0 -0
  15. data/ext/gecode-2.1.1/contribs/qecode/SDFVariableHeuristic.hh +0 -0
  16. data/ext/gecode-2.1.1/contribs/qecode/configure +0 -0
  17. data/ext/gecode-2.1.1/contribs/qecode/extensivecomparator.cc +0 -0
  18. data/ext/gecode-2.1.1/contribs/qecode/extensivecomparator.hh +0 -0
  19. data/ext/gecode-2.1.1/contribs/qecode/heap.cc +0 -0
  20. data/ext/gecode-2.1.1/contribs/qecode/implicative.cc +0 -0
  21. data/ext/gecode-2.1.1/contribs/qecode/implicative.hh +0 -0
  22. data/ext/gecode-2.1.1/contribs/qecode/myspace.cc +0 -0
  23. data/ext/gecode-2.1.1/contribs/qecode/myspace.hh +0 -0
  24. data/ext/gecode-2.1.1/contribs/qecode/qecore.cc +0 -0
  25. data/ext/gecode-2.1.1/contribs/qecode/qecore.hh +0 -0
  26. data/ext/gecode-2.1.1/contribs/qecode/warner.cc +0 -0
  27. data/ext/gecode-2.1.1/contribs/qecode/warner.hh +0 -0
  28. data/ext/gecode-2.1.1/gecode/cpltset/var-imp/cpltset.vis +0 -0
  29. data/ext/gecode-2.1.1/gecode/int/arithmetic/abs.icc +0 -0
  30. data/ext/gecode-2.1.1/gecode/int/arithmetic/max.icc +0 -0
  31. data/ext/gecode-2.1.1/gecode/int/arithmetic/mult.icc +0 -0
  32. data/ext/gecode-2.1.1/gecode/int/arithmetic/sqr.icc +0 -0
  33. data/ext/gecode-2.1.1/gecode/int/arithmetic/sqrt.icc +0 -0
  34. data/ext/gecode-2.1.1/gecode/int/array.cc +0 -0
  35. data/ext/gecode-2.1.1/gecode/int/array.icc +0 -0
  36. data/ext/gecode-2.1.1/gecode/int/bool/base.icc +0 -0
  37. data/ext/gecode-2.1.1/gecode/int/bool/eq.icc +0 -0
  38. data/ext/gecode-2.1.1/gecode/int/bool/eqv.icc +0 -0
  39. data/ext/gecode-2.1.1/gecode/int/bool/lq.icc +0 -0
  40. data/ext/gecode-2.1.1/gecode/int/bool/or.icc +0 -0
  41. data/ext/gecode-2.1.1/gecode/int/branch/select-val.icc +0 -0
  42. data/ext/gecode-2.1.1/gecode/int/branch/select-view.icc +0 -0
  43. data/ext/gecode-2.1.1/gecode/int/branch.cc +0 -0
  44. data/ext/gecode-2.1.1/gecode/int/branch.hh +0 -0
  45. data/ext/gecode-2.1.1/gecode/int/channel/base.icc +0 -0
  46. data/ext/gecode-2.1.1/gecode/int/channel/dom.icc +0 -0
  47. data/ext/gecode-2.1.1/gecode/int/channel/link-multi.cc +0 -0
  48. data/ext/gecode-2.1.1/gecode/int/channel/link-multi.icc +0 -0
  49. data/ext/gecode-2.1.1/gecode/int/channel/link-single.cc +0 -0
  50. data/ext/gecode-2.1.1/gecode/int/channel/link-single.icc +0 -0
  51. data/ext/gecode-2.1.1/gecode/int/channel/val.icc +0 -0
  52. data/ext/gecode-2.1.1/gecode/int/channel.cc +0 -0
  53. data/ext/gecode-2.1.1/gecode/int/channel.hh +0 -0
  54. data/ext/gecode-2.1.1/gecode/int/circuit/base.icc +0 -0
  55. data/ext/gecode-2.1.1/gecode/int/circuit/dom.icc +0 -0
  56. data/ext/gecode-2.1.1/gecode/int/circuit/val.icc +0 -0
  57. data/ext/gecode-2.1.1/gecode/int/circuit.cc +0 -0
  58. data/ext/gecode-2.1.1/gecode/int/circuit.hh +0 -0
  59. data/ext/gecode-2.1.1/gecode/int/count/int.icc +0 -0
  60. data/ext/gecode-2.1.1/gecode/int/count/rel.icc +0 -0
  61. data/ext/gecode-2.1.1/gecode/int/count/view.icc +0 -0
  62. data/ext/gecode-2.1.1/gecode/int/distinct/bilink.icc +0 -0
  63. data/ext/gecode-2.1.1/gecode/int/distinct/bnd.icc +0 -0
  64. data/ext/gecode-2.1.1/gecode/int/distinct/combptr.icc +0 -0
  65. data/ext/gecode-2.1.1/gecode/int/distinct/dom.icc +0 -0
  66. data/ext/gecode-2.1.1/gecode/int/distinct/edge.icc +0 -0
  67. data/ext/gecode-2.1.1/gecode/int/distinct/node.icc +0 -0
  68. data/ext/gecode-2.1.1/gecode/int/distinct/ter-dom.icc +0 -0
  69. data/ext/gecode-2.1.1/gecode/int/distinct/val.icc +0 -0
  70. data/ext/gecode-2.1.1/gecode/int/dom/range.icc +0 -0
  71. data/ext/gecode-2.1.1/gecode/int/dom/spec.icc +0 -0
  72. data/ext/gecode-2.1.1/gecode/int/dom.cc +0 -0
  73. data/ext/gecode-2.1.1/gecode/int/dom.hh +0 -0
  74. data/ext/gecode-2.1.1/gecode/int/element/int.icc +0 -0
  75. data/ext/gecode-2.1.1/gecode/int/element/view.icc +0 -0
  76. data/ext/gecode-2.1.1/gecode/int/element.cc +0 -0
  77. data/ext/gecode-2.1.1/gecode/int/element.hh +0 -0
  78. data/ext/gecode-2.1.1/gecode/int/exception.icc +0 -0
  79. data/ext/gecode-2.1.1/gecode/int/extensional/dfa.cc +0 -0
  80. data/ext/gecode-2.1.1/gecode/int/extensional/dfa.icc +0 -0
  81. data/ext/gecode-2.1.1/gecode/int/extensional/layered-graph.icc +0 -0
  82. data/ext/gecode-2.1.1/gecode/int/gcc/dom.icc +0 -0
  83. data/ext/gecode-2.1.1/gecode/int/gcc/gccbndsup.icc +0 -0
  84. data/ext/gecode-2.1.1/gecode/int/gcc/lbc.icc +0 -0
  85. data/ext/gecode-2.1.1/gecode/int/gcc/ubc.icc +0 -0
  86. data/ext/gecode-2.1.1/gecode/int/gcc.cc +0 -0
  87. data/ext/gecode-2.1.1/gecode/int/gcc.hh +0 -0
  88. data/ext/gecode-2.1.1/gecode/int/int-set.cc +0 -0
  89. data/ext/gecode-2.1.1/gecode/int/int-set.icc +0 -0
  90. data/ext/gecode-2.1.1/gecode/int/linear/bool-int.icc +0 -0
  91. data/ext/gecode-2.1.1/gecode/int/linear/bool-post.cc +0 -0
  92. data/ext/gecode-2.1.1/gecode/int/linear/bool-scale.icc +0 -0
  93. data/ext/gecode-2.1.1/gecode/int/linear/bool-view.icc +0 -0
  94. data/ext/gecode-2.1.1/gecode/int/linear/int-bin.icc +0 -0
  95. data/ext/gecode-2.1.1/gecode/int/linear/int-dom.icc +0 -0
  96. data/ext/gecode-2.1.1/gecode/int/linear/int-nary.icc +0 -0
  97. data/ext/gecode-2.1.1/gecode/int/linear/int-post.cc +0 -0
  98. data/ext/gecode-2.1.1/gecode/int/linear/int-ter.icc +0 -0
  99. data/ext/gecode-2.1.1/gecode/int/linear/post.icc +0 -0
  100. data/ext/gecode-2.1.1/gecode/int/propagator.icc +0 -0
  101. data/ext/gecode-2.1.1/gecode/int/rel/eq.icc +0 -0
  102. data/ext/gecode-2.1.1/gecode/int/rel/lex.icc +0 -0
  103. data/ext/gecode-2.1.1/gecode/int/rel/lq-le.icc +0 -0
  104. data/ext/gecode-2.1.1/gecode/int/rel/nq.icc +0 -0
  105. data/ext/gecode-2.1.1/gecode/int/unshare.cc +0 -0
  106. data/ext/gecode-2.1.1/gecode/int/var/bool.cc +0 -0
  107. data/ext/gecode-2.1.1/gecode/int/var-imp/bool.cc +0 -0
  108. data/ext/gecode-2.1.1/gecode/int/var-imp/bool.icc +0 -0
  109. data/ext/gecode-2.1.1/gecode/int/var-imp/bool.vis +0 -0
  110. data/ext/gecode-2.1.1/gecode/int/var-imp/delta.icc +0 -0
  111. data/ext/gecode-2.1.1/gecode/int/var-imp/int.icc +0 -0
  112. data/ext/gecode-2.1.1/gecode/int/var-imp/int.vis +0 -0
  113. data/ext/gecode-2.1.1/gecode/int/view/bool.icc +0 -0
  114. data/ext/gecode-2.1.1/gecode/int/view/constint.icc +0 -0
  115. data/ext/gecode-2.1.1/gecode/int/view/int.icc +0 -0
  116. data/ext/gecode-2.1.1/gecode/int/view/iter.icc +0 -0
  117. data/ext/gecode-2.1.1/gecode/int/view/minus.icc +0 -0
  118. data/ext/gecode-2.1.1/gecode/int/view/offset.icc +0 -0
  119. data/ext/gecode-2.1.1/gecode/int/view/print.cc +0 -0
  120. data/ext/gecode-2.1.1/gecode/int/view/rtest.icc +0 -0
  121. data/ext/gecode-2.1.1/gecode/int/view/scale.icc +0 -0
  122. data/ext/gecode-2.1.1/gecode/int/view/zero.icc +0 -0
  123. data/ext/gecode-2.1.1/gecode/int/view.icc +0 -0
  124. data/ext/gecode-2.1.1/gecode/iter/ranges-add.icc +0 -0
  125. data/ext/gecode-2.1.1/gecode/iter/ranges-append.icc +0 -0
  126. data/ext/gecode-2.1.1/gecode/iter/ranges-array.icc +0 -0
  127. data/ext/gecode-2.1.1/gecode/iter/ranges-cache.icc +0 -0
  128. data/ext/gecode-2.1.1/gecode/iter/ranges-compl.icc +0 -0
  129. data/ext/gecode-2.1.1/gecode/iter/ranges-diff.icc +0 -0
  130. data/ext/gecode-2.1.1/gecode/iter/ranges-empty.icc +0 -0
  131. data/ext/gecode-2.1.1/gecode/iter/ranges-inter.icc +0 -0
  132. data/ext/gecode-2.1.1/gecode/iter/ranges-minmax.icc +0 -0
  133. data/ext/gecode-2.1.1/gecode/iter/ranges-minus.icc +0 -0
  134. data/ext/gecode-2.1.1/gecode/iter/ranges-offset.icc +0 -0
  135. data/ext/gecode-2.1.1/gecode/iter/ranges-operations.icc +0 -0
  136. data/ext/gecode-2.1.1/gecode/iter/ranges-scale.icc +0 -0
  137. data/ext/gecode-2.1.1/gecode/iter/ranges-singleton-append.icc +0 -0
  138. data/ext/gecode-2.1.1/gecode/iter/ranges-singleton.icc +0 -0
  139. data/ext/gecode-2.1.1/gecode/iter/ranges-union.icc +0 -0
  140. data/ext/gecode-2.1.1/gecode/iter/ranges-values.icc +0 -0
  141. data/ext/gecode-2.1.1/gecode/iter/values-array.icc +0 -0
  142. data/ext/gecode-2.1.1/gecode/iter/values-minus.icc +0 -0
  143. data/ext/gecode-2.1.1/gecode/iter/values-offset.icc +0 -0
  144. data/ext/gecode-2.1.1/gecode/iter/values-ranges.icc +0 -0
  145. data/ext/gecode-2.1.1/gecode/iter/values-singleton.icc +0 -0
  146. data/ext/gecode-2.1.1/gecode/iter/values-unique.icc +0 -0
  147. data/ext/gecode-2.1.1/gecode/iter.hh +0 -0
  148. data/ext/gecode-2.1.1/gecode/kernel/advisor.icc +0 -0
  149. data/ext/gecode-2.1.1/gecode/kernel/array.icc +0 -0
  150. data/ext/gecode-2.1.1/gecode/kernel/branching.icc +0 -0
  151. data/ext/gecode-2.1.1/gecode/kernel/exception.icc +0 -0
  152. data/ext/gecode-2.1.1/gecode/kernel/macros.icc +0 -0
  153. data/ext/gecode-2.1.1/gecode/kernel/memory-manager.icc +0 -0
  154. data/ext/gecode-2.1.1/gecode/kernel/modevent.icc +0 -0
  155. data/ext/gecode-2.1.1/gecode/kernel/propagator.icc +0 -0
  156. data/ext/gecode-2.1.1/gecode/kernel/shared-array.icc +0 -0
  157. data/ext/gecode-2.1.1/gecode/kernel/var-traits.icc +0 -0
  158. data/ext/gecode-2.1.1/gecode/kernel/var.icc +0 -0
  159. data/ext/gecode-2.1.1/gecode/kernel/view.icc +0 -0
  160. data/ext/gecode-2.1.1/gecode/kernel.hh +0 -0
  161. data/ext/gecode-2.1.1/gecode/minimodel/arithmetic.cc +0 -0
  162. data/ext/gecode-2.1.1/gecode/minimodel/bool-expr.cc +0 -0
  163. data/ext/gecode-2.1.1/gecode/minimodel/bool-expr.icc +0 -0
  164. data/ext/gecode-2.1.1/gecode/minimodel/bool-rel.icc +0 -0
  165. data/ext/gecode-2.1.1/gecode/minimodel/lin-expr.icc +0 -0
  166. data/ext/gecode-2.1.1/gecode/minimodel/lin-rel.icc +0 -0
  167. data/ext/gecode-2.1.1/gecode/minimodel/reg.cc +0 -0
  168. data/ext/gecode-2.1.1/gecode/minimodel.hh +0 -0
  169. data/ext/gecode-2.1.1/gecode/search/bab.cc +0 -0
  170. data/ext/gecode-2.1.1/gecode/search/bab.icc +0 -0
  171. data/ext/gecode-2.1.1/gecode/search/dfs.cc +0 -0
  172. data/ext/gecode-2.1.1/gecode/search/dfs.icc +0 -0
  173. data/ext/gecode-2.1.1/gecode/search/engine-ctrl.icc +0 -0
  174. data/ext/gecode-2.1.1/gecode/search/lds.cc +0 -0
  175. data/ext/gecode-2.1.1/gecode/search/lds.icc +0 -0
  176. data/ext/gecode-2.1.1/gecode/search/options.cc +0 -0
  177. data/ext/gecode-2.1.1/gecode/search/options.icc +0 -0
  178. data/ext/gecode-2.1.1/gecode/search/reco-stack.icc +0 -0
  179. data/ext/gecode-2.1.1/gecode/search/restart.icc +0 -0
  180. data/ext/gecode-2.1.1/gecode/search/statistics.icc +0 -0
  181. data/ext/gecode-2.1.1/gecode/search/stop.cc +0 -0
  182. data/ext/gecode-2.1.1/gecode/search/stop.icc +0 -0
  183. data/ext/gecode-2.1.1/gecode/set/var-imp/set.vis +0 -0
  184. data/ext/gecode-2.1.1/gecode/support/block-allocator.icc +0 -0
  185. data/ext/gecode-2.1.1/gecode/support/cast.icc +0 -0
  186. data/ext/gecode-2.1.1/gecode/support/exception.cc +0 -0
  187. data/ext/gecode-2.1.1/gecode/support/exception.icc +0 -0
  188. data/ext/gecode-2.1.1/gecode/support/macros.icc +0 -0
  189. data/ext/gecode-2.1.1/gecode/support/marked-pointer.icc +0 -0
  190. data/ext/gecode-2.1.1/gecode/support/memory.icc +0 -0
  191. data/ext/gecode-2.1.1/gecode/support/sentinel-stack.icc +0 -0
  192. data/ext/gecode-2.1.1/gecode/support/static-stack.icc +0 -0
  193. data/ext/gecode-2.1.1/gecode/support/symbol.cc +0 -0
  194. data/ext/gecode-2.1.1/gecode/support.hh +0 -0
  195. data/ext/gecode-2.1.1/install-sh +0 -0
  196. data/ext/gecode-2.1.1/misc/debian/rules +0 -0
  197. data/ext/gecode-2.1.1/misc/doxygen/back.png +0 -0
  198. data/ext/gecode-2.1.1/misc/doxygen/gecode-logo-100.png +0 -0
  199. data/ext/gecode-2.1.1/misc/genchangelog.perl +0 -0
  200. data/ext/gecode-2.1.1/misc/genlicense.perl +0 -0
  201. data/ext/gecode-2.1.1/misc/genstatistics.perl +0 -0
  202. data/ext/gecode-2.1.1/misc/genvariables.perl +0 -0
  203. data/ext/gecode-2.1.1/misc/getrevision.perl +0 -0
  204. data/ext/gecode-2.1.1/misc/makedepend.perl +0 -0
  205. data/ext/gecode-2.1.1/misc/svn-ignore.txt +0 -0
  206. data/ext/gecode-2.1.1/variables.vsl +0 -0
  207. data/lib/gecoder/bindings/bindings.rb +16 -0
  208. data/lib/gecoder/bindings.rb +42 -0
  209. data/lib/gecoder/interface/branch.rb +16 -9
  210. data/lib/gecoder/interface/constraints/bool/boolean.rb +205 -213
  211. data/lib/gecoder/interface/constraints/bool/channel.rb +4 -5
  212. data/lib/gecoder/interface/constraints/bool/linear.rb +192 -21
  213. data/lib/gecoder/interface/constraints/bool_enum/channel.rb +43 -39
  214. data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +43 -49
  215. data/lib/gecoder/interface/constraints/bool_enum/relation.rb +38 -71
  216. data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +73 -22
  217. data/lib/gecoder/interface/constraints/bool_var_constraints.rb +140 -61
  218. data/lib/gecoder/interface/constraints/extensional_regexp.rb +4 -4
  219. data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
  220. data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
  221. data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
  222. data/lib/gecoder/interface/constraints/int/arithmetic.rb +131 -130
  223. data/lib/gecoder/interface/constraints/int/channel.rb +21 -31
  224. data/lib/gecoder/interface/constraints/int/domain.rb +45 -42
  225. data/lib/gecoder/interface/constraints/int/linear.rb +85 -239
  226. data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
  227. data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +55 -64
  228. data/lib/gecoder/interface/constraints/int_enum/channel.rb +35 -37
  229. data/lib/gecoder/interface/constraints/int_enum/count.rb +53 -78
  230. data/lib/gecoder/interface/constraints/int_enum/distinct.rb +36 -46
  231. data/lib/gecoder/interface/constraints/int_enum/element.rb +39 -57
  232. data/lib/gecoder/interface/constraints/int_enum/equality.rb +15 -19
  233. data/lib/gecoder/interface/constraints/int_enum/extensional.rb +65 -72
  234. data/lib/gecoder/interface/constraints/int_enum/sort.rb +42 -45
  235. data/lib/gecoder/interface/constraints/int_enum_constraints.rb +79 -22
  236. data/lib/gecoder/interface/constraints/int_var_constraints.rb +215 -44
  237. data/lib/gecoder/interface/constraints/reifiable_constraints.rb +14 -14
  238. data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
  239. data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
  240. data/lib/gecoder/interface/constraints/set/cardinality.rb +43 -53
  241. data/lib/gecoder/interface/constraints/set/channel.rb +26 -29
  242. data/lib/gecoder/interface/constraints/set/connection.rb +89 -152
  243. data/lib/gecoder/interface/constraints/set/domain.rb +112 -65
  244. data/lib/gecoder/interface/constraints/set/include.rb +36 -0
  245. data/lib/gecoder/interface/constraints/set/operation.rb +96 -110
  246. data/lib/gecoder/interface/constraints/set/relation.rb +114 -137
  247. data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
  248. data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
  249. data/lib/gecoder/interface/constraints/set_enum/channel.rb +23 -27
  250. data/lib/gecoder/interface/constraints/set_enum/distinct.rb +18 -19
  251. data/lib/gecoder/interface/constraints/set_enum/operation.rb +62 -53
  252. data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
  253. data/lib/gecoder/interface/constraints/set_enum_constraints.rb +73 -23
  254. data/lib/gecoder/interface/constraints/set_var_constraints.rb +222 -57
  255. data/lib/gecoder/interface/constraints.rb +410 -451
  256. data/lib/gecoder/interface/enum_matrix.rb +4 -4
  257. data/lib/gecoder/interface/enum_wrapper.rb +71 -22
  258. data/lib/gecoder/interface/model.rb +167 -12
  259. data/lib/gecoder/interface/model_sugar.rb +84 -0
  260. data/lib/gecoder/interface/search.rb +30 -18
  261. data/lib/gecoder/interface/variables.rb +103 -33
  262. data/lib/gecoder/interface.rb +2 -1
  263. data/lib/gecoder/version.rb +2 -2
  264. data/specs/bool_var.rb +19 -12
  265. data/specs/constraints/{boolean.rb → bool/boolean.rb} +103 -28
  266. data/specs/constraints/bool/boolean_properties.rb +51 -0
  267. data/specs/constraints/bool/linear.rb +213 -0
  268. data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
  269. data/specs/constraints/bool_enum/channel.rb +102 -0
  270. data/specs/constraints/{extensional.rb → bool_enum/extensional.rb} +32 -101
  271. data/specs/constraints/constraint_helper.rb +149 -179
  272. data/specs/constraints/constraint_receivers.rb +103 -0
  273. data/specs/constraints/constraints.rb +6 -63
  274. data/specs/constraints/fixnum_enum/element.rb +58 -0
  275. data/specs/constraints/fixnum_enum/operation.rb +67 -0
  276. data/specs/constraints/int/arithmetic.rb +149 -0
  277. data/specs/constraints/int/channel.rb +101 -0
  278. data/specs/constraints/int/domain.rb +106 -0
  279. data/specs/constraints/int/linear.rb +183 -0
  280. data/specs/constraints/int/linear_properties.rb +97 -0
  281. data/specs/constraints/int/relation.rb +84 -0
  282. data/specs/constraints/int_enum/arithmetic.rb +72 -0
  283. data/specs/constraints/int_enum/channel.rb +57 -0
  284. data/specs/constraints/int_enum/count.rb +72 -0
  285. data/specs/constraints/int_enum/distinct.rb +80 -0
  286. data/specs/constraints/int_enum/element.rb +61 -0
  287. data/specs/constraints/int_enum/equality.rb +29 -0
  288. data/specs/constraints/int_enum/extensional.rb +224 -0
  289. data/specs/constraints/int_enum/sort.rb +167 -0
  290. data/specs/constraints/operands.rb +264 -0
  291. data/specs/constraints/property_helper.rb +443 -0
  292. data/specs/constraints/reification_sugar.rb +4 -5
  293. data/specs/constraints/selected_set/select.rb +56 -0
  294. data/specs/constraints/selected_set/select_properties.rb +157 -0
  295. data/specs/constraints/set/cardinality.rb +58 -0
  296. data/specs/constraints/set/cardinality_properties.rb +46 -0
  297. data/specs/constraints/set/channel.rb +77 -0
  298. data/specs/constraints/set/connection.rb +176 -0
  299. data/specs/constraints/set/domain.rb +197 -0
  300. data/specs/constraints/set/include.rb +36 -0
  301. data/specs/constraints/set/operation.rb +132 -0
  302. data/specs/constraints/set/relation.rb +117 -0
  303. data/specs/constraints/set_elements/relation.rb +84 -0
  304. data/specs/constraints/set_enum/channel.rb +80 -0
  305. data/specs/constraints/set_enum/distinct.rb +59 -0
  306. data/specs/constraints/set_enum/operation.rb +111 -0
  307. data/specs/constraints/set_enum/select.rb +73 -0
  308. data/specs/enum_wrapper.rb +53 -3
  309. data/specs/int_var.rb +44 -25
  310. data/specs/model.rb +58 -1
  311. data/specs/model_sugar.rb +30 -0
  312. data/specs/search.rb +24 -5
  313. data/specs/selected_set.rb +39 -0
  314. data/specs/set_elements.rb +34 -0
  315. data/specs/set_var.rb +22 -8
  316. data/specs/spec_helper.rb +206 -6
  317. data/tasks/distribution.rake +22 -7
  318. data/tasks/svn.rake +3 -1
  319. metadata +219 -135
  320. data/lib/gecoder/interface/constraints/set_enum/selection.rb +0 -217
  321. data/specs/constraints/arithmetic.rb +0 -351
  322. data/specs/constraints/bool_enum_relation.rb +0 -160
  323. data/specs/constraints/cardinality.rb +0 -157
  324. data/specs/constraints/channel.rb +0 -454
  325. data/specs/constraints/connection.rb +0 -369
  326. data/specs/constraints/count.rb +0 -146
  327. data/specs/constraints/distinct.rb +0 -164
  328. data/specs/constraints/element.rb +0 -108
  329. data/specs/constraints/equality.rb +0 -31
  330. data/specs/constraints/int_domain.rb +0 -70
  331. data/specs/constraints/int_relation.rb +0 -82
  332. data/specs/constraints/linear.rb +0 -340
  333. data/specs/constraints/selection.rb +0 -292
  334. data/specs/constraints/set_domain.rb +0 -185
  335. data/specs/constraints/set_operation.rb +0 -285
  336. data/specs/constraints/set_relation.rb +0 -197
  337. data/specs/constraints/sort.rb +0 -179
@@ -1,156 +1,72 @@
1
- module Gecode
2
- class FreeIntVar
3
- # Creates a linear expression where the int variables are summed.
4
- def +(var)
5
- Gecode::Constraints::Int::Linear::ExpressionNode.new(self,
6
- @model) + var
1
+ module Gecode::Int
2
+ module IntOperand
3
+ # Produces a new IntOperand representing this operand plus
4
+ # +int_operand_or_fixnum+.
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # +int1+ plus +int2+
9
+ # int1 + int2
10
+ #
11
+ # # +int+ plus 17
12
+ # int + 17
13
+ def +(int_operand_or_fixnum)
14
+ int_linear_expression_operation(:+, int_operand_or_fixnum)
7
15
  end
8
16
 
9
- alias_method :pre_linear_mult, :* if instance_methods.include? '*'
17
+ # Produces a new IntOperand representing this operand minus
18
+ # +int_operand_or_fixnum+.
19
+ #
20
+ # ==== Examples
21
+ #
22
+ # # +int1+ minus +int2+
23
+ # int1 - int2
24
+ #
25
+ # # +int+ minus 17
26
+ # int - 17
27
+ def -(int_operand_or_fixnum)
28
+ int_linear_expression_operation(:-, int_operand_or_fixnum)
29
+ end
10
30
 
11
- # Creates a linear expression where the int variable is multiplied with
12
- # a constant integer.
13
- def *(int)
14
- if int.kind_of? Fixnum
15
- Gecode::Constraints::Int::Linear::ExpressionNode.new(self,
16
- @model) * int
31
+ # Produces a new IntOperand representing this operand times a
32
+ # constant.
33
+ #
34
+ # ==== Examples
35
+ #
36
+ # # +int+ times 17
37
+ # int * 17
38
+ def *(fixnum)
39
+ if fixnum.kind_of? Fixnum
40
+ int_linear_expression_operation(:*, fixnum)
17
41
  else
18
- pre_linear_mult(int) if respond_to? :pre_linear_mult
42
+ raise TypeError, "Expected fixnum, got #{fixnum.class}."
19
43
  end
20
44
  end
21
-
22
- # Creates a linear expression where the specified variable is subtracted
23
- # from this one.
24
- def -(var)
25
- Gecode::Constraints::Int::Linear::ExpressionNode.new(self,
26
- @model) - var
27
- end
28
- end
29
-
30
- module Constraints::Int
31
- class Expression #:nodoc:
32
- # Add some relation selection based on whether the expression is negated.
33
- alias_method :pre_linear_initialize, :initialize
34
- def initialize(model, params)
35
- pre_linear_initialize(model, params)
36
- unless params[:negate]
37
- @method_relations = Constraints::Util::RELATION_TYPES
38
- else
39
- @method_relations = Constraints::Util::NEGATED_RELATION_TYPES
40
- end
41
- end
42
-
43
- # Define the relation methods.
44
- Constraints::Util::RELATION_TYPES.each_key do |name|
45
- module_eval <<-"end_code"
46
- def #{name}(expression, options = {})
47
- relation = @method_relations[:#{name}]
48
- @params.update(
49
- Gecode::Constraints::Util.decode_options(options))
50
- if self.simple_expression? and simple_expression?(expression)
51
- # A relation constraint is enough.
52
- add_relation_constraint(relation, expression)
53
- else
54
- add_linear_constraint(relation, expression)
55
- end
56
- end
57
- end_code
58
- end
59
- alias_comparison_methods
60
-
61
- protected
62
-
63
- # Checks whether the given expression is simple enough to be used in a
64
- # simple relation constraint. Returns true if it is, false otherwise. If
65
- # no expression is given then the this expression's left hand side is
66
- # checked.
67
- def simple_expression?(expression = nil)
68
- if expression.nil?
69
- simple_expression?(@params[:lhs])
70
- else
71
- expression.kind_of?(Gecode::FreeIntVar) or
72
- expression.kind_of?(Gecode::FreeBoolVar) or
73
- expression.kind_of?(Fixnum)
74
- end
75
- end
76
-
77
- private
78
-
79
- # Places the linear constraint corresponding to the specified (integer)
80
- # relation type (as specified by Gecode) in relation to the specifed
81
- # expression.
82
- #
83
- # Raises TypeError if the element is of a type that doesn't allow a
84
- # relation to be specified.
85
- def add_linear_constraint(relation_type, right_hand_side)
86
- # Bind parameters.
87
- lhs = @params[:lhs]
88
- if lhs.kind_of?(Gecode::FreeIntVar) or lhs.kind_of?(Gecode::FreeBoolVar)
89
- lhs = lhs * 1 # Convert to Gecode::Raw::LinExp
90
- end
91
- if not (right_hand_side.respond_to? :to_minimodel_lin_exp or
92
- right_hand_side.kind_of?(Gecode::FreeIntVar) or
93
- right_hand_side.kind_of?(Gecode::FreeBoolVar) or
94
- right_hand_side.kind_of?(Fixnum))
95
- raise TypeError, 'Invalid right hand side of linear equation.'
96
- end
97
-
98
- @params.update(:relation_type => relation_type, :lhs => lhs,
99
- :rhs => right_hand_side)
100
- @model.add_constraint Linear::LinearConstraint.new(@model, @params)
45
+
46
+ private
47
+
48
+ # Performs the int linear expression operation +operator+ on self
49
+ # and +operand2+.
50
+ def int_linear_expression_operation(operator, operand2)
51
+ unless operand2.respond_to? :to_minimodel_lin_exp
52
+ operand2 = Linear::ExpressionNode.new operand2
101
53
  end
102
-
103
- # Places the relation constraint corresponding to the specified (integer)
104
- # relation type (as specified by Gecode) in relation to the specifed
105
- # element.
106
- def add_relation_constraint(relation_type, element)
107
- @model.add_constraint Linear::SimpleRelationConstraint.new(@model,
108
- @params.update(:relation_type => relation_type, :element => element))
54
+ operand1 = self
55
+ unless operand1.respond_to? :to_minimodel_lin_exp
56
+ operand1 = Linear::ExpressionNode.new(self, @model)
109
57
  end
58
+ Linear::ExpressionTree.new(operand1, operand2, operator)
110
59
  end
111
60
  end
112
-
61
+
113
62
  # A module that gathers the classes and modules used in linear constraints.
114
- module Constraints::Int::Linear #:nodoc:
115
- # Linear constraints specify that an integer variable must have a linear
116
- # equation containing variables must hold. The same relations and options
117
- # used in +SimpleRelationConstraint+ can also be used for linear
118
- # constraints.
119
- #
120
- # Boolean variables can also be used instead of integer variables. In that
121
- # case a boolean variable assigned true is equal to 1 and a boolean variable
122
- # assigned false is equal to 0. There is one exception: boolean variables
123
- # can not be used alone as left hand side.
124
- #
125
- # Do not mix boolean and integer variables. Even if possible it's not
126
- # supported, and might be removed in the future.
127
- #
128
- # == Examples
129
- #
130
- # # The sum of the int variables +x+ and +y+ must equal +z+ + 3.
131
- # (x + y).must == z + 3
132
- #
133
- # # Another way of writing the above.
134
- # z.must == x + y - 3
135
- #
136
- # # The inequality 10(x + y) > 3x must not hold.
137
- # (x + y)*10.must_not > x*3
138
- #
139
- # # Specifies the above, but reifies the constraint with the boolean
140
- # # variable +bool+ and gives it propagation strength +domain+.
141
- # (x + y)*10.must_not_be.greater_than(x*3, :reify => bool, :strength => :domain)
142
- class LinearConstraint < Gecode::Constraints::ReifiableConstraint
63
+ module Linear #:nodoc:
64
+ class LinearRelationConstraint < Gecode::ReifiableConstraint #:nodoc:
143
65
  def post
144
66
  lhs, rhs, relation_type, reif_var =
145
67
  @params.values_at(:lhs, :rhs, :relation_type, :reif)
146
- reif_var = reif_var.bind if reif_var.respond_to? :bind
147
- if rhs.respond_to? :to_minimodel_lin_exp
148
- rhs = rhs.to_minimodel_lin_exp
149
- elsif rhs.respond_to? :bind
150
- rhs = rhs.bind * 1
151
- end
152
-
153
- final_exp = (lhs.to_minimodel_lin_exp - rhs)
68
+ reif_var = reif_var.to_bool_var.bind if reif_var.respond_to? :to_bool_var
69
+ final_exp = (lhs.to_minimodel_lin_exp - rhs.to_minimodel_lin_exp)
154
70
  if reif_var.nil?
155
71
  final_exp.post(@model.active_space, relation_type,
156
72
  *propagation_options)
@@ -161,102 +77,18 @@ module Gecode
161
77
  end
162
78
  end
163
79
 
164
- # Simple relation constraints specify that an integer variable must have a
165
- # specified relation to a constant integer or another integer variable. The
166
- # following relations are supported (the aliases of each relation are also
167
- # listed).
168
- #
169
- # * <, lesser, lesser_than
170
- # * >, greater, greater_than
171
- # * >=, greater_or_equal, greater_than_or_equal_to
172
- # * <=, less_or_equal, less_than_or_equal_to
173
- # * ==, equal, equal_to
174
- #
175
- # Each can be negated by using +must_not+ instead of +must+.
176
- #
177
- # Two options (given as a hash) are available:
178
- #
179
- # [strength] Specifies the propagation strength of the constraint. Must be
180
- # one of +value+, +bounds+, +domain+ and +default+. The
181
- # strength generally progresses as +value+ -> +bounds+ ->
182
- # +domain+ (+value+ being the weakest, but usually cheapest,
183
- # while +domain+ is the strongest but usually costly).
184
- # [reify] Specifies a boolean variable that should be used for
185
- # reification (see +ReifiableConstraint+).
186
- #
187
- # == Examples
188
- #
189
- # # Int variable +x+ must not equal 0.
190
- # x.must_not.equal(0)
191
- #
192
- # # Another way of writing the above.
193
- # x.must_not == 0
194
- #
195
- # # +x+ must be strictly larger than +y+.
196
- # x.must > y
197
- #
198
- # # Specifies the above, but reifies the constraint with the boolean
199
- # # variable +bool+.
200
- # x.must_be.greater_than(y, :reify => bool)
201
- class SimpleRelationConstraint < Gecode::Constraints::ReifiableConstraint
202
- def post
203
- # Fetch the parameters to Gecode.
204
- lhs, relation, rhs, reif_var =
205
- @params.values_at(:lhs, :relation_type, :element, :reif)
206
-
207
- rhs = rhs.bind if rhs.respond_to? :bind
208
- if reif_var.nil?
209
- Gecode::Raw::rel(@model.active_space, lhs.bind, relation, rhs,
210
- *propagation_options)
211
- else
212
- Gecode::Raw::rel(@model.active_space, lhs.bind, relation, rhs,
213
- reif_var.bind, *propagation_options)
214
- end
215
- end
216
- end
217
-
218
- # Helper methods for linear expressions. Classes mixing in this module must
219
- # have a method #model which gives the model the expression is operating in.
220
- module Helper #:nodoc:
221
- include Gecode::Constraints::LeftHandSideMethods
222
-
223
- private
224
-
225
- OPERATION_TYPES = [:+, :-, :*]
226
-
227
- public
228
-
229
- # Define methods for the available operations.
230
- OPERATION_TYPES.each do |name|
231
- module_eval <<-"end_code"
232
- def #{name}(expression)
233
- unless expression.kind_of? ExpressionTree
234
- expression = ExpressionNode.new(expression)
235
- end
236
- ExpressionTree.new(self, expression, :#{name})
237
- end
238
- end_code
239
- end
240
-
241
- private
242
-
243
- # Produces an expression for the lhs module.
244
- def expression(params)
245
- params.update(:lhs => self)
246
- Gecode::Constraints::Int::Expression.new(model, params)
247
- end
248
- end
249
-
250
80
  # Describes a binary tree of expression nodes which together form a linear
251
81
  # expression.
252
- class ExpressionTree #:nodoc:
253
- include Helper
254
-
255
- # Constructs a new expression with the specified variable
82
+ class ExpressionTree < Gecode::Int::ShortCircuitRelationsOperand #:nodoc:
83
+ attr :model
84
+
85
+ # Constructs a new expression with the specified operands.
256
86
  def initialize(left_node, right_node, operation)
87
+ super(left_node.model || right_node.model)
257
88
  @left = left_node
258
89
  @right = right_node
259
90
  @operation = operation
91
+ @model = @left.model || @right.model
260
92
  end
261
93
 
262
94
  # Converts the linear expression to an instance of
@@ -264,20 +96,35 @@ module Gecode
264
96
  def to_minimodel_lin_exp
265
97
  @left.to_minimodel_lin_exp.send(@operation, @right.to_minimodel_lin_exp)
266
98
  end
267
-
268
- # Fetches the space that the expression's variables is in.
269
- def model
270
- @left.model || @right.model
99
+
100
+ def relation_constraint(relation, int_operand_or_fix, params)
101
+ unless params[:negate]
102
+ relation_type =
103
+ Gecode::Util::RELATION_TYPES[relation]
104
+ else
105
+ relation_type =
106
+ Gecode::Util::NEGATED_RELATION_TYPES[relation]
107
+ end
108
+
109
+ unless int_operand_or_fix.respond_to? :to_minimodel_lin_exp
110
+ int_operand_or_fix = Linear::ExpressionNode.new(int_operand_or_fix);
111
+ end
112
+
113
+ params.update(:lhs => self, :rhs => int_operand_or_fix,
114
+ :relation_type => relation_type)
115
+ LinearRelationConstraint.new(model, params)
271
116
  end
272
117
  end
273
118
 
274
119
  # Describes a single node in a linear expression.
275
120
  class ExpressionNode #:nodoc:
276
- include Helper
277
-
278
121
  attr :model
279
122
 
280
123
  def initialize(value, model = nil)
124
+ unless value.respond_to?(:to_int_var) or value.kind_of?(Fixnum)
125
+ raise TypeError, 'Expected int operand or fixnum, ' +
126
+ "got #{value.class}."
127
+ end
281
128
  @value = value
282
129
  @model = model
283
130
  end
@@ -286,12 +133,11 @@ module Gecode
286
133
  # Gecode::Raw::MiniModel::LinExpr
287
134
  def to_minimodel_lin_exp
288
135
  expression = @value
289
- if expression.respond_to? :bind
290
- # Minimodel requires that we do this first.
291
- expression = expression.bind * 1
136
+ if expression.respond_to? :to_int_var
137
+ expression = expression.to_int_var.bind * 1
292
138
  end
293
139
  expression
294
140
  end
295
141
  end
296
142
  end
297
- end
143
+ end
@@ -0,0 +1,141 @@
1
+ module Gecode::Int
2
+ class IntConstraintReceiver
3
+ # Constrains the integer operand to equal +int_operand_or_fixnum+.
4
+ # #equal and #equal_to are aliases of this method.
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # +int1+ must equal +int2+
9
+ # int1.must == int2
10
+ #
11
+ # # +int+ must equal 17
12
+ # int.must == 17
13
+ #
14
+ # # +int1+ must equal +int2+. We reify the constraint with
15
+ # # +bool+ and select +domain+ as strength.
16
+ # int1.must.equal(int2, :reify => bool, :strength => :domain)
17
+ def ==(int_operand_or_fixnum, options = {})
18
+ comparison(:==, int_operand_or_fixnum, options)
19
+ end
20
+
21
+ # Constrains the integer operand to be strictly greater than
22
+ # +int_operand_or_fixnum+. #greater and #greater_than are
23
+ # aliases of this method.
24
+ #
25
+ # ==== Examples
26
+ #
27
+ # # +int1+ must be strictly greater than +int2+
28
+ # int1.must > int2
29
+ #
30
+ # # +int+ must be strictly greater than 17
31
+ # int.must > 17
32
+ #
33
+ # # +int1+ must be strictly greater than +int2+. We reify the
34
+ # # constraint with +bool+ and select +domain+ as strength.
35
+ # int1.must_be.greater_than(int2, :reify => bool, :strength => :domain)
36
+ def >(int_operand_or_fixnum, options = {})
37
+ comparison(:>, int_operand_or_fixnum, options)
38
+ end
39
+
40
+ # Constrains the integer operand to be greater than or equal to
41
+ # +int_operand_or_fixnum+. #greater_or_equal and
42
+ # #greater_than_or_equal_to are aliases of this method.
43
+ #
44
+ # ==== Examples
45
+ #
46
+ # # +int1+ must be greater than or equal to +int2+
47
+ # int1.must >= int2
48
+ #
49
+ # # +int+ must be greater than or equal to 17
50
+ # int.must >= 17
51
+ #
52
+ # # +int1+ must be greater than or equal to +int2+. We reify the
53
+ # # constraint with +bool+ and select +domain+ as strength.
54
+ # int1.must.greater_or_equal(int2, :reify => bool, :strength => :domain)
55
+ def >=(int_operand_or_fixnum, options = {})
56
+ comparison(:>=, int_operand_or_fixnum, options)
57
+ end
58
+
59
+ # Constrains the integer operand to be strictly less than
60
+ # +int_operand_or_fixnum+. #lesser and #lesser_than are
61
+ # aliases of this method.
62
+ #
63
+ # ==== Examples
64
+ #
65
+ # # +int1+ must be strictly less than +int2+
66
+ # int1.must < int2
67
+ #
68
+ # # +int+ must be strictly less than 17
69
+ # int.must < 17
70
+ #
71
+ # # +int1+ must be strictly less than +int2+. We reify the
72
+ # # constraint with +bool+ and select +domain+ as strength.
73
+ # int1.must_be.less_than(int2, :reify => bool, :strength => :domain)
74
+ def <(int_operand_or_fixnum, options = {})
75
+ comparison(:<, int_operand_or_fixnum, options)
76
+ end
77
+
78
+ # Constrains the integer operand to be less than or equal to
79
+ # +int_operand_or_fixnum+. #less_or_equal and
80
+ # #less_than_or_equal_to are aliases of this method.
81
+ #
82
+ # ==== Examples
83
+ #
84
+ # # +int1+ must be less than or equal to +int2+
85
+ # int1.must <= int2
86
+ #
87
+ # # +int+ must be less than or equal to 17
88
+ # int.must <= 17
89
+ #
90
+ # # +int1+ must be less than or equal to +int2+. We reify the
91
+ # # constraint with +bool+ and select +domain+ as strength.
92
+ # int1.must.less_or_equal(int2, :reify => bool, :strength => :domain)
93
+ def <=(int_operand_or_fixnum, options = {})
94
+ comparison(:<=, int_operand_or_fixnum, options)
95
+ end
96
+
97
+ alias_comparison_methods
98
+
99
+ private
100
+
101
+ # Helper for the comparison methods. The reason that they are not
102
+ # generated in a loop is that it would mess up the RDoc.
103
+ def comparison(name, int_operand_or_fixnum, options)
104
+ unless int_operand_or_fixnum.respond_to?(:to_int_var) or
105
+ int_operand_or_fixnum.kind_of?(Fixnum)
106
+ raise TypeError, "Expected int operand or integer, got " +
107
+ "#{int_operand_or_fixnum.class}."
108
+ end
109
+
110
+ unless @params[:negate]
111
+ relation_type = Gecode::Util::RELATION_TYPES[name]
112
+ else
113
+ relation_type = Gecode::Util::NEGATED_RELATION_TYPES[name]
114
+ end
115
+ @params.update Gecode::Util.decode_options(options)
116
+ @model.add_constraint Relation::RelationConstraint.new(@model,
117
+ @params.update(:relation_type => relation_type,
118
+ :rhs => int_operand_or_fixnum))
119
+ end
120
+ end
121
+
122
+ # A module that gathers the classes and modules used in relation constraints.
123
+ module Relation #:nodoc:
124
+ class RelationConstraint < Gecode::ReifiableConstraint #:nodoc:
125
+ def post
126
+ # Fetch the parameters to Gecode.
127
+ lhs, relation, rhs, reif_var =
128
+ @params.values_at(:lhs, :relation_type, :rhs, :reif)
129
+
130
+ rhs = rhs.to_int_var.bind if rhs.respond_to? :to_int_var
131
+ if reif_var.nil?
132
+ Gecode::Raw::rel(@model.active_space, lhs.to_int_var.bind,
133
+ relation, rhs, *propagation_options)
134
+ else
135
+ Gecode::Raw::rel(@model.active_space, lhs.to_int_var.bind,
136
+ relation, rhs, reif_var.to_bool_var.bind, *propagation_options)
137
+ end
138
+ end
139
+ end
140
+ end
141
+ end
@@ -1,72 +1,63 @@
1
- module Gecode::IntEnumMethods
2
- # Starts an arithmetic max constraint. This overrides the normal enum max, but
3
- # that's not a problem since variables are not implemented to be comparable.
4
- def max
5
- return Gecode::Constraints::IntEnum::Arithmetic::MaxExpressionStub.new(
6
- @model, :lhs => self)
7
- end
8
-
9
- # Starts an arithmetic min constraint. This overrides the normal enum min, but
10
- # that's not a problem since variables are not implemented to be comparable.
11
- def min
12
- return Gecode::Constraints::IntEnum::Arithmetic::MinExpressionStub.new(
13
- @model, :lhs => self)
1
+ module Gecode::IntEnum
2
+ module IntEnumOperand
3
+ # Produces an IntOperand representing the maximum value of the
4
+ # integer operands in this enumeration.
5
+ #
6
+ # ==== Examples
7
+ #
8
+ # # The maximum of +int_enum+.
9
+ # int_enum.max
10
+ def max
11
+ Arithmetic::IntEnumMaxOperand.new(@model, self)
12
+ end
13
+
14
+ # Produces an IntOperand representing the minimum value of the
15
+ # integer operands in this enumeration.
16
+ #
17
+ # ==== Examples
18
+ #
19
+ # # The minimum of +int_enum+.
20
+ # int_enum.min
21
+ def min
22
+ Arithmetic::IntEnumMinOperand.new(@model, self)
23
+ end
14
24
  end
15
- end
16
25
 
17
- # A module that gathers the classes and modules used by arithmetic constraints.
18
- module Gecode::Constraints::IntEnum::Arithmetic #:nodoc:
19
- # Describes a CompositeStub for the max constraint, which constrains the
20
- # maximum value of the integer variables in an enumeration.
21
- #
22
- # == Example
23
- #
24
- # # The maximum must be positive.
25
- # int_enum.max.must > 0
26
- #
27
- # # The maximum must equal a integer variable +max+.
28
- # int_enum.max.must == max
29
- #
30
- # # The maximum must not be negative. The constraint is reified with the
31
- # # boolean variable +is_negative+ and strength +domain+ is selected.
32
- # int_enum.max.must_not_be.less_than(0, :reify => is_negative,
33
- # :strength => :domain)
34
- class MaxExpressionStub < Gecode::Constraints::Int::CompositeStub
35
- def constrain_equal(variable, params, constrain)
36
- enum = @params[:lhs]
37
- if constrain
38
- variable.must_be.in enum.domain_range
26
+ # A module that gathers the classes and modules used by arithmetic
27
+ # constraints.
28
+ module Arithmetic #:nodoc:
29
+ class IntEnumMaxOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc:
30
+ def initialize(model, int_enum)
31
+ super model
32
+ @int_enum = int_enum
33
+ end
34
+
35
+ def constrain_equal(int_operand, constrain, propagation_options)
36
+ enum = @int_enum.to_int_enum
37
+ if constrain
38
+ int_operand.must_be.in enum.domain_range
39
+ end
40
+
41
+ Gecode::Raw::max(@model.active_space, enum.bind_array,
42
+ int_operand.to_int_var.bind, *propagation_options)
39
43
  end
40
-
41
- Gecode::Raw::max(@model.active_space, enum.to_int_var_array,
42
- variable.bind, *propagation_options)
43
44
  end
44
- end
45
-
46
- # Describes a CompositeStub for the min constraint, which constrains the
47
- # minimum value of the integer variables in an enumeration.
48
- #
49
- # == Example
50
- #
51
- # # The minimum must be positive.
52
- # int_enum.min.must > 0
53
- #
54
- # # The minimum must equal a integer variable +min+.
55
- # int_enum.min.must == min
56
- #
57
- # # The minimum must not be non-positive. The constraint is reified with the
58
- # # boolean variable +is_positive+ and strength +domain+ is selected.
59
- # int_enum.min.must_not_be.less_or_equal(0, :reify => is_positive,
60
- # :strength => :domain)
61
- class MinExpressionStub < Gecode::Constraints::Int::CompositeStub
62
- def constrain_equal(variable, params, constrain)
63
- enum = @params[:lhs]
64
- if constrain
65
- variable.must_be.in enum.domain_range
45
+
46
+ class IntEnumMinOperand < Gecode::Int::ShortCircuitEqualityOperand #:nodoc:
47
+ def initialize(model, int_enum)
48
+ super model
49
+ @int_enum = int_enum
50
+ end
51
+
52
+ def constrain_equal(int_operand, constrain, propagation_options)
53
+ enum = @int_enum.to_int_enum
54
+ if constrain
55
+ int_operand.must_be.in enum.domain_range
56
+ end
57
+
58
+ Gecode::Raw::min(@model.active_space, enum.bind_array,
59
+ int_operand.to_int_var.bind, *propagation_options)
66
60
  end
67
-
68
- Gecode::Raw::min(@model.active_space, enum.to_int_var_array,
69
- variable.bind, *propagation_options)
70
61
  end
71
62
  end
72
63
  end