gecoder-with-gecode 0.8.3 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
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,443 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ # Every property should have a spec that specs the following:
4
+ #
5
+ # * An example where the property is used to constrain a sample problem.
6
+ # * should_behave_like foo operand
7
+ # * A test that the property is translated to the correct Gecode
8
+ # constraint if deemed necessary.
9
+
10
+ # Several of these shared specs requires one or more of the following instance
11
+ # variables to be used:
12
+ # [@operand] The operand that is being tested.
13
+ # [@model] The model that defines the context in which the test is
14
+ # conducted.
15
+ # [@property_types] An array of symbols signaling what types of
16
+ # arguments @select_property accepts. The symbols
17
+ # must be one of: :int, :bool, :set, :int_enum,
18
+ # :bool_enum, :set_enum, :fixnum_enum.
19
+ # [@select_property] A proc that selects the property under test. It
20
+ # should take at least one argument: the operand that
21
+ # the property should be selected from.
22
+ # [@selected_property] The resulting operand of the property. It should
23
+ # be constrained to the degree that it has a
24
+ # non-maximal domain.
25
+ # [@constraint_class] The class of the constraints that are expected to be
26
+ # produced when a constraint is short circuited.
27
+ #
28
+
29
+
30
+ # Requires @operand and @model.
31
+ describe 'int var operand', :shared => true do
32
+ it 'should implement #model' do
33
+ @operand.model.should be_kind_of(Gecode::Model)
34
+ end
35
+
36
+ it 'should implement #to_int_var' do
37
+ int_var = @operand.to_int_var
38
+ int_var.should be_kind_of(Gecode::IntVar)
39
+ @model.solve!
40
+ (int_var.min..int_var.max).should_not equal(Gecode::Model::LARGEST_INT_DOMAIN)
41
+ end
42
+
43
+ it 'should implement #must' do
44
+ receiver = @operand.must
45
+ receiver.should be_kind_of(
46
+ Gecode::Int::IntConstraintReceiver)
47
+ end
48
+ end
49
+
50
+ # Requires @operand and @model.
51
+ describe 'bool var operand', :shared => true do
52
+ it 'should implement #model' do
53
+ @operand.model.should be_kind_of(Gecode::Model)
54
+ end
55
+
56
+ it 'should implement #to_bool_var' do
57
+ bool_var = @operand.to_bool_var
58
+ bool_var.should be_kind_of(Gecode::BoolVar)
59
+ end
60
+
61
+ it 'should implement #must' do
62
+ receiver = @operand.must
63
+ receiver.should be_kind_of(
64
+ Gecode::Bool::BoolConstraintReceiver)
65
+ end
66
+ end
67
+
68
+ # Requires @operand and @model.
69
+ describe 'set var operand', :shared => true do
70
+ it 'should implement #model' do
71
+ @operand.model.should be_kind_of(Gecode::Model)
72
+ end
73
+
74
+ it 'should implement #to_set_var' do
75
+ set_var = @operand.to_set_var
76
+ set_var.should be_kind_of(Gecode::SetVar)
77
+ @model.solve!
78
+ ((set_var.lower_bound == []) &&
79
+ (set_var.upper_bound == Gecode::Model::LARGEST_SET_BOUND)).should_not(
80
+ be_true)
81
+ end
82
+
83
+ it 'should implement #must' do
84
+ receiver = @operand.must
85
+ receiver.should be_kind_of(
86
+ Gecode::Set::SetConstraintReceiver)
87
+ end
88
+ end
89
+
90
+ # Requires @model, @property_types and @select_property.
91
+ describe 'property that produces operand', :shared => true do
92
+ it 'should raise errors if parameters of the incorrect type are given' do
93
+ operands, variables = produce_general_arguments(@property_types)
94
+ (1...operands.size).each do |i|
95
+ bogus_operands = operands.clone
96
+ bogus_operands[i] = Object.new
97
+ lambda do
98
+ @select_property.call(*bogus_operands)
99
+ end.should raise_error(TypeError)
100
+ end
101
+ end
102
+ end
103
+
104
+ # Requires @model, @property_types and @select_property.
105
+ describe 'property that produces int operand', :shared => true do
106
+ it 'should produce int operand' do
107
+ operands, variables = produce_general_arguments(@property_types)
108
+ operand = @select_property.call(*operands)
109
+
110
+ # Test the same invariants as in the test for int var operands.
111
+ operand.model.should be_kind_of(Gecode::Model)
112
+
113
+ int_var = operand.to_int_var
114
+ int_var.should be_kind_of(Gecode::IntVar)
115
+
116
+ receiver = operand.must
117
+ receiver.should be_kind_of(
118
+ Gecode::Int::IntConstraintReceiver)
119
+ end
120
+
121
+ it_should_behave_like 'property that produces operand'
122
+ end
123
+
124
+ # Requires @model, @property_types and @select_property.
125
+ describe 'property that produces bool operand', :shared => true do
126
+ it 'should produce bool operand' do
127
+ operands, variables = produce_general_arguments(@property_types)
128
+ operand = @select_property.call(*operands)
129
+
130
+ # Test the same invariants as in the test for bool var operands.
131
+ operand.model.should be_kind_of(Gecode::Model)
132
+
133
+ bool_var = operand.to_bool_var
134
+ bool_var.should be_kind_of(Gecode::BoolVar)
135
+
136
+ receiver = operand.must
137
+ receiver.should be_kind_of(
138
+ Gecode::Bool::BoolConstraintReceiver)
139
+ end
140
+
141
+ it_should_behave_like 'property that produces operand'
142
+ end
143
+
144
+ # Requires @model, @property_types and @select_property.
145
+ describe 'property that produces set operand', :shared => true do
146
+ it 'should produce set operand' do
147
+ operands, variables = produce_general_arguments(@property_types)
148
+ operand = @select_property.call(*operands)
149
+
150
+ # Test the same invariants as in the test for int var operands.
151
+ operand.model.should be_kind_of(Gecode::Model)
152
+
153
+ set_var = operand.to_set_var
154
+ set_var.should be_kind_of(Gecode::SetVar)
155
+
156
+ receiver = operand.must
157
+ receiver.should be_kind_of(
158
+ Gecode::Set::SetConstraintReceiver)
159
+ end
160
+
161
+ it_should_behave_like 'property that produces operand'
162
+ end
163
+
164
+ # Requires @model, @constraint_class, @property_types, @select_property and
165
+ # @selected_property.
166
+ #
167
+ # These properties should only short circuit equality when there is no
168
+ # negation nor reification and the right hand side is an int operand.
169
+ describe 'property that produces int operand by short circuiting equality', :shared => true do
170
+ it 'should produce constraints when short circuited' do
171
+ @constraint_class.superclass.should == Gecode::Constraint
172
+ end
173
+
174
+ it 'should give the same solution regardless of whether short circuit was used' do
175
+ int_operand = @selected_property
176
+ direct_int_var = int_operand.to_int_var
177
+ indirect_int_op, _ = general_int_operand(@model)
178
+ @selected_property.must == indirect_int_op
179
+ @model.solve!
180
+
181
+ direct_int_var.should_not have_domain(Gecode::Model::LARGEST_INT_DOMAIN)
182
+ direct_int_var.should have_domain(indirect_int_op.domain)
183
+ end
184
+
185
+ it 'should short circuit equality' do
186
+ (@selected_property.must == @model.int_var).should(
187
+ be_kind_of(@constraint_class))
188
+ end
189
+
190
+ it 'should not short circuit when negation is used' do
191
+ (@selected_property.must_not == @model.int_var).should_not(
192
+ be_kind_of(@constraint_class))
193
+ end
194
+
195
+ it 'should not short circuit when reification is used' do
196
+ @selected_property.must.equal(@model.int_var,
197
+ :reify => @model.bool_var).should_not(be_kind_of(@constraint_class))
198
+ end
199
+
200
+ it 'should not short circuit when the right hand side is not a operand' do
201
+ @selected_property.must.equal(2).should_not(be_kind_of(@constraint_class))
202
+ end
203
+
204
+ it 'should not short circuit when equality is not used' do
205
+ (@selected_property.must > @model.int_var).should_not(
206
+ be_kind_of(@constraint_class))
207
+ end
208
+
209
+ it 'should raise error when the right hand side is of illegal type' do
210
+ lambda do
211
+ @selected_property.must == 'foo'
212
+ end.should raise_error(TypeError)
213
+ end
214
+
215
+ it_should_behave_like 'property that produces int operand'
216
+ end
217
+
218
+ # Requires @model, @constraint_class, @property_types, @select_property and
219
+ # @selected_property.
220
+ #
221
+ # These properties should only short circuit equality when there is no
222
+ # negation nor reification and the right hand side is a bool operand.
223
+ describe 'property that produces bool operand by short circuiting equality', :shared => true do
224
+ it 'should produce constraints when short circuited' do
225
+ @constraint_class.superclass.should == Gecode::Constraint
226
+ end
227
+
228
+ it 'should give the same solution regardless of whether short circuit was used' do
229
+ bool_operand = @selected_property
230
+ direct_bool_var = bool_operand.to_bool_var
231
+ indirect_bool_var = @model.bool_var
232
+ @selected_property.must == indirect_bool_var
233
+ @model.solve!
234
+
235
+ direct_bool_var.value.should == indirect_bool_var.value
236
+ end
237
+
238
+ it 'should short circuit equality' do
239
+ (@selected_property.must == @model.bool_var).should(
240
+ be_kind_of(@constraint_class))
241
+ end
242
+
243
+ it 'should not short circuit when negation is used' do
244
+ (@selected_property.must_not == @model.bool_var).should_not(
245
+ be_kind_of(@constraint_class))
246
+ end
247
+
248
+ it 'should not short circuit when reification is used' do
249
+ @selected_property.must.equal(@model.bool_var,
250
+ :reify => @model.bool_var).should_not(be_kind_of(@constraint_class))
251
+ end
252
+
253
+ it 'should not short circuit when equality is not used' do
254
+ (@selected_property.must.imply @model.bool_var).should_not(
255
+ be_kind_of(@constraint_class))
256
+ end
257
+
258
+ it 'should raise error when the right hand side is of illegal type' do
259
+ lambda do
260
+ @selected_property.must == 'foo'
261
+ end.should raise_error(TypeError)
262
+ end
263
+
264
+ it_should_behave_like 'property that produces bool operand'
265
+ end
266
+
267
+ # Requires @model, @constraint_class, @property_types and @select_property.
268
+ #
269
+ # These properties should short circuit all comparison relations
270
+ # even when negated and when fixnums are used as right hand side.
271
+ describe 'property that produces int operand by short circuiting relations', :shared => true do
272
+ it 'should produce reifiable constraints when short circuited' do
273
+ @constraint_class.superclass.should ==
274
+ Gecode::ReifiableConstraint
275
+ end
276
+
277
+ Gecode::Util::RELATION_TYPES.keys.each do |relation|
278
+ it "should give the same solution regardless of whether short circuit #{relation} was used" do
279
+ direct_int_var = @model.int_var
280
+ @selected_property.to_int_var.must.method(relation).call direct_int_var
281
+ indirect_int_var = @model.int_var
282
+ @selected_property.must.method(relation).call indirect_int_var
283
+ @model.solve!
284
+
285
+ direct_int_var.should_not have_domain(Gecode::Model::LARGEST_INT_DOMAIN)
286
+ direct_int_var.should have_domain(indirect_int_var.domain)
287
+ end
288
+
289
+ it "should short circuit #{relation}" do
290
+ (@selected_property.must.method(relation).call @model.int_var).should(
291
+ be_kind_of(@constraint_class))
292
+ end
293
+
294
+ it "should short circuit negated #{relation}" do
295
+ (@selected_property.must_not.method(relation).call @model.int_var).should(
296
+ be_kind_of(@constraint_class))
297
+ end
298
+
299
+ it "should short circuit #{relation} when reification is used" do
300
+ (@selected_property.must.method(relation).call(@model.int_var,
301
+ :reify => @model.bool_var)).should(be_kind_of(@constraint_class))
302
+ end
303
+
304
+ it "should short circuit #{relation} even when the right hand side is a fixnum" do
305
+ (@selected_property.must.method(relation).call 2).should(
306
+ be_kind_of(@constraint_class))
307
+ end
308
+
309
+ it "should raise error when the #{relation} right hand side is of illegal type" do
310
+ lambda do
311
+ @selected_property.must.method(relation).call('foo')
312
+ end.should raise_error(TypeError)
313
+ end
314
+ end
315
+
316
+ it_should_behave_like 'property that produces int operand'
317
+ end
318
+
319
+ # Requires @model, @constraint_class, @property_types, @select_property and
320
+ # @selected_property.
321
+ #
322
+ # These properties should only short circuit equality when there is no
323
+ # negation nor reification and the right hand side is a set operand.
324
+ describe 'property that produces set operand by short circuiting equality', :shared => true do
325
+ it 'should produce constraints when short circuited' do
326
+ @constraint_class.superclass.should == Gecode::Constraint
327
+ end
328
+
329
+ it 'should give the same solution regardless of whether short circuit was used' do
330
+ set_operand = @selected_property
331
+ direct_set_var = set_operand.to_set_var
332
+ indirect_set_var = @model.set_var
333
+ @selected_property.must == indirect_set_var
334
+ @model.solve!
335
+
336
+ direct_set_var.should have_bounds(indirect_set_var.lower_bound,
337
+ indirect_set_var.upper_bound)
338
+ end
339
+
340
+ it 'should short circuit equality' do
341
+ (@selected_property.must == @model.set_var).should(
342
+ be_kind_of(@constraint_class))
343
+ end
344
+
345
+ it 'should not short circuit when negation is used' do
346
+ (@selected_property.must_not == @model.set_var).should_not(
347
+ be_kind_of(@constraint_class))
348
+ end
349
+
350
+ it 'should not short circuit when reification is used' do
351
+ (@selected_property.must.equal(@model.set_var,
352
+ :reify => @model.bool_var)).should_not(be_kind_of(@constraint_class))
353
+ end
354
+
355
+ it 'should not short circuit when the right hand side is not a operand' do
356
+ (@selected_property.must == [1,3,5]).should_not(
357
+ be_kind_of(@constraint_class))
358
+ end
359
+
360
+ it 'should not short circuit when equality is not used' do
361
+ (@selected_property.must_be.subset_of(@model.set_var)).should_not(
362
+ be_kind_of(@constraint_class))
363
+ end
364
+
365
+ it 'should raise error when the right hand side is of illegal type' do
366
+ lambda do
367
+ @selected_property.must == 'foo'
368
+ end.should raise_error(TypeError)
369
+ end
370
+
371
+ it_should_behave_like 'property that produces set operand'
372
+ end
373
+
374
+ # Requires @model, @constraint_class, @property_types and @select_property.
375
+ #
376
+ # These properties should only short circuit set relations when neither
377
+ # negation nor reification is used (both for constant sets and set
378
+ # variables).
379
+ describe 'property that produces set operand by short circuiting set relations', :shared => true do
380
+ Gecode::Util::SET_RELATION_TYPES.keys.each do |relation|
381
+ it 'should produce constraints when short circuited' do
382
+ @constraint_class.superclass.should == Gecode::Constraint
383
+ end
384
+
385
+ it "should give the same solution regardless of whether short circuit #{relation} was used" do
386
+ if relation == :complement
387
+ direct_set_var, indirect_set_var = Array.new(2){ @model.set_var }
388
+ else
389
+ direct_set_var, indirect_set_var = Array.new(2) do
390
+ @model.set_var([], -1000..1000)
391
+ end
392
+ end
393
+
394
+ @selected_property.to_set_var.must.method(relation).call direct_set_var
395
+ @selected_property.must.method(relation).call indirect_set_var
396
+ @model.solve!
397
+
398
+ if relation == :complement
399
+ direct_set_var.upper_bound.min.should ==
400
+ indirect_set_var.upper_bound.min
401
+ direct_set_var.upper_bound.max.should ==
402
+ indirect_set_var.upper_bound.max
403
+ direct_set_var.lower_bound.min.should ==
404
+ indirect_set_var.lower_bound.min
405
+ direct_set_var.lower_bound.max.should ==
406
+ indirect_set_var.lower_bound.max
407
+ direct_set_var.lower_bound.size.should ==
408
+ indirect_set_var.lower_bound.size
409
+ else
410
+ direct_set_var.should have_bounds(indirect_set_var.lower_bound,
411
+ indirect_set_var.upper_bound)
412
+ end
413
+ end
414
+
415
+ it "should short circuit #{relation}" do
416
+ @selected_property.must.method(relation).call(@model.set_var).should(
417
+ be_kind_of(@constraint_class))
418
+ end
419
+
420
+ it "should not short circuit negated #{relation}" do
421
+ @selected_property.must_not.method(relation).call(
422
+ @model.set_var).should_not(be_kind_of(@constraint_class))
423
+ end
424
+
425
+ it "should not short circuit reified #{relation}" do
426
+ @selected_property.must.method(relation).call(@model.set_var,
427
+ :reify => @model.bool_var).should_not(be_kind_of(@constraint_class))
428
+ end
429
+
430
+ it "should short circuit #{relation} even when the right hand side is a constant set" do
431
+ @selected_property.must.method(relation).call([1, 2, 3]).should(
432
+ be_kind_of(@constraint_class))
433
+ end
434
+
435
+ it "should raise error when the #{relation} right hand side is of illegal type" do
436
+ lambda do
437
+ @selected_property.must.method(relation).call('foo')
438
+ end.should raise_error(TypeError)
439
+ end
440
+ end
441
+
442
+ it_should_behave_like 'property that produces set operand'
443
+ end
@@ -13,7 +13,7 @@ class ReifSugarSampleProblem < Gecode::Model
13
13
  end
