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
@@ -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
@@ -0,0 +1,117 @@
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::Relation, " (#{relation})" do
7
+ before do
8
+ @model = Gecode::Model.new
9
+ @set = @model.set_var([0], 0..3)
10
+ @set2 = @model.set_var([1], 0..3)
11
+ @model.branch_on @model.wrap_enum([@set, @set2])
12
+
13
+ @types = [:set, :set]
14
+ @invoke = lambda do |receiver, set_op, hash|
15
+ receiver.method(relation).call(set_op, hash)
16
+ @model.solve!
17
+ end
18
+ @expect = lambda do |var1, var2, opts, reif_var|
19
+ if reif_var.nil?
20
+ Gecode::Raw.should_receive(:rel).once.with(
21
+ an_instance_of(Gecode::Raw::Space),
22
+ var1, type, var2)
23
+ else
24
+ Gecode::Raw.should_receive(:rel).once.with(
25
+ an_instance_of(Gecode::Raw::Space),
26
+ var1, type, var2, reif_var)
27
+ end
28
+ end
29
+ end
30
+
31
+ it "should correctly constrain the set when #{relation} is used" do
32
+ @set = @model.set_var if relation == :complement
33
+ @set.must.method(relation).call(@set2)
34
+ @model.solve!
35
+ @set.should be_assigned
36
+ @set2.should be_assigned
37
+ case relation
38
+ when :superset
39
+ (@set2.value.to_a - @set.value.to_a).should be_empty
40
+ when :subset
41
+ (@set.value.to_a - @set2.value.to_a).should be_empty
42
+ when :complement
43
+ val = @set.value
44
+ val.min.should == Gecode::Model::SET_MIN_INT
45
+ val.max.should == Gecode::Model::SET_MAX_INT
46
+ @set2.value.each do |element|
47
+ @set.not_in_upper_bound?(element).should be_true
48
+ end
49
+ when :disjoint
50
+ (@set2.value.to_a & @set.value.to_a).should be_empty
51
+ end
52
+ end
53
+
54
+ it "should correctly constrain the set when negated #{relation} is used" do
55
+ @set.must_not.method(relation).call(@set2)
56
+ @model.solve!
57
+ @set.should be_assigned
58
+ @set2.should be_assigned
59
+ case relation
60
+ when :superset
61
+ (@set2.value.to_a - @set.value.to_a).should_not be_empty
62
+ when :subset
63
+ (@set.value.to_a - @set2.value.to_a).should_not be_empty
64
+ when :complement
65
+ val = @set.value
66
+ ((val.min != Gecode::Model::SET_MIN_INT) ||
67
+ (val.max != Gecode::Model::SET_MAX_INT) ||
68
+ @set.value.to_a.any?{ |element| @set.in_lower_bound?(element) }
69
+ ).should be_true
70
+ when :disjoint
71
+ (@set.value.to_a & @set.value.to_a).should_not be_empty
72
+ end
73
+ end
74
+
75
+ it_should_behave_like 'reifiable set constraint'
76
+ end
77
+ end
78
+
79
+ describe Gecode::Set::Relation, ' (equality)' do
80
+ before do
81
+ @model = Gecode::Model.new
82
+ @set = @model.set_var([0], 0..1)
83
+ @set2 = @model.set_var([1], 0..1)
84
+ @model.branch_on @model.wrap_enum([@set, @set2])
85
+
86
+ @types = [:set, :set]
87
+ @invoke = lambda do |receiver, set_op, hash|
88
+ receiver.equal(set_op, hash)
89
+ @model.solve!
90
+ end
91
+ @expect = lambda do |var1, var2, opts, reif_var|
92
+ if reif_var.nil?
93
+ Gecode::Raw.should_receive(:rel).once.with(
94
+ an_instance_of(Gecode::Raw::Space),
95
+ var1, Gecode::Raw::SRT_EQ, var2)
96
+ else
97
+ Gecode::Raw.should_receive(:rel).once.with(
98
+ an_instance_of(Gecode::Raw::Space),
99
+ var1, Gecode::Raw::SRT_EQ, var2, reif_var)
100
+ end
101
+ end
102
+ end
103
+
104
+ it 'should constrain sets to be equal' do
105
+ @set.must == @set2
106
+ @model.solve!
107
+ @set.value.to_a.should == @set2.value.to_a
108
+ end
109
+
110
+ it 'should constrain sets to not be equal when negated' do
111
+ @set.must_not == @set2
112
+ @model.solve!
113
+ @set.value.to_a.should_not == @set2.value.to_a
114
+ end
115
+
116
+ it_should_behave_like 'reifiable set constraint'
117
+ end
@@ -0,0 +1,84 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
4
+ describe Gecode::SetElements::Relation, " (#{relation} with int op)" do
5
+ before do
6
+ @model = Gecode::Model.new
7
+ @set = @model.set_var([0], 0..2)
8
+ @int = @model.int_var(-1..2)
9
+ @model.branch_on @set
10
+ @model.branch_on @int
11
+
12
+ # For constraint spec.
13
+ @types = [:set_elements, :int]
14
+ @invoke = lambda do |receiver, op, hash|
15
+ receiver.method(relation).call(op, hash)
16
+ @model.solve!
17
+ end
18
+ @expect = lambda do |var1, var2, opts, reif_var|
19
+ Gecode::Raw.should_receive(:rel).once.with(
20
+ an_instance_of(Gecode::Raw::Space),
21
+ var1, rel_value, var2)
22
+ end
23
+ end
24
+
25
+ it "should constrain the elements of the set when #{relation} is used" do
26
+ @set.elements.must.method(relation).call(@int)
27
+ @model.solve!
28
+ @set.value.each do |i|
29
+ i.should.method(relation).call(@int.value)
30
+ end
31
+ end
32
+
33
+ it "should constrain the elements of the set when negated #{relation} is used" do
34
+ @set.elements.must_not.method(relation).call(@int)
35
+ @model.solve!
36
+ @set.value.each do |i|
37
+ i.should_not.method(relation).call(@int.value)
38
+ end
39
+ end
40
+
41
+ it_should_behave_like 'non-reifiable set constraint'
42
+ end
43
+ end
44
+
45
+ Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
46
+ describe Gecode::SetElements::Relation, " (#{relation} with fixnum)" do
47
+ before do
48
+ @model = Gecode::Model.new
49
+ @set = @model.set_var([], 0..2)
50
+ @int_constant = 1
51
+ @model.branch_on @set
52
+
53
+ # For constraint spec.
54
+ @types = [:set_elements]
55
+ @invoke = lambda do |receiver, hash|
56
+ receiver.method(relation).call(@int_constant, hash)
57
+ @model.solve!
58
+ end
59
+ @expect = lambda do |var1, var2, opts, reif_var|
60
+ Gecode::Raw.should_receive(:rel).once.with(
61
+ an_instance_of(Gecode::Raw::Space),
62
+ var1, rel_value, an_instance_of(Gecode::Raw::IntVar))
63
+ end
64
+ end
65
+
66
+ it "should constrain the elements of the set when #{relation} is used" do
67
+ @set.elements.must.method(relation).call(@int_constant)
68
+ @model.solve!
69
+ @set.value.each do |i|
70
+ i.should.method(relation).call(@int_constant)
71
+ end
72
+ end
73
+
74
+ it "should constrain the elements of the set when negated #{relation} is used" do
75
+ @set.elements.must_not.method(relation).call(@int_constant)
76
+ @model.solve!
77
+ @set.value.each do |i|
78
+ i.should_not.method(relation).call(@int_constant)
79
+ end
80
+ end
81
+
82
+ it_should_behave_like 'non-reifiable set constraint'
83
+ end
84
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ class ChannelSampleProblem < Gecode::Model
4
+ attr :elements
5
+ attr :positions
6
+ attr :sets
7
+
8
+ def initialize
9
+ @elements = int_var_array(4, 0..3)
10
+ @elements.must_be.distinct
11
+ @positions = int_var_array(4, 0..3)
12
+ @positions.must_be.distinct
13
+ @sets = set_var_array(4, [], 0..3)
14
+ branch_on @positions
15
+ end
16
+ end
17
+
18
+ describe Gecode::SetEnum::Channel::IntEnumChannelConstraint, ' (channel with set as right hand side)' do
19
+ before do
20
+ @model = ChannelSampleProblem.new
21
+ @positions = @model.positions
22
+ @sets = @model.sets
23
+
24
+ @types = [:int_enum, :set_enum]
25
+ @invoke = lambda do |receiver, set_enum, hash|
26
+ receiver.channel(set_enum, hash)
27
+ @model.solve!
28
+ end
29
+ @expect = lambda do |var1, var2, opts, reif_var|
30
+ Gecode::Raw.should_receive(:channel).once.with(
31
+ an_instance_of(Gecode::Raw::Space),
32
+ var1, var2)
33
+ end
34
+ end
35
+
36
+ it 'should constrain variables to be channelled' do
37
+ @positions.must.channel @sets
38
+ @model.solve!
39
+ sets = @model.sets
40
+ positions = @model.positions.values
41
+ positions.each_with_index do |position, i|
42
+ sets[position].value.should include(i)
43
+ end
44
+ end
45
+
46
+ it_should_behave_like 'non-reifiable set constraint'
47
+ it_should_behave_like 'non-negatable constraint'
48
+ end
49
+
50
+ describe Gecode::SetEnum::Channel::IntEnumChannelConstraint, ' (channel with set as left hand side)' do
51
+ before do
52
+ @model = ChannelSampleProblem.new
53
+ @positions = @model.positions
54
+ @sets = @model.sets
55
+
56
+ @types = [:set_enum, :int_enum]
57
+ @invoke = lambda do |receiver, int_enum, hash|
58
+ receiver.channel(int_enum, hash)
59
+ @model.solve!
60
+ end
61
+ @expect = lambda do |var1, var2, opts, reif_var|
62
+ Gecode::Raw.should_receive(:channel).once.with(
63
+ an_instance_of(Gecode::Raw::Space),
64
+ var2, var1)
65
+ end
66
+ end
67
+
68
+ it 'should constrain variables to be channelled' do
69
+ @sets.must.channel @positions
70
+ @model.solve!
71
+ sets = @model.sets
72
+ positions = @model.positions.values
73
+ positions.each_with_index do |position, i|
74
+ sets[position].value.should include(i)
75
+ end
76
+ end
77
+
78
+ it_should_behave_like 'non-reifiable set constraint'
79
+ it_should_behave_like 'non-negatable constraint'
80
+ end
@@ -0,0 +1,59 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ class SetEnumDistinctSampleProblem < Gecode::Model
4
+ attr :vars
5
+ attr :sets
6
+
7
+ def initialize
8
+ @vars = int_var_array(2, 1)
9
+ @sets = set_var_array(2, [], 0..2)
10
+ branch_on @sets
11
+ end
12
+ end
13
+
14
+ describe Gecode::SetEnum::Distinct, ' (at most one)' do
15
+ before do
16
+ @model = SetEnumDistinctSampleProblem.new
17
+ @sets = @model.sets
18
+ @size = 2
19
+
20
+ @types = [:set_enum]
21
+ @invoke = lambda do |receiver, hash|
22
+ receiver.at_most_share_one_element hash.update(:size => @size)
23
+ @model.solve!
24
+ end
25
+ @expect = lambda do |var, opts, reif_var|
26
+ Gecode::Raw.should_receive(:atmostOne).once.with(
27
+ an_instance_of(Gecode::Raw::Space),
28
+ var, @size)
29
+ end
30
+ end
31
+
32
+ it 'should translate into a atmostOne constraint' do
33
+ Gecode::Raw.should_receive(:atmostOne).once.with(
34
+ an_instance_of(Gecode::Raw::Space),
35
+ an_instance_of(Gecode::Raw::SetVarArray), @size)
36
+ @sets.must.at_most_share_one_element(:size => @size)
37
+ @model.solve!
38
+ end
39
+
40
+ it 'should constrain sets to have at most one element in common' do
41
+ @sets.must.at_most_share_one_element(:size => @size)
42
+ @sets[0].must_not_be.superset_of 0
43
+ solution = @model.solve!
44
+ solution.should_not be_nil
45
+ set1, set2 = solution.sets
46
+ set1.value.size.should == @size
47
+ set2.value.size.should == @size
48
+ (set1.value.to_a & set2.value.to_a).size.should <= 1
49
+ end
50
+
51
+ it 'should raise error if :size is not specified' do
52
+ lambda do
53
+ @sets.must.at_most_share_one_element
54
+ end.should raise_error(ArgumentError)
55
+ end
56
+
57
+ it_should_behave_like 'non-reifiable set constraint'
58
+ it_should_behave_like 'non-negatable constraint'
59
+ end
@@ -0,0 +1,111 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ # Assumes that @operation, @set and @set_enum are defined.
4
+ describe 'set enum operation property', :shared => true do
5
+ before do
6
+ @property_types = [:set_enum]
7
+ @select_property = lambda do |set_enum|
8
+ set_enum.method(@operation).call
9
+ end
10
+ @selected_property = @set_enum.method(@operation).call
11
+
12
+ @constraint_class = Gecode::BlockConstraint
13
+ end
14
+
15
+ it "should translate #{@operation} into an operand constraint" do
16
+ operation_type = Gecode::Util::SET_OPERATION_TYPES[@operation]
17
+ @model.allow_space_access do
18
+ Gecode::Raw.should_receive(:rel).with(
19
+ an_instance_of(Gecode::Raw::Space), operation_type,
20
+ @set_enum.bind_array, @set.bind)
21
+ end
22
+ @set_enum.method(@operation).call.must == @set
23
+ @model.solve!
24
+ end
25
+
26
+ it_should_behave_like(
27
+ 'property that produces set operand by short circuiting equality')
28
+ end
29
+
30
+ describe Gecode::SetEnum::Operation, ' (union)' do
31
+ before do
32
+ @model = Gecode::Model.new
33
+ @set_enum = @sets = @model.set_var_array(10, [], 0..20)
34
+ @set = @model.set_var([], 0..20)
35
+ @model.branch_on @sets
36
+
37
+ @operation = :union
38
+ end
39
+
40
+ it 'should constrain the union of the sets' do
41
+ @sets.union.must_be.subset_of [1,4,17]
42
+ @sets.union.must_be.superset_of 1
43
+ @model.solve!.should_not be_nil
44
+ union = @sets.values.inject([]){ |union, set| union += set.to_a }.uniq
45
+ union.should include(1)
46
+ (union - [1,4,17]).should be_empty
47
+ end
48
+
49
+ it_should_behave_like 'set enum operation property'
50
+ end
51
+
52
+ describe Gecode::SetEnum::Operation, ' (intersection)' do
53
+ before do
54
+ @model = Gecode::Model.new
55
+ @set_enum = @sets = @model.set_var_array(10, [], 0..20)
56
+ @set = @model.set_var([], 0..20)
57
+ @model.branch_on @sets
58
+
59
+ @operation = :intersection
60
+ end
61
+
62
+ it 'should constrain the intersection of the sets' do
63
+ @sets.intersection.must_be.subset_of [1,4,17]
64
+ @sets.intersection.must_be.superset_of [1]
65
+ @model.solve!.should_not be_nil
66
+ intersection = @sets.values.inject(nil) do |intersection, set|
67
+ next set.to_a if intersection.nil?
68
+ intersection &= set.to_a
69
+ end.uniq
70
+ intersection.should include(1)
71
+ (intersection - [1,4,17]).should be_empty
72
+ end
73
+
74
+ it_should_behave_like 'set enum operation property'
75
+ end
76
+
77
+ describe Gecode::SetEnum::Operation, ' (disjoint union)' do
78
+ before do
79
+ @model = Gecode::Model.new
80
+ @set_enum = @sets = @model.set_var_array(10, [], 0..20)
81
+ @set = @model.set_var([], 0..20)
82
+ @model.branch_on @sets
83
+
84
+ @operation = :disjoint_union
85
+ end
86
+
87
+ it 'should constrain the disjoint union of the sets' do
88
+ @sets.disjoint_union.must_be.subset_of [1,4,17]
89
+ @sets.disjoint_union.must_be.superset_of [1]
90
+ @model.solve!.should_not be_nil
91
+ disjoint_union = @sets.values.inject([]) do |union, set|
92
+ unless union.any?{ |x| set.to_a.include? x }
93
+ union += set.to_a
94
+ end
95
+ end.uniq
96
+ disjoint_union.should include(1)
97
+ (disjoint_union - [1,4,17]).should be_empty
98
+ end
99
+
100
+ it 'should constrain the disjoint union of the sets (2)' do
101
+ @sets.disjoint_union.must_be.subset_of [1,4,17]
102
+ @sets.disjoint_union.must_be.superset_of [1]
103
+ @sets[0].must_be.superset_of [1]
104
+ @sets[1].must_be.superset_of [1]
105
+ lambda do
106
+ @model.solve!
107
+ end.should raise_error(Gecode::NoSolutionError)
108
+ end
109
+
110
+ it_should_behave_like 'set enum operation property'
111
+ end
@@ -0,0 +1,73 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ class SelectionSampleProblem < Gecode::Model
4
+ attr :sets
5
+ attr :set
6
+ attr :target
7
+ attr :index
8
+
9
+ def initialize
10
+ @sets = set_var_array(3, [], 0..20)
11
+ @set = set_var([], 0...3)
12
+ @target = set_var([], 0..20)
13
+ @index = int_var(0...3)
14
+ branch_on wrap_enum([@index])
15
+ branch_on @sets
16
+ end
17
+ end
18
+
19
+ # Requires everything that composite behaviour spec requires in addition to
20
+ # @stub and @expect_constrain_equal .
21
+ describe 'selection constraint', :shared => true do
22
+ it 'should not disturb normal array access' do
23
+ @sets[0].should be_kind_of(Gecode::SetVar)
24
+ end
25
+ end
26
+
27
+ describe Gecode::SetEnum::Select, ' (int operand)' do
28
+ include GecodeR::Specs::SetHelper
29
+
30
+ before do
31
+ @model = SelectionSampleProblem.new
32
+ @sets = @model.sets
33
+ @target = @set = @model.target
34
+ @index = @model.index
35
+ @model.branch_on @model.wrap_enum([@set])
36
+ @stub = @sets[@index]
37
+
38
+ @property_types = [:set_enum, :int]
39
+ @select_property = lambda do |set_enum, int|
40
+ set_enum[int]
41
+ end
42
+ @selected_property = @sets[@index]
43
+ @constraint_class = Gecode::BlockConstraint
44
+ end
45
+
46
+ it 'should constrain the specified element of an enum of sets' do
47
+ @sets[@index].must_be.superset_of([5,7,9])
48
+ @model.solve!
49
+ @sets[@index.value].value.should include(5,7,9)
50
+ end
51
+
52
+ it 'should translate into a select constraint' do
53
+ Gecode::Raw.should_receive(:selectSet)
54
+ @sets[@index].must_be.superset_of([5,7,9])
55
+ @model.solve!
56
+ end
57
+
58
+ it_should_behave_like 'selection constraint'
59
+ it_should_behave_like(
60
+ 'property that produces set operand by short circuiting equality')
61
+ end
62
+
63
+ describe Gecode::SetEnum::Select, ' (set operand)' do
64
+ before do
65
+ @model = SelectionSampleProblem.new
66
+ @sets = @model.sets
67
+ @set = @model.set
68
+ end
69
+
70
+ it 'should produce a selected set operand' do
71
+ @sets[@set].should be_respond_to(:to_selected_set)
72
+ end
73
+ end