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,84 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
4
+ describe Gecode::Int::Relation, " (#{relation} with int op)" do
5
+ before do
6
+ @model = Gecode::Model.new
7
+
8
+ # For constraint spec.
9
+ @types = [:int, :int]
10
+ @invoke = lambda do |receiver, op, hash|
11
+ receiver.method(relation).call(op, hash)
12
+ @model.solve!
13
+ end
14
+ @expect = lambda do |var1, var2, opts, reif_var|
15
+ if reif_var.nil?
16
+ Gecode::Raw.should_receive(:rel).once.with(
17
+ an_instance_of(Gecode::Raw::Space),
18
+ var1, rel_value, var2, *opts)
19
+ else
20
+ Gecode::Raw.should_receive(:rel).once.with(
21
+ an_instance_of(Gecode::Raw::Space),
22
+ var1, rel_value, var2, reif_var, *opts)
23
+ end
24
+ end
25
+ end
26
+
27
+ it "should constrain the #{relation} with an int operand" do
28
+ ints = @model.int_var_array(2, -5..5)
29
+ @model.branch_on ints
30
+ int1, int2 = ints
31
+ int1.must.method(relation).call(int2)
32
+ @model.solve!
33
+ int1.value.should.method(relation).call(int2.value)
34
+ end
35
+
36
+ it "should constrain the negated #{relation} with an int operand" do
37
+ ints = @model.int_var_array(2, -5..5)
38
+ @model.branch_on ints
39
+ int1, int2 = ints
40
+ int1.must_not.method(relation).call(int2)
41
+ @model.solve!
42
+ int1.value.should_not.method(relation).call(int2.value)
43
+ end
44
+
45
+ it_should_behave_like 'reifiable constraint'
46
+ end
47
+ end
48
+
49
+ Gecode::Util::RELATION_TYPES.each_pair do |relation, rel_value|
50
+ describe Gecode::Int::Relation, " (#{relation} with fixnum)" do
51
+ before do
52
+ @model = Gecode::Model.new
53
+
54
+ # For constraint spec.
55
+ @types = [:int]
56
+ @invoke = lambda do |receiver, hash|
57
+ receiver.method(relation).call(17, hash)
58
+ @model.solve!
59
+ end
60
+ @expect = lambda do |var, opts, reif_var|
61
+ if reif_var.nil?
62
+ Gecode::Raw.should_receive(:rel).once.with(
63
+ an_instance_of(Gecode::Raw::Space),
64
+ var, rel_value, 17, *opts)
65
+ else
66
+ Gecode::Raw.should_receive(:rel).once.with(
67
+ an_instance_of(Gecode::Raw::Space),
68
+ var, rel_value, 17, reif_var, *opts)
69
+ end
70
+ end
71
+ end
72
+
73
+ it "should constrain the #{relation} with a fixnum" do
74
+ int = @model.int_var(-5..5)
75
+ @model.branch_on int
76
+ int.must.method(relation).call(3)
77
+ @model.solve!
78
+ int.value.should.method(relation).call(3)
79
+ end
80
+
81
+ it_should_behave_like 'reifiable constraint'
82
+ end
83
+ end
84
+
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ class IntEnumArithmeticSampleProblem < Gecode::Model
4
+ attr :numbers
5
+ attr :var
6
+
7
+ def initialize
8
+ @numbers = int_var_array(4, 0..9)
9
+ @var = int_var(-9..9)
10
+ branch_on @numbers
11
+ branch_on @var
12
+ end
13
+ end
14
+
15
+ describe Gecode::IntEnum::Arithmetic, ' (max)' do
16
+ before do
17
+ @model = IntEnumArithmeticSampleProblem.new
18
+ @numbers = @model.numbers
19
+ @var = @model.var
20
+
21
+ @property_types = [:int_enum]
22
+ @select_property = lambda do |int_enum|
23
+ int_enum.max
24
+ end
25
+ @selected_property = @numbers.max
26
+ @constraint_class = Gecode::BlockConstraint
27
+ end
28
+
29
+ it 'should constrain the maximum value' do
30
+ @numbers.max.must > 5
31
+ @model.solve!.numbers.values.max.should > 5
32
+ end
33
+
34
+ it 'should translate into a max constraint' do
35
+ Gecode::Raw.should_receive(:max)
36
+ @numbers.max.must == 5
37
+ @model.solve!
38
+ end
39
+
40
+ it_should_behave_like(
41
+ 'property that produces int operand by short circuiting equality')
42
+ end
43
+
44
+ describe Gecode::IntEnum::Arithmetic, ' (min)' do
45
+ before do
46
+ @model = IntEnumArithmeticSampleProblem.new
47
+ @numbers = @model.numbers
48
+ @var = @model.var
49
+
50
+ @property_types = [:int_enum]
51
+ @select_property = lambda do |int_enum|
52
+ int_enum.min
53
+ end
54
+ @selected_property = @numbers.min
55
+ @constraint_class = Gecode::BlockConstraint
56
+ end
57
+
58
+ it 'should constrain the minimum value' do
59
+ @numbers.min.must > 5
60
+ @model.solve!.numbers.values.min.should > 5
61
+ end
62
+
63
+ it 'should translate into a min constraint' do
64
+ Gecode::Raw.should_receive(:min)
65
+ @numbers.min.must == 5
66
+ @model.solve!
67
+ end
68
+
69
+ it_should_behave_like(
70
+ 'property that produces int operand by short circuiting equality')
71
+ end
72
+
@@ -0,0 +1,57 @@
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::IntEnum::Channel, ' (two int enums)' do
19
+ before do
20
+ @model = ChannelSampleProblem.new
21
+ @positions = @model.positions
22
+ @elements = @model.elements
23
+
24
+ @types = [:int_enum, :int_enum]
25
+ @invoke = lambda do |receiver, int_enum, hash|
26
+ receiver.channel(int_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, *opts)
33
+ end
34
+ end
35
+
36
+ it 'should translate into a channel constraint' do
37
+ Gecode::Raw.should_receive(:channel).once.with(
38
+ an_instance_of(Gecode::Raw::Space),
39
+ anything, anything, Gecode::Raw::ICL_DEF, Gecode::Raw::PK_DEF)
40
+ @positions.must.channel @elements
41
+ @model.solve!
42
+ end
43
+
44
+ it 'should constrain variables to be channelled' do
45
+ @elements.must.channel @positions
46
+ @model.solve!
47
+ elements = @model.elements.values
48
+ positions = @model.elements.values
49
+ elements.each_with_index do |element, i|
50
+ element.should equal(positions.index(i))
51
+ end
52
+ end
53
+
54
+ it_should_behave_like 'non-reifiable constraint'
55
+ it_should_behave_like 'non-negatable constraint'
56
+ end
57
+
@@ -0,0 +1,72 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ class CountSampleProblem < Gecode::Model
4
+ attr :list
5
+ attr :element
6
+ attr :target
7
+
8
+ def initialize
9
+ @list = int_var_array(4, 0..3)
10
+ @element = int_var(0..3)
11
+ @target = int_var(0..4)
12
+ branch_on @list
13
+ branch_on @element
14
+ end
15
+ end
16
+
17
+ describe Gecode::IntEnum::Count, ' (with int var)' do
18
+ before do
19
+ @model = CountSampleProblem.new
20
+ @list = @model.list
21
+ @element = @model.element
22
+ @target = @model.target
23
+
24
+ # For int operand producing property spec.
25
+ @property_types = [:int_enum, :int]
26
+ @select_property = lambda do |int_enum, int|
27
+ int_enum.count(int)
28
+ end
29
+ @selected_property = @list.count(@element)
30
+ @constraint_class =
31
+ Gecode::IntEnum::Count::CountConstraint
32
+ end
33
+
34
+ it 'should constrain the count' do
35
+ @list.count(@element).must == 2
36
+ @model.solve!
37
+ @list.values.map{ |x| x == @element.value }.inject(0) do |sum, b|
38
+ sum += b ? 1 : 0
39
+ end.should == 2
40
+ end
41
+
42
+ it_should_behave_like(
43
+ 'property that produces int operand by short circuiting relations')
44
+ end
45
+
46
+ describe Gecode::IntEnum::Count, ' (with fixnum)' do
47
+ before do
48
+ @model = CountSampleProblem.new
49
+ @list = @model.list
50
+ @target = @model.target
51
+
52
+ # For int operand producing property spec.
53
+ @property_types = [:int_enum]
54
+ @select_property = lambda do |int_enum|
55
+ int_enum.count(1)
56
+ end
57
+ @selected_property = @list.count(1)
58
+ @constraint_class =
59
+ Gecode::IntEnum::Count::CountConstraint
60
+ end
61
+
62
+ it 'should constrain the count' do
63
+ @list.count(1).must == 2
64
+ @model.solve!
65
+ @list.values.map{ |x| x == 1 }.inject(0) do |sum, b|
66
+ sum += b ? 1 : 0
67
+ end.should == 2
68
+ end
69
+
70
+ it_should_behave_like(
71
+ 'property that produces int operand by short circuiting relations')
72
+ end
@@ -0,0 +1,80 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ class DistinctSampleProblem < Gecode::Model
4
+ def initialize
5
+ vars_is_an int_var_array(2, 0..1)
6
+ branch_on vars
7
+ end
8
+ end
9
+
10
+ describe Gecode::IntEnum::Distinct do
11
+ before do
12
+ @model = DistinctSampleProblem.new
13
+
14
+ @types = [:int_enum]
15
+ @invoke = lambda do |receiver, hash|
16
+ receiver.distinct(hash)
17
+ @model.solve!
18
+ end
19
+ @expect = lambda do |var, opts, reif_var|
20
+ Gecode::Raw.should_receive(:distinct).once.with(
21
+ an_instance_of(Gecode::Raw::Space),
22
+ var, *opts)
23
+ end
24
+ end
25
+
26
+ it 'should constrain variables to be distinct' do
27
+ @model.vars.must_be.distinct
28
+ @model.solve!
29
+ @model.vars[0].value.should_not == @model.vars[1].value
30
+ end
31
+
32
+ it_should_behave_like 'non-reifiable constraint'
33
+ it_should_behave_like 'non-negatable constraint'
34
+ end
35
+
36
+ describe Gecode::IntEnum::Distinct, ' (with offsets)' do
37
+ before do
38
+ @model = DistinctSampleProblem.new
39
+
40
+ @types = [:int_enum]
41
+ @invoke = lambda do |receiver, hash|
42
+ receiver.distinct hash.update(:offsets => [1,2])
43
+ @model.solve!
44
+ end
45
+ @expect = lambda do |var, opts, reif_var|
46
+ if reif_var.nil?
47
+ Gecode::Raw.should_receive(:distinct).once.with(
48
+ an_instance_of(Gecode::Raw::Space),
49
+ [1,2], var, *opts)
50
+ else
51
+ Gecode::Raw.should_receive(:distinct).once.with(
52
+ an_instance_of(Gecode::Raw::Space),
53
+ [1,2], var, reif_var, *opts)
54
+ end
55
+ end
56
+ end
57
+
58
+ it 'should constrain variables to be distinct' do
59
+ @model.vars.must_be.distinct(:offsets => [-1, 0])
60
+ x, y = @model.solve!.vars
61
+ (x.value - 1).should_not == y.value
62
+ end
63
+
64
+ # This tests two distinct in conjunction. It's here because of a bug found.
65
+ it 'should play nice with normal distinct' do
66
+ @model.vars.must_be.distinct(:offsets => [-1, 0])
67
+ @model.vars.must_be.distinct(:offsets => [0, -1])
68
+ @model.vars.must_be.distinct
69
+ lambda{ @model.solve! }.should raise_error(Gecode::NoSolutionError)
70
+ end
71
+
72
+ it 'should raise error if the offsets are of an incorrect type' do
73
+ lambda do
74
+ @model.vars.must_be.distinct(:offsets => :foo)
75
+ end.should raise_error(TypeError)
76
+ end
77
+
78
+ it_should_behave_like 'non-reifiable constraint'
79
+ it_should_behave_like 'non-negatable constraint'
80
+ end
@@ -0,0 +1,61 @@
1
+ require File.dirname(__FILE__) + '/../property_helper'
2
+
3
+ class ElementSampleProblem < Gecode::Model
4
+ attr :prices
5
+ attr :store
6
+ attr :price
7
+ attr :fixnum_prices
8
+
9
+ def initialize
10
+ prices = [17, 63, 45, 63]
11
+ @fixnum_prices = wrap_enum(prices)
12
+ @prices = int_var_array(4, prices)
13
+ @store = int_var(0...prices.size)
14
+ @price = int_var(prices)
15
+ branch_on @store
16
+ end
17
+ end
18
+
19
+ describe Gecode::IntEnum::Element do
20
+ before do
21
+ @model = ElementSampleProblem.new
22
+ @prices = @model.prices
23
+ @target = @price = @model.price
24
+ @store = @model.store
25
+
26
+ # For int operand producing property spec.
27
+ @property_types = [:int_enum, :int]
28
+ @select_property = lambda do |int_enum, int|
29
+ int_enum[int]
30
+ end
31
+ @selected_property = @prices[@store]
32
+ @constraint_class = Gecode::BlockConstraint
33
+ end
34
+
35
+ it 'should not disturb normal array access' do
36
+ @prices[2].should_not be_nil
37
+ end
38
+
39
+ it 'should constrain the selected element' do
40
+ @prices[@store].must == 63
41
+ @prices.values_at(0,2,3).each{ |x| x.must < 50 }
42
+ @model.solve!.should_not be_nil
43
+ @store.value.should equal(1)
44
+ end
45
+
46
+ it 'should be translated into an element constraint' do
47
+ @prices[@store].must == @price
48
+ @model.allow_space_access do
49
+ Gecode::Raw.should_receive(:element).once.with(
50
+ an_instance_of(Gecode::Raw::Space),
51
+ an_instance_of(Gecode::Raw::IntVarArray),
52
+ @store.bind, @price.bind,
53
+ Gecode::Raw::ICL_DEF,
54
+ Gecode::Raw::PK_DEF)
55
+ end
56
+ @model.solve!
57
+ end
58
+
59
+ it_should_behave_like(
60
+ 'property that produces int operand by short circuiting equality')
61
+ end
@@ -0,0 +1,29 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ describe Gecode::IntEnum::Equality do
4
+ before do
5
+ @model = Gecode::Model.new
6
+ @vars = @model.int_var_array(4, -2..2)
7
+
8
+ @types = [:int_enum]
9
+ @invoke = lambda do |receiver, hash|
10
+ receiver.equal(hash)
11
+ @model.solve!
12
+ end
13
+ @expect = lambda do |var, opts, reif_var|
14
+ Gecode::Raw.should_receive(:rel).once.with(
15
+ an_instance_of(Gecode::Raw::Space),
16
+ var, Gecode::Raw::IRT_EQ, *opts)
17
+ end
18
+ end
19
+
20
+ it 'should constrain elements to be equal' do
21
+ @vars[1].must == 1
22
+ @vars.must_be.equal
23
+ @model.solve!
24
+ @vars.values.each{ |x| x.should == 1 }
25
+ end
26
+
27
+ it_should_behave_like 'non-reifiable constraint'
28
+ it_should_behave_like 'non-negatable constraint'
29
+ end
@@ -0,0 +1,224 @@
1
+ require File.dirname(__FILE__) + '/../constraint_helper'
2
+
3
+ # Assumes that @variables, @expected_array and @tuples are defined.
4
+ describe 'int tuple constraint', :shared => true do
5
+ it 'should not allow negation' do
6
+ lambda do
7
+ @variables.must_not_be.in @tuples
8
+ end.should raise_error(Gecode::MissingConstraintError)
9
+ end
10
+
11
+ it 'should not allow empty tuples' do
12
+ lambda do
13
+ @variables.must_be.in []
14
+ end.should raise_error(ArgumentError)
15
+ end
16
+
17
+ it 'should not allow tuples of sizes other than the number of variables' do
18
+ lambda do
19
+ @variables.must_be.in([@tuples.first * 2])
20
+ end.should raise_error(ArgumentError)
21
+ end
22
+
23
+ it 'should raise error if the right hand side does not contain tuples of correct type' do
24
+ lambda do
25
+ size = @variables.size
26
+ @variables.must_be.in ['h'*size, 'i'*size]
27
+ end.should raise_error(TypeError)
28
+ end
29
+ end
30
+
31
+ describe Gecode::IntEnum::Extensional, ' (tuple constraint)' do
32
+ before do
33
+ @model = Gecode::Model.new
34
+ @tuples = [[1,7], [5,1]]
35
+ @variables = @digits = @model.int_var_array(2, 0..9)
36
+ @model.branch_on @digits
37
+
38
+ @types = [:int_enum]
39
+ @invoke = lambda do |receiver, hash|
40
+ receiver.in([[1, 7, 5, 3, 0], [8, 9, 9, 9, 0]], hash)
41
+ @model.solve!
42
+ end
43
+ @expect = lambda do |var, opts, reif_var|
44
+ Gecode::Raw.should_receive(:extensional).once.with(
45
+ an_instance_of(Gecode::Raw::Space),
46
+ var, an_instance_of(Gecode::Raw::TupleSet), *opts)
47
+ end
48
+ end
49
+
50
+ it 'should constrain the domain of all variables' do
51
+ @digits.must_be.in @tuples
52
+
53
+ found_solutions = []
54
+ @model.each_solution do |m|
55
+ found_solutions << @digits.values
56
+ end
57
+
58
+ found_solutions.size.should == 2
59
+ (found_solutions - @tuples).should be_empty
60
+ end
61
+
62
+ it 'should raise error if the right hand side is not an enumeration' do
63
+ lambda{ @digits.must_be.in 4711 }.should raise_error(TypeError)
64
+ end
65
+
66
+ it 'should raise error if the right hand side does not contain tuples' do
67
+ lambda{ @digits.must_be.in [17, 4711] }.should raise_error(TypeError)
68
+ end
69
+
70
+ it_should_behave_like 'int tuple constraint'
71
+ it_should_behave_like 'non-reifiable constraint'
72
+ end
73
+
74
+ # Assumes that @variables, @expected_array, @value1, @value2 (must not
75
+ # equal @value1) and @regexp are defined.
76
+ describe 'int regular expression constraint', :shared => true do
77
+ it 'should handle values grouped in a single array' do
78
+ @variables.must.match [@value1, @value2, @value1]
79
+ @model.solve!.should_not be_nil
80
+ @variables.values.should == [@value1, @value2, @value1]
81
+ end
82
+
83
+ it 'should allow nested groups of values' do
84
+ @variables.must.match [@value1, [@value2, [@value1]]]
85
+ @model.solve!.should_not be_nil
86
+ @variables.values.should == [@value1, @value2, @value1]
87
+ end
88
+
89
+ it 'should handle the repeat operation' do
90
+ @variables.must.match [@value1, @model.repeat([@value2], 1, 2)]
91
+ @model.solve!.should_not be_nil
92
+ @variables.values.should == [@value1, @value2, @value2]
93
+ end
94
+
95
+ it 'should handle repeat operations that do not encase constant values in arrays' do
96
+ @variables.must.match [@value1, @model.repeat(@value2, 1, 2)]
97
+ @model.solve!.should_not be_nil
98
+ @variables.values.should == [@value1, @value2, @value2]
99
+ end
100
+
101
+ it 'should handle nested repeat operations' do
102
+ @variables.must.match [[@model.repeat(@model.repeat([@value2], 1, 3), 1, 2)]]
103
+ @model.solve!.should_not be_nil
104
+ @variables.values.should == [@value2, @value2, @value2]
105
+ end
106
+
107
+ it 'should handle nested repeat operations (2)' do
108
+ @variables.must.match [[@model.repeat([@model.repeat(@value2, 1, 3)], 1, 2)]]
109
+ @model.solve!.should_not be_nil
110
+ @variables.values.should == [@value2, @value2, @value2]
111
+ end
112
+
113
+ it 'should interpret the repeat operation with the last argument omitted as only giving a lower bound' do
114
+ @variables.must.match [@value1, @model.repeat([@value2], 1)]
115
+ @model.solve!.should_not be_nil
116
+ @variables.values.should == [@value1, @value2, @value2]
117
+ end
118
+
119
+ it 'should interpret the repeat operation with all but the first argument omitted as not giving any bound' do
120
+ @variables.must.match [@model.repeat(@value2), @value1, @value1, @value1]
121
+ @model.solve!.should_not be_nil
122
+ @variables.values.should == [@value1, @value1, @value1]
123
+ end
124
+
125
+ it 'should interpret the repeat operation with all but the first argument omitted as not giving any bound (2)' do
126
+ @variables.must.match [@model.repeat(@value2)]
127
+ @model.solve!.should_not be_nil
128
+ @variables.values.should == [@value2, @value2, @value2]
129
+ end
130
+
131
+ it 'should translate at_most_once(reg) to repeat(reg, 0, 1)' do
132
+ @model.should_receive(:repeat).once.with([@value1], 0, 1)
133
+ @model.at_most_once [@value1]
134
+ end
135
+
136
+ it 'should translate at_least_once(reg) to repeat(reg, 1)' do
137
+ @model.should_receive(:repeat).once.with([@value1], 1)
138
+ @model.at_least_once [@value1]
139
+ end
140
+
141
+ it 'should raise error if the right hand side is not an enumeration' do
142
+ lambda do
143
+ @variables.must.match Object.new
144
+ end.should raise_error(TypeError)
145
+ end
146
+
147
+ it 'should raise error if the right hand side does not a regexp of the right type' do
148
+ lambda do
149
+ @variables.must.match [@value1, 'foo']
150
+ end.should raise_error(TypeError)
151
+ end
152
+
153
+ it 'should raise error if the right hand side contains a nested element of an incorrect type' do
154
+ lambda do
155
+ @variables.must.match [@value1, [@value2, 'foo']]
156
+ end.should raise_error(TypeError)
157
+ end
158
+
159
+ it 'should raise error if the repeat operation is given arguments of incorrect type (2)' do
160
+ lambda do
161
+ @variables.must.match @model.repeat(@value1, [0], 1)
162
+ end.should raise_error(TypeError)
163
+ end
164
+
165
+ it 'should raise error if the repeat operation is given arguments of incorrect type (3)' do
166
+ lambda do
167
+ @variables.must.match @model.repeat(@value1, 0, [1])
168
+ end.should raise_error(TypeError)
169
+ end
170
+
171
+ it 'should raise error if the repeat operation is given arguments of incorrect type' do
172
+ lambda do
173
+ @variables.must.match @model.repeat('foo', 0, 1)
174
+ end.should raise_error(TypeError)
175
+ end
176
+
177
+ it 'should not allow negation' do
178
+ lambda do
179
+ @variables.must_not.match @regexp
180
+ end.should raise_error(Gecode::MissingConstraintError)
181
+ end
182
+ end
183
+
184
+ describe Gecode::IntEnum::Extensional, ' (regexp constraint)' do
185
+ before do
186
+ @model = Gecode::Model.new
187
+ @variables = @digits = @model.int_var_array(3, 0..9)
188
+ @model.branch_on @digits
189
+ @expected_array = an_instance_of Gecode::Raw::IntVarArray
190
+ @value1 = 3
191
+ @value2 = 5
192
+ @regexp = [1, @model.any(3, 4), @model.at_most_once(5)]
193
+
194
+ @types = [:int_enum]
195
+ @invoke = lambda do |receiver, hash|
196
+ receiver.match(@regexp, hash)
197
+ @model.solve!
198
+ end
199
+ @expect = lambda do |var, opts, reif_var|
200
+ Gecode::Raw.should_receive(:extensional).once.with(
201
+ an_instance_of(Gecode::Raw::Space),
202
+ var, an_instance_of(Gecode::Raw::REG), *opts)
203
+ end
204
+ end
205
+
206
+ it 'should handle the any operation' do
207
+ @digits.must.match [1, @model.any(1, 2, 3), 3]
208
+ @model.solve!.should_not be_nil
209
+ values = @digits.values
210
+ values.size.should == 3
211
+ values.should == values.sort
212
+ end
213
+
214
+ it 'should handle the any operator with nested expressions' do
215
+ @digits.must.match [1, @model.any(@model.at_least_once(2), [3, 5])]
216
+ @digits[2].must < 4
217
+ @model.solve!.should_not be_nil
218
+ @digits.values.should == [1,2,2]
219
+ end
220
+
221
+ it_should_behave_like 'int regular expression constraint'
222
+ it_should_behave_like 'non-reifiable constraint'
223
+ end
224
+