14
14
  end
15
15
 
16
- describe Gecode::Constraints::ReifiableConstraint do
16
+ describe Gecode::ReifiableConstraint do
17
17
  before do
18
18
  @model = ReifSugarSampleProblem.new
19
19
  @x = @model.x
@@ -23,7 +23,7 @@ describe Gecode::Constraints::ReifiableConstraint do
23
23
 
24
24
  it 'should fail disjunctions if neither side can be satisfied' do
25
25
  (@x.must == 3) | (@y.must == 3)
26
- @model.solve!.should be_nil
26
+ lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
27
27
  end
28
28
 
29
29
  it 'should solve disjunctions' do
@@ -35,7 +35,7 @@ describe Gecode::Constraints::ReifiableConstraint do
35
35
 
36
36
  it 'should fail conjunctions if one side can\'t be satisfied' do
37
37
  (@x.must > 3) & (@y.must == 3)
38
- @model.solve!.should be_nil
38
+ lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
39
39
  end
40
40
 
41
41
  it 'should solve conjunctions' do
@@ -64,7 +64,6 @@ describe Gecode::Constraints::ReifiableConstraint do
64
64
 
65
65
  it 'should handle negations' do
66
66
  (@z.must_not == 4) & (@z.must == 4)
67
- sol = @model.solve!
68
- sol.should be_nil
67
+ lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
69
68
  end
70
69
  end
@@ -0,0 +1,56 @@
1
+ require File.dirname(__FILE__) + '/../constraint_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
+ describe Gecode::SetEnum::Select, ' (disjoint)' do
20
+ include GecodeR::Specs::SetHelper
21
+
22
+ before do
23
+ @model = SelectionSampleProblem.new
24
+ @sets = @model.sets
25
+ @set = @model.set
26
+ @target = @model.target
27
+ @model.branch_on @model.wrap_enum([@target, @set])
28
+
29
+ @types = [:selected_set]
30
+ @invoke = lambda do |receiver, hash|
31
+ receiver.disjoint(hash)
32
+ @model.solve!
33
+ end
34
+ @expect = lambda do |var, opts, reif_var|
35
+ set_enum, set = var
36
+ Gecode::Raw.should_receive(:selectDisjoint).once.with(
37
+ an_instance_of(Gecode::Raw::Space),
38
+ set_enum, set)
39
+ end
40
+ end
41
+
42
+ it 'should constrain the selected sets to be disjoint' do
43
+ @sets[0].must_be.superset_of([7,8])
44
+ @sets[1].must_be.superset_of([5,7,9])
45
+ @sets[2].must_be.superset_of([6,8,10])
46
+ @sets[@set].must_be.disjoint
47
+ @set.size.must > 1
48
+ @model.solve!.should_not be_nil
49
+
50
+ @set.value.to_a.sort.should == [1,2]
51
+ end
52
+
53
+ it_should_behave_like 'non-reifiable set constraint'
54
+ it_should_behave_like 'non-negatable constraint'
55
+ end
56
+
@@ -0,0 +1,157 @@
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
+ describe Gecode::SelectedSet::Select, ' (union)' do
20
+ include GecodeR::Specs::SetHelper
21
+
22
+ before do
23
+ @model = SelectionSampleProblem.new
24
+ @sets = @model.sets
25
+ @set = @model.set
26
+ @model.branch_on @set
27
+
28
+ @property_types = [:selected_set]
29
+ @select_property = lambda do |selected_set|
30
+ selected_set.union
31
+ end
32
+ @selected_property = @sets[@set].union
33
+ @constraint_class = Gecode::BlockConstraint
34
+ end
35
+
36
+ it 'should constrain the selected union of an enum of sets' do
37
+ @sets[@set].union.must_be.subset_of([5,7,9])
38
+ @sets[@set].union.must_be.superset_of([5])
39
+ @model.solve!
40
+ union = @set.value.inject([]) do |union, i|
41
+ union += @sets[i].value.to_a
42
+ end.uniq
43
+ union.should include(5)
44
+ (union - [5,7,9]).should be_empty
45
+ end
46
+
47
+ it 'should translate into a select union constraint' do
48
+ Gecode::Raw.should_receive(:selectUnion)
49
+ @sets[@set].union.must_be.subset_of([5,7,9])
50
+ @model.solve!
51
+ end
52
+
53
+ it_should_behave_like(
54
+ 'property that produces set operand by short circuiting equality')
55
+ end
56
+
57
+ describe Gecode::SetEnum::Select, ' (intersection)' do
58
+ include GecodeR::Specs::SetHelper
59
+
60
+ before do
61
+ @model = SelectionSampleProblem.new
62
+ @sets = @model.sets
63
+ @set = @model.set
64
+ @model.branch_on @set
65
+
66
+ @property_types = [:selected_set]
67
+ @select_property = lambda do |selected_set|
68
+ selected_set.intersection
69
+ end
70
+ @selected_property = @sets[@set].intersection
71
+ @constraint_class = Gecode::BlockConstraint
72
+ end
73
+
74
+ it 'should constrain the selected intersection of an enum of sets' do
75
+ @sets[@set].intersection.must_be.subset_of([5,7,9])
76
+ @sets[@set].intersection.must_be.superset_of([5])
77
+ @model.solve!
78
+ intersection = @set.value.inject(nil) do |intersection, i|
79
+ elements = @sets[i].value.to_a
80
+ next elements if intersection.nil?
81
+ intersection &= elements
82
+ end.uniq
83
+ intersection.should include(5)
84
+ (intersection - [5,7,9]).should be_empty
85
+ end
86
+
87
+ it 'should translate into a select intersection constraint' do
88
+ Gecode::Raw.should_receive(:selectInter)
89
+ @sets[@set].intersection.must_be.subset_of([5,7,9])
90
+ @model.solve!
91
+ end
92
+
93
+ it_should_behave_like(
94
+ 'property that produces set operand by short circuiting equality')
95
+ end
96
+
97
+ describe Gecode::SelectedSet::Select, ' (intersection with universe)' do
98
+ include GecodeR::Specs::SetHelper
99
+
100
+ before do
101
+ @model = SelectionSampleProblem.new
102
+ @sets = @model.sets
103
+ @set = @model.set
104
+ @model.branch_on @set
105
+ @universe = [1,2]
106
+
107
+ @property_types = [:selected_set]
108
+ @select_property = lambda do |selected_set|
109
+ selected_set.intersection(:with => @universe)
110
+ end
111
+ @selected_property = @sets[@set].intersection(:with => @universe)
112
+ @constraint_class = Gecode::BlockConstraint
113
+ end
114
+
115
+ it 'should constrain the selected intersection of an enum of sets in a universe' do
116
+ @sets[@set].intersection(:with => @universe).must_be.subset_of([2])
117
+ @model.solve!
118
+ intersection = @set.value.inject(@universe) do |intersection, i|
119
+ intersection &= @sets[i].value.to_a
120
+ end.uniq
121
+ intersection.should include(2)
122
+ (intersection - [1,2]).should be_empty
123
+ end
124
+
125
+ it 'should allow the universe to be specified as a range' do
126
+ @sets[@set].intersection(:with => 1..2).must_be.subset_of([2])
127
+ @model.solve!
128
+ intersection = @set.value.inject(@universe) do |intersection, i|
129
+ intersection &= @sets[i].value.to_a
130
+ end.uniq
131
+ intersection.should include(2)
132
+ (intersection - [1,2]).should be_empty
133
+ end
134
+
135
+ it 'should translate into a select intersection constraint' do
136
+ Gecode::Raw.should_receive(:selectInterIn)
137
+ @sets[@set].intersection(:with => 1..2).must_be.subset_of([5,7,9])
138
+ @model.solve!
139
+ end
140
+
141
+ it 'should raise error if unknown options are specified' do
142
+ lambda do
143
+ @sets[@set].intersection(:does_not_exist => nil).must_be.subset_of([2])
144
+ end.should raise_error(ArgumentError)
145
+ end
146
+
147
+ it 'should raise error if the universe is of the wrong type' do
148
+ lambda do
149
+ @sets[@set].intersection(:with => 'foo').must_be.subset_of([2])
150
+ end.should raise_error(TypeError)
151
+ end
152
+
153
+ it_should_behave_like(
154
+ 'property that produces set operand by short circuiting equality')
155
+ end
156
+
157
+