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
@@ -1,285 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- describe Gecode::Constraints::Set::Operation do
5
- before do
6
- @model = Gecode::Model.new
7
- @set1 = @model.set_var([], 0..20)
8
- @set2 = @model.set_var([], 0..20)
9
- @rhs = @model.set_var([], 0..20)
10
- @model.branch_on @model.wrap_enum([@set1, @set2, @rhs])
11
- @constant_set = [4,9,17]
12
- @wrapped_constant_set = @model.wrap_enum(@constant_set)
13
-
14
- @expect = lambda do |op1, operation_type, op2, relation_type, rhs, reif_var, negated|
15
- op1, op2, rhs = [op1, op2, rhs].map do |expression|
16
- # Convert the expression to the corresponding expected class.
17
- if expression.respond_to? :bind
18
- an_instance_of(Gecode::Raw::SetVar)
19
- else
20
- an_instance_of(Gecode::Raw::IntSet)
21
- end
22
- end
23
-
24
- Gecode::Raw.should_receive(:rel).once.with(
25
- an_instance_of(Gecode::Raw::Space), op1, operation_type, op2,
26
- relation_type, rhs)
27
- end
28
-
29
- # For options spec.
30
- @invoke_options = lambda do |hash|
31
- @set1.union(@set2).must_be.superset_of(@rhs, hash)
32
- @model.solve!
33
- end
34
- @expect_options = option_expectation do |strength, kind, reif_var|
35
- @expect.call(@set1, Gecode::Raw::SOT_SUP, @set2, Gecode::Raw::SRT_SUP,
36
- @rhs, reif_var, false)
37
- end
38
- end
39
-
40
- Gecode::Constraints::Util::SET_OPERATION_TYPES.each_pair do |relation, type|
41
- it "should translate #{relation} with variable operands and variable rhs" do
42
- @expect.call(@set1, type, @set2, Gecode::Raw::SRT_SUP, @rhs, nil, false)
43
- @set1.send(relation, @set2).must_be.superset_of(@rhs)
44
- @model.solve!
45
- end
46
-
47
- it "should translate #{relation} with variable operands and constant rhs" do
48
- @expect.call(@set1, type, @set2, Gecode::Raw::SRT_SUP, @constant_set,
49
- nil, false)
50
- @set1.send(relation, @set2).must_be.superset_of(@constant_set)
51
- @model.solve!
52
- end
53
-
54
- it "should translate #{relation} with variable lhs, constant operand and variable rhs" do
55
- @expect.call(@set1, type, @constant_set, Gecode::Raw::SRT_SUP, @rhs, nil,
56
- false)
57
- @set1.send(relation, @constant_set).must_be.superset_of(@rhs)
58
- @model.solve!
59
- end
60
-
61
- it "should translate #{relation} with variable lhs, constant operand and constant rhs" do
62
- @expect.call(@set1, type, @constant_set, Gecode::Raw::SRT_SUP,
63
- @constant_set, nil, false)
64
- @set1.send(relation, @constant_set).must_be.superset_of(@constant_set)
65
- @model.solve!
66
- end
67
-
68
- it "should translate #{relation} with constant lhs, variable operand and variable rhs" do
69
- @expect.call(@constant_set, type, @set2, Gecode::Raw::SRT_SUP,
70
- @rhs, nil, false)
71
- @wrapped_constant_set.send(relation, @set2).must_be.superset_of(@rhs)
72
- @model.solve!
73
- end
74
-
75
- it "should translate #{relation} with constant lhs, variable operand and constant rhs" do
76
- @expect.call(@constant_set, type, @set2, Gecode::Raw::SRT_SUP,
77
- @constant_set, nil, false)
78
- @wrapped_constant_set.send(relation, @set2).must_be.superset_of(@constant_set)
79
- @model.solve!
80
- end
81
-
82
- it "should raise error for #{relation} with constant lhs, operand and rhs" do
83
- lambda do
84
- @wrapped_constant_set.send(relation, @constant_set).must_be.superset_of(
85
- @constant_set)
86
- end.should raise_error(ArgumentError)
87
- end
88
- end
89
-
90
- it 'should raise error if negated' do
91
- lambda do
92
- @set1.union(@set2).must_not_be.subset_of(@rhs)
93
- end.should raise_error(Gecode::MissingConstraintError)
94
- end
95
-
96
- it 'should constrain the sets according to the operation (variable operands, variable rhs)' do
97
- @set1.intersection(@set2).must == @rhs
98
- @rhs.must == @constant_set
99
- @model.solve!.should_not be_nil
100
- (@set1.value.to_a & @set2.value.to_a).sort.should == @constant_set
101
- end
102
-
103
- it 'should constrain the sets according to the operation (variable operands, constant rhs)' do
104
- @set1.intersection(@set2).must == @constant_set
105
- @model.solve!.should_not be_nil
106
- (@set1.value.to_a & @set2.value.to_a).sort.should == @constant_set
107
- end
108
-
109
- it 'should constrain the sets according to the operation (variable lhs, constant operand and rhs)' do
110
- @set1.union(@constant_set).must == @constant_set
111
- @model.solve!.should_not be_nil
112
- (@set1.value.to_a + @constant_set).uniq.sort.should == @constant_set.sort
113
- end
114
-
115
- it 'should constrain the sets according to the operation (variable lhs and rhs, constant operand)' do
116
- @set1.union(@constant_set).must == @rhs
117
- @model.solve!.should_not be_nil
118
- (@set1.value.to_a + @constant_set).uniq.sort.should == @rhs.value.to_a.sort
119
- end
120
-
121
- it 'should constrain the sets according to the operation (constant lhs, variable operand and rhs)' do
122
- @wrapped_constant_set.minus(@set2).must == @rhs
123
- @model.solve!.should_not be_nil
124
- (@constant_set - @set2.value.to_a).sort.should == @rhs.value.sort
125
- end
126
-
127
- it 'should constrain the sets according to the operation (constant lhs and rhs, variable operand)' do
128
- @wrapped_constant_set.minus(@set2).must == @constant_set
129
- @model.solve!.should_not be_nil
130
- (@constant_set - @set2.value.to_a).sort.should == @constant_set
131
- end
132
-
133
- it_should_behave_like 'non-reifiable set constraint'
134
- end
135
-
136
- describe 'set enum operation constraint', :shared => true do
137
- include GecodeR::Specs::SetHelper
138
-
139
- before do
140
- @expect = lambda do |enum, operation_type, relation, rhs, reif_var, negated|
141
- if rhs.respond_to? :bind
142
- expected_target = [an_instance_of(Gecode::Raw::SetVar)]
143
- relation_constraint = :rel
144
- else
145
- expected_target = expect_constant_set(rhs)
146
- relation_constraint = :dom
147
- end
148
-
149
- if reif_var.nil?
150
- if !negated and relation == Gecode::Raw::IRT_EQ and
151
- !rhs.kind_of? Enumerable
152
- Gecode::Raw.should_receive(:rel).once.with(
153
- an_instance_of(Gecode::Raw::Space), operation_type,
154
- an_instance_of(Gecode::Raw::SetVarArray),
155
- *expected_target)
156
- Gecode::Raw.should_receive(:dom).exactly(0).times
157
- else
158
- if relation_constraint == :rel
159
- Gecode::Raw.should_receive(:rel).twice
160
- else
161
- Gecode::Raw.should_receive(:rel).once.with(
162
- an_instance_of(Gecode::Raw::Space), operation_type,
163
- an_instance_of(Gecode::Raw::SetVarArray),
164
- an_instance_of(Gecode::Raw::SetVar))
165
- Gecode::Raw.should_receive(relation_constraint).at_most(:twice)
166
- end
167
- end
168
- else
169
- if relation_constraint == :rel
170
- Gecode::Raw.should_receive(:rel).twice
171
- else
172
- Gecode::Raw.should_receive(:rel).once.with(
173
- an_instance_of(Gecode::Raw::Space), operation_type,
174
- an_instance_of(Gecode::Raw::SetVarArray),
175
- an_instance_of(Gecode::Raw::SetVar))
176
- expected_target << an_instance_of(Gecode::Raw::BoolVar)
177
- Gecode::Raw.should_receive(relation_constraint).once.with(
178
- an_instance_of(Gecode::Raw::Space),
179
- an_instance_of(Gecode::Raw::SetVar), relation, *expected_target)
180
- end
181
- end
182
- end
183
-
184
- # For composite spec.
185
- @invoke_relation = lambda do |relation, target, negated|
186
- if negated
187
- @stub.must_not.send(relation, target)
188
- else
189
- @stub.must.send(relation, target)
190
- end
191
- @model.solve!
192
- end
193
- @expect_relation = lambda do |relation, target, negated|
194
- @expect.call(@sets, @operation_type, relation, target, nil, negated)
195
- end
196
-
197
- # For options spec.
198
- @invoke_options = lambda do |hash|
199
- @stub.must_be.superset_of(@rhs, hash)
200
- @model.solve!
201
- end
202
- @expect_options = option_expectation do |strength, kind, reif_var|
203
- @expect.call(@sets, @operation_type, Gecode::Raw::SRT_SUP, @rhs,
204
- reif_var, false)
205
- end
206
- end
207
-
208
- it_should_behave_like 'reifiable set constraint'
209
- it_should_behave_like 'composite set constraint'
210
- end
211
-
212
- describe Gecode::Constraints::SetEnum::Operation, ' (union)' do
213
- before do
214
- @model = Gecode::Model.new
215
- @sets = @model.set_var_array(10, [], 0..20)
216
- @target = @rhs = @model.set_var([], 0..20)
217
- @model.branch_on @sets
218
-
219
- @stub = @sets.union
220
- @operation_type = Gecode::Raw::SOT_UNION
221
- end
222
-
223
- it 'should constrain the union of the sets' do
224
- @sets.union.must_be.subset_of [1,4,17]
225
- @sets.union.must_be.superset_of 1
226
- @model.solve!.should_not be_nil
227
- union = @sets.values.inject([]){ |union, set| union += set.to_a }.uniq
228
- union.should include(1)
229
- (union - [1,4,17]).should be_empty
230
- end
231
-
232
- it_should_behave_like 'set enum operation constraint'
233
- end
234
-
235
- describe Gecode::Constraints::SetEnum::Operation, ' (intersection)' do
236
- before do
237
- @model = Gecode::Model.new
238
- @sets = @model.set_var_array(10, [], 0..20)
239
- @target = @rhs = @model.set_var([], 0..20)
240
- @model.branch_on @sets
241
-
242
- @stub = @sets.intersection
243
- @operation_type = Gecode::Raw::SOT_INTER
244
- end
245
-
246
- it 'should constrain the intersection of the sets' do
247
- @sets.intersection.must_be.subset_of [1,4,17]
248
- @sets.intersection.must_be.superset_of [1]
249
- @model.solve!.should_not be_nil
250
- intersection = @sets.values.inject(nil) do |intersection, set|
251
- next set.to_a if intersection.nil?
252
- intersection &= set.to_a
253
- end.uniq
254
- intersection.should include(1)
255
- (intersection - [1,4,17]).should be_empty
256
- end
257
-
258
- it_should_behave_like 'set enum operation constraint'
259
- end
260
-
261
- describe Gecode::Constraints::SetEnum::Operation, ' (disjoint union)' do
262
- before do
263
- @model = Gecode::Model.new
264
- @sets = @model.set_var_array(10, [], 0..20)
265
- @target = @rhs = @model.set_var([], 0..20)
266
- @model.branch_on @sets
267
-
268
- @stub = @sets.disjoint_union
269
- @operation_type = Gecode::Raw::SOT_DUNION
270
- end
271
-
272
- it 'should constrain the disjoint union of the sets' do
273
- @sets.disjoint_union.must_be.subset_of [1,4,17]
274
- @sets.disjoint_union.must_be.superset_of [1]
275
- @model.solve!.should_not be_nil
276
- disjoint_union = @sets.values.inject([]) do |union, set|
277
- intersection = union & set.to_a
278
- union += set.to_a - intersection
279
- end.uniq
280
- disjoint_union.should include(1)
281
- (disjoint_union - [1,4,17]).should be_empty
282
- end
283
-
284
- it_should_behave_like 'set enum operation constraint'
285
- end
@@ -1,197 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- describe Gecode::Constraints::Set::Relation do
5
- include GecodeR::Specs::SetHelper
6
-
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
-
12
- @expect = lambda do |relation_type, rhs, reif_var, negated|
13
- @model.allow_space_access do
14
- if reif_var.nil? and !negated
15
- Gecode::Raw.should_receive(:rel).once.with(
16
- an_instance_of(Gecode::Raw::Space),
17
- an_instance_of(Gecode::Raw::SetVar), relation_type,
18
- an_instance_of(Gecode::Raw::SetVar))
19
- else
20
- Gecode::Raw.should_receive(:rel).once.with(
21
- an_instance_of(Gecode::Raw::Space),
22
- an_instance_of(Gecode::Raw::SetVar), relation_type,
23
- an_instance_of(Gecode::Raw::SetVar),
24
- an_instance_of(Gecode::Raw::BoolVar))
25
- end
26
- end
27
- end
28
-
29
- # For options spec.
30
- @invoke_options = lambda do |hash|
31
- @set.must_be.superset_of(@set2, hash)
32
- @model.solve!
33
- end
34
- @expect_options = option_expectation do |strength, kind, reif_var|
35
- @expect.call(Gecode::Raw::SRT_SUP, @set2, reif_var, false)
36
- end
37
- end
38
-
39
- Gecode::Constraints::Util::SET_RELATION_TYPES.each_pair do |relation, type|
40
- next if relation == :==
41
-
42
- it "should translate #{relation} with set to relation constraint" do
43
- @expect.call(type, @set2, nil, false)
44
- @set.must.send(relation, @set2)
45
- @model.solve!
46
- end
47
-
48
- it "should translate negated #{relation} with set to relation constraint" do
49
- @expect.call(type, @set2, nil, true)
50
- @set.must_not.send(relation, @set2)
51
- @model.solve!
52
- end
53
- end
54
- it_should_behave_like 'reifiable set constraint'
55
- end
56
-
57
- describe Gecode::Constraints::Set::Relation, ' (equality)' do
58
- include GecodeR::Specs::SetHelper
59
-
60
- before do
61
- @model = Gecode::Model.new
62
- @set = @model.set_var([0], 0..1)
63
- @set2 = @model.set_var([1], 0..1)
64
-
65
- @expect = lambda do |relation_type, rhs, reif_var|
66
- @model.allow_space_access do
67
- if reif_var.nil?
68
- Gecode::Raw.should_receive(:rel).once.with(
69
- an_instance_of(Gecode::Raw::Space),
70
- an_instance_of(Gecode::Raw::SetVar), relation_type,
71
- an_instance_of(Gecode::Raw::SetVar))
72
- else
73
- Gecode::Raw.should_receive(:rel).once.with(
74
- an_instance_of(Gecode::Raw::Space),
75
- an_instance_of(Gecode::Raw::SetVar), relation_type,
76
- an_instance_of(Gecode::Raw::SetVar),
77
- an_instance_of(Gecode::Raw::BoolVar))
78
- end
79
- end
80
- end
81
-
82
- # For options spec.
83
- @invoke_options = lambda do |hash|
84
- @set.must_be.equal_to(@set2, hash)
85
- @model.solve!
86
- end
87
- @expect_options = option_expectation do |strength, kind, reif_var|
88
- @expect.call(Gecode::Raw::SRT_EQ, @set2, reif_var)
89
- end
90
- end
91
-
92
- it 'should translate equality with set to relation constraint' do
93
- @expect.call(Gecode::Raw::SRT_EQ, @set2, nil)
94
- @set.must == @set2
95
- @model.solve!
96
- end
97
-
98
- it 'should translate negated equality with set to domain constraint' do
99
- @expect.call(Gecode::Raw::SRT_NQ, @set2, nil)
100
- @set.must_not == @set2
101
- @model.solve!
102
- end
103
-
104
- it 'should constrain sets to be equality when not negated' do
105
- @set.must == @set2
106
- @model.solve!
107
- @set.should have_bounds(0..1, 0..1)
108
- @set2.should have_bounds(0..1, 0..1)
109
- end
110
-
111
- it 'should constrain sets to not be equal when negated' do
112
- @set.must_not == @set2
113
- union = @model.set_var([0, 1], [0, 1])
114
- @set.must_not == union
115
- @set2.must_not == union
116
- @model.solve!
117
- @set.should have_bounds([0], [0])
118
- @set2.should have_bounds([1], [1])
119
- end
120
-
121
- it_should_behave_like 'reifiable set constraint'
122
- end
123
-
124
- describe Gecode::Constraints::Set::Relation, ' (elements)' do
125
- include GecodeR::Specs::SetHelper
126
-
127
- before do
128
- @model = Gecode::Model.new
129
- @set = @model.set_var([0], 0..2)
130
- @int_var = @model.int_var(0..2)
131
- @int_constant = 2
132
- @model.branch_on @model.wrap_enum([@set])
133
- @expect = lambda do |relation_type, rhs|
134
- @model.allow_space_access do
135
- if rhs.kind_of? Fixnum
136
- rhs = an_instance_of(Gecode::Raw::IntVar)
137
- end
138
- rhs = rhs.bind if rhs.respond_to? :bind
139
- Gecode::Raw.should_receive(:rel).once.with(
140
- an_instance_of(Gecode::Raw::Space),
141
- an_instance_of(Gecode::Raw::SetVar), relation_type,
142
- an_instance_of(Gecode::Raw::IntVar))
143
- end
144
- end
145
-
146
- @invoke_options = lambda do |hash|
147
- @set.elements.must_be.equal_to(@int_var, hash)
148
- end
149
- end
150
-
151
- Gecode::Constraints::Util::RELATION_TYPES.each_pair do |relation, type|
152
- it "should translate #{relation} with variable to relation constraint" do
153
- @expect.call(type, @int_var)
154
- @set.elements.must.send(relation, @int_var)
155
- @model.solve!
156
- end
157
-
158
- it "should translate #{relation} with constant to relation constraint" do
159
- @expect.call(type, @int_constant)
160
- @set.elements.must.send(relation, @int_constant)
161
- @model.solve!
162
- end
163
- end
164
-
165
- Gecode::Constraints::Util::NEGATED_RELATION_TYPES.each_pair do |relation, type|
166
- it "should translate negated #{relation} with variable to relation constraint" do
167
- @expect.call(type, @int_var)
168
- @set.elements.must_not.send(relation, @int_var)
169
- @model.solve!
170
- end
171
-
172
- it "should translate negated #{relation} with constant to relation constraint" do
173
- @expect.call(type, @int_constant)
174
- @set.elements.must_not.send(relation, @int_constant)
175
- @model.solve!
176
- end
177
- end
178
-
179
- it 'should constrain the elements of the set' do
180
- @set.elements.must <= @int_var
181
- @int_var.must == 0
182
- @model.solve!
183
- @set.should be_assigned
184
- @set.value.should include(0)
185
- @set.value.should_not include(1,2)
186
- end
187
-
188
- it 'should constrain the elements of the set (constant parameter)' do
189
- @set.elements.must <= 0
190
- @model.solve!
191
- @set.should be_assigned
192
- @set.value.should include(0)
193
- @set.value.should_not include(1,2)
194
- end
195
-
196
- it_should_behave_like 'non-reifiable set constraint'
197
- end
@@ -1,179 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper'
2
- require File.dirname(__FILE__) + '/constraint_helper'
3
-
4
- class SortSampleProblem < Gecode::Model
5
- attr :vars
6
- attr :sorted
7
- attr :indices
8
-
9
- def initialize
10
- @vars = int_var_array(4, 10..19)
11
- @sorted = int_var_array(4, 10..19)
12
- @indices = int_var_array(4, 0..9)
13
-
14
- # To make it more interesting
15
- @vars.must_be.distinct
16
-
17
- branch_on @vars
18
- end
19
- end
20
-
21
- describe Gecode::Constraints::IntEnum::Sort, ' (without :as and :order)' do
22
- before do
23
- @model = SortSampleProblem.new
24
- @vars = @model.vars
25
- @sorted = @model.sorted
26
-
27
- @invoke_options = lambda do |hash|
28
- @vars.must_be.sorted(hash)
29
- @model.solve!
30
- end
31
- @expect_options = option_expectation do |strength, kind, reif_var|
32
- if reif_var.nil?
33
- Gecode::Raw.should_receive(:rel).exactly(@vars.size - 1).times.with(
34
- an_instance_of(Gecode::Raw::Space),
35
- an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_LQ,
36
- an_instance_of(Gecode::Raw::IntVar), strength, kind)
37
- else
38
- Gecode::Raw.should_receive(:rel).once.with(
39
- an_instance_of(Gecode::Raw::Space), anything,
40
- an_instance_of(Gecode::Raw::BoolVarArray),
41
- anything, anything, anything)
42
- Gecode::Raw.should_receive(:rel).exactly(@vars.size - 1).times.with(
43
- an_instance_of(Gecode::Raw::Space),
44
- an_instance_of(Gecode::Raw::IntVar), Gecode::Raw::IRT_LQ,
45
- an_instance_of(Gecode::Raw::IntVar),
46
- an_instance_of(Gecode::Raw::BoolVar), strength, kind)
47
- end
48
- end
49
- end
50
-
51
- it 'should translate into n relation constraints' do
52
- @expect_options.call({})
53
- @invoke_options.call({})
54
- end
55
-
56
- it 'should constraint variables to be sorted' do
57
- @vars.must_be.sorted
58
- values = @model.solve!.vars.values
59
- values.should == values.sort
60
- end
61
-
62
- it 'should allow negation' do
63
- @vars.must_not_be.sorted
64
- @model.solve!
65
- values = @vars.values
66
- values.should_not == values.sort
67
- end
68
-
69
- it_should_behave_like 'reifiable constraint'
70
- end
71
-
72
- describe Gecode::Constraints::IntEnum::Sort, ' (with :as)' do
73
- before do
74
- @model = SortSampleProblem.new
75
- @vars = @model.vars
76
- @sorted = @model.sorted
77
-
78
- # Make it a bit more interesting.
79
- @vars[0].must > @vars[3] + 1
80
-
81
- @invoke_options = lambda do |hash|
82
- @vars.must_be.sorted hash.update(:as => @sorted)
83
- @model.solve!
84
- end
85
- @expect_options = option_expectation do |strength, kind, reif_var|
86
- Gecode::Raw.should_receive(:sorted).once.with(
87
- an_instance_of(Gecode::Raw::Space),
88
- an_instance_of(Gecode::Raw::IntVarArray),
89
- an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
90
- end
91
- end
92
-
93
- it 'should translate into a sortedness constraints' do
94
- @expect_options.call({})
95
- @invoke_options.call({})
96
- end
97
-
98
- it 'should constraint variables to be sorted' do
99
- @vars.must_be.sorted(:as => @sorted)
100
- @model.solve!
101
- values = @sorted.values
102
- values.should == values.sort
103
- end
104
-
105
- it 'should not allow targets that are not int var enums' do
106
- lambda{ @vars.must_be.sorted(:as => 'hello') }.should raise_error(TypeError)
107
- end
108
-
109
- it 'should not allow negation' do
110
- lambda{ @vars.must_not_be.sorted(:as => @sorted) }.should raise_error(
111
- Gecode::MissingConstraintError)
112
- end
113
-
114
- it_should_behave_like 'non-reifiable constraint'
115
- end
116
-
117
- describe Gecode::Constraints::IntEnum::Sort, ' (with :order)' do
118
- before do
119
- @model = SortSampleProblem.new
120
- @vars = @model.vars
121
- @sorted = @model.sorted
122
- @indices = @model.indices
123
-
124
- # Make it a bit more interesting.
125
- @vars[0].must > @vars[3] + 1
126
-
127
- @invoke_options = lambda do |hash|
128
- @vars.must_be.sorted hash.update(:order => @indices, :as => @sorted)
129
- @model.solve!
130
- end
131
- @expect_options = option_expectation do |strength, kind, reif_var|
132
- Gecode::Raw.should_receive(:sorted).once.with(
133
- an_instance_of(Gecode::Raw::Space),
134
- an_instance_of(Gecode::Raw::IntVarArray),
135
- an_instance_of(Gecode::Raw::IntVarArray),
136
- an_instance_of(Gecode::Raw::IntVarArray), strength, kind)
137
- end
138
- end
139
-
140
- it 'should translate into a sortedness constraints' do
141
- @expect_options.call({})
142
- @invoke_options.call({})
143
- end
144
-
145
- it 'should translate into a sortedness constraints, even without a target' do
146
- @expect_options.call({})
147
- @vars.must_be.sorted(:order => @indices)
148
- @model.solve!
149
- end
150
-
151
- it 'should constraint variables to be sorted with the specified indices' do
152
- @vars.must_be.sorted(:as => @sorted, :order => @indices)
153
- @model.solve!
154
- sorted_values = @sorted.values
155
- sorted_values.should == sorted_values.sort
156
- expected_indices = @vars.map{ |v| sorted_values.index(v.value) }
157
- @indices.values.should == expected_indices
158
- end
159
-
160
- it 'should not allow targets that are not int var enums' do
161
- lambda do
162
- @vars.must_be.sorted(:as => 'hello', :order => @indices)
163
- end.should raise_error(TypeError)
164
- end
165
-
166
- it 'should not allow order that are not int var enums' do
167
- lambda do
168
- @vars.must_be.sorted(:as => @sorted, :order => 'hello')
169
- end.should raise_error(TypeError)
170
- end
171
-
172
- it 'should not allow negation' do
173
- lambda do
174
- @vars.must_not_be.sorted(:as => @sorted, :order => @indices)
175
- end.should raise_error(Gecode::MissingConstraintError)
176
- end
177
-
178
- it_should_behave_like 'non-reifiable constraint'
179
- end