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.
- data/CHANGES +15 -0
- data/README +6 -2
- data/example/equation_system.rb +15 -0
- data/example/magic_sequence.rb +7 -7
- data/example/money.rb +36 -0
- data/example/queens.rb +7 -8
- data/example/send_most_money.rb +1 -1
- data/example/square_tiling.rb +2 -2
- data/example/sudoku-set.rb +11 -12
- data/example/sudoku.rb +40 -45
- data/ext/extconf.rb +0 -0
- data/ext/gecode-2.1.1/LICENSE +0 -0
- data/ext/gecode-2.1.1/configure +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/SDFVariableHeuristic.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/SDFVariableHeuristic.hh +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/configure +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/extensivecomparator.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/extensivecomparator.hh +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/heap.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/implicative.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/implicative.hh +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/myspace.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/myspace.hh +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/qecore.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/qecore.hh +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/warner.cc +0 -0
- data/ext/gecode-2.1.1/contribs/qecode/warner.hh +0 -0
- data/ext/gecode-2.1.1/gecode/cpltset/var-imp/cpltset.vis +0 -0
- data/ext/gecode-2.1.1/gecode/int/arithmetic/abs.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/arithmetic/max.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/arithmetic/mult.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/arithmetic/sqr.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/arithmetic/sqrt.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/array.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/array.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/bool/base.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/bool/eq.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/bool/eqv.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/bool/lq.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/bool/or.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/branch/select-val.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/branch/select-view.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/branch.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/branch.hh +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/base.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/dom.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/link-multi.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/link-multi.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/link-single.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/link-single.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel/val.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/channel.hh +0 -0
- data/ext/gecode-2.1.1/gecode/int/circuit/base.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/circuit/dom.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/circuit/val.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/circuit.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/circuit.hh +0 -0
- data/ext/gecode-2.1.1/gecode/int/count/int.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/count/rel.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/count/view.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/bilink.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/bnd.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/combptr.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/dom.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/edge.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/node.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/ter-dom.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/distinct/val.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/dom/range.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/dom/spec.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/dom.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/dom.hh +0 -0
- data/ext/gecode-2.1.1/gecode/int/element/int.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/element/view.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/element.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/element.hh +0 -0
- data/ext/gecode-2.1.1/gecode/int/exception.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/extensional/dfa.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/extensional/dfa.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/extensional/layered-graph.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/gcc/dom.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/gcc/gccbndsup.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/gcc/lbc.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/gcc/ubc.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/gcc.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/gcc.hh +0 -0
- data/ext/gecode-2.1.1/gecode/int/int-set.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/int-set.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/bool-int.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/bool-post.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/bool-scale.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/bool-view.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/int-bin.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/int-dom.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/int-nary.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/int-post.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/int-ter.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/linear/post.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/propagator.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/rel/eq.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/rel/lex.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/rel/lq-le.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/rel/nq.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/unshare.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/var/bool.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/var-imp/bool.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/var-imp/bool.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/var-imp/bool.vis +0 -0
- data/ext/gecode-2.1.1/gecode/int/var-imp/delta.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/var-imp/int.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/var-imp/int.vis +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/bool.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/constint.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/int.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/iter.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/minus.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/offset.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/print.cc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/rtest.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/scale.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view/zero.icc +0 -0
- data/ext/gecode-2.1.1/gecode/int/view.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-add.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-append.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-array.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-cache.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-compl.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-diff.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-empty.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-inter.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-minmax.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-minus.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-offset.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-operations.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-scale.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-singleton-append.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-singleton.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-union.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/ranges-values.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/values-array.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/values-minus.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/values-offset.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/values-ranges.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/values-singleton.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter/values-unique.icc +0 -0
- data/ext/gecode-2.1.1/gecode/iter.hh +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/advisor.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/array.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/branching.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/exception.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/macros.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/memory-manager.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/modevent.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/propagator.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/shared-array.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/var-traits.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/var.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel/view.icc +0 -0
- data/ext/gecode-2.1.1/gecode/kernel.hh +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/arithmetic.cc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/bool-expr.cc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/bool-expr.icc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/bool-rel.icc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/lin-expr.icc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/lin-rel.icc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel/reg.cc +0 -0
- data/ext/gecode-2.1.1/gecode/minimodel.hh +0 -0
- data/ext/gecode-2.1.1/gecode/search/bab.cc +0 -0
- data/ext/gecode-2.1.1/gecode/search/bab.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/dfs.cc +0 -0
- data/ext/gecode-2.1.1/gecode/search/dfs.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/engine-ctrl.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/lds.cc +0 -0
- data/ext/gecode-2.1.1/gecode/search/lds.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/options.cc +0 -0
- data/ext/gecode-2.1.1/gecode/search/options.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/reco-stack.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/restart.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/statistics.icc +0 -0
- data/ext/gecode-2.1.1/gecode/search/stop.cc +0 -0
- data/ext/gecode-2.1.1/gecode/search/stop.icc +0 -0
- data/ext/gecode-2.1.1/gecode/set/var-imp/set.vis +0 -0
- data/ext/gecode-2.1.1/gecode/support/block-allocator.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/cast.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/exception.cc +0 -0
- data/ext/gecode-2.1.1/gecode/support/exception.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/macros.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/marked-pointer.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/memory.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/sentinel-stack.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/static-stack.icc +0 -0
- data/ext/gecode-2.1.1/gecode/support/symbol.cc +0 -0
- data/ext/gecode-2.1.1/gecode/support.hh +0 -0
- data/ext/gecode-2.1.1/install-sh +0 -0
- data/ext/gecode-2.1.1/misc/debian/rules +0 -0
- data/ext/gecode-2.1.1/misc/doxygen/back.png +0 -0
- data/ext/gecode-2.1.1/misc/doxygen/gecode-logo-100.png +0 -0
- data/ext/gecode-2.1.1/misc/genchangelog.perl +0 -0
- data/ext/gecode-2.1.1/misc/genlicense.perl +0 -0
- data/ext/gecode-2.1.1/misc/genstatistics.perl +0 -0
- data/ext/gecode-2.1.1/misc/genvariables.perl +0 -0
- data/ext/gecode-2.1.1/misc/getrevision.perl +0 -0
- data/ext/gecode-2.1.1/misc/makedepend.perl +0 -0
- data/ext/gecode-2.1.1/misc/svn-ignore.txt +0 -0
- data/ext/gecode-2.1.1/variables.vsl +0 -0
- data/lib/gecoder/bindings/bindings.rb +16 -0
- data/lib/gecoder/bindings.rb +42 -0
- data/lib/gecoder/interface/branch.rb +16 -9
- data/lib/gecoder/interface/constraints/bool/boolean.rb +205 -213
- data/lib/gecoder/interface/constraints/bool/channel.rb +4 -5
- data/lib/gecoder/interface/constraints/bool/linear.rb +192 -21
- data/lib/gecoder/interface/constraints/bool_enum/channel.rb +43 -39
- data/lib/gecoder/interface/constraints/bool_enum/extensional.rb +43 -49
- data/lib/gecoder/interface/constraints/bool_enum/relation.rb +38 -71
- data/lib/gecoder/interface/constraints/bool_enum_constraints.rb +73 -22
- data/lib/gecoder/interface/constraints/bool_var_constraints.rb +140 -61
- data/lib/gecoder/interface/constraints/extensional_regexp.rb +4 -4
- data/lib/gecoder/interface/constraints/fixnum_enum/element.rb +63 -0
- data/lib/gecoder/interface/constraints/fixnum_enum/operation.rb +65 -0
- data/lib/gecoder/interface/constraints/fixnum_enum_constraints.rb +42 -0
- data/lib/gecoder/interface/constraints/int/arithmetic.rb +131 -130
- data/lib/gecoder/interface/constraints/int/channel.rb +21 -31
- data/lib/gecoder/interface/constraints/int/domain.rb +45 -42
- data/lib/gecoder/interface/constraints/int/linear.rb +85 -239
- data/lib/gecoder/interface/constraints/int/relation.rb +141 -0
- data/lib/gecoder/interface/constraints/int_enum/arithmetic.rb +55 -64
- data/lib/gecoder/interface/constraints/int_enum/channel.rb +35 -37
- data/lib/gecoder/interface/constraints/int_enum/count.rb +53 -78
- data/lib/gecoder/interface/constraints/int_enum/distinct.rb +36 -46
- data/lib/gecoder/interface/constraints/int_enum/element.rb +39 -57
- data/lib/gecoder/interface/constraints/int_enum/equality.rb +15 -19
- data/lib/gecoder/interface/constraints/int_enum/extensional.rb +65 -72
- data/lib/gecoder/interface/constraints/int_enum/sort.rb +42 -45
- data/lib/gecoder/interface/constraints/int_enum_constraints.rb +79 -22
- data/lib/gecoder/interface/constraints/int_var_constraints.rb +215 -44
- data/lib/gecoder/interface/constraints/reifiable_constraints.rb +14 -14
- data/lib/gecoder/interface/constraints/selected_set/select.rb +120 -0
- data/lib/gecoder/interface/constraints/selected_set_constraints.rb +75 -0
- data/lib/gecoder/interface/constraints/set/cardinality.rb +43 -53
- data/lib/gecoder/interface/constraints/set/channel.rb +26 -29
- data/lib/gecoder/interface/constraints/set/connection.rb +89 -152
- data/lib/gecoder/interface/constraints/set/domain.rb +112 -65
- data/lib/gecoder/interface/constraints/set/include.rb +36 -0
- data/lib/gecoder/interface/constraints/set/operation.rb +96 -110
- data/lib/gecoder/interface/constraints/set/relation.rb +114 -137
- data/lib/gecoder/interface/constraints/set_elements/relation.rb +116 -0
- data/lib/gecoder/interface/constraints/set_elements_constraints.rb +97 -0
- data/lib/gecoder/interface/constraints/set_enum/channel.rb +23 -27
- data/lib/gecoder/interface/constraints/set_enum/distinct.rb +18 -19
- data/lib/gecoder/interface/constraints/set_enum/operation.rb +62 -53
- data/lib/gecoder/interface/constraints/set_enum/select.rb +79 -0
- data/lib/gecoder/interface/constraints/set_enum_constraints.rb +73 -23
- data/lib/gecoder/interface/constraints/set_var_constraints.rb +222 -57
- data/lib/gecoder/interface/constraints.rb +410 -451
- data/lib/gecoder/interface/enum_matrix.rb +4 -4
- data/lib/gecoder/interface/enum_wrapper.rb +71 -22
- data/lib/gecoder/interface/model.rb +167 -12
- data/lib/gecoder/interface/model_sugar.rb +84 -0
- data/lib/gecoder/interface/search.rb +30 -18
- data/lib/gecoder/interface/variables.rb +103 -33
- data/lib/gecoder/interface.rb +2 -1
- data/lib/gecoder/version.rb +2 -2
- data/specs/bool_var.rb +19 -12
- data/specs/constraints/{boolean.rb → bool/boolean.rb} +103 -28
- data/specs/constraints/bool/boolean_properties.rb +51 -0
- data/specs/constraints/bool/linear.rb +213 -0
- data/specs/constraints/bool_enum/bool_enum_relation.rb +117 -0
- data/specs/constraints/bool_enum/channel.rb +102 -0
- data/specs/constraints/{extensional.rb → bool_enum/extensional.rb} +32 -101
- data/specs/constraints/constraint_helper.rb +149 -179
- data/specs/constraints/constraint_receivers.rb +103 -0
- data/specs/constraints/constraints.rb +6 -63
- data/specs/constraints/fixnum_enum/element.rb +58 -0
- data/specs/constraints/fixnum_enum/operation.rb +67 -0
- data/specs/constraints/int/arithmetic.rb +149 -0
- data/specs/constraints/int/channel.rb +101 -0
- data/specs/constraints/int/domain.rb +106 -0
- data/specs/constraints/int/linear.rb +183 -0
- data/specs/constraints/int/linear_properties.rb +97 -0
- data/specs/constraints/int/relation.rb +84 -0
- data/specs/constraints/int_enum/arithmetic.rb +72 -0
- data/specs/constraints/int_enum/channel.rb +57 -0
- data/specs/constraints/int_enum/count.rb +72 -0
- data/specs/constraints/int_enum/distinct.rb +80 -0
- data/specs/constraints/int_enum/element.rb +61 -0
- data/specs/constraints/int_enum/equality.rb +29 -0
- data/specs/constraints/int_enum/extensional.rb +224 -0
- data/specs/constraints/int_enum/sort.rb +167 -0
- data/specs/constraints/operands.rb +264 -0
- data/specs/constraints/property_helper.rb +443 -0
- data/specs/constraints/reification_sugar.rb +4 -5
- data/specs/constraints/selected_set/select.rb +56 -0
- data/specs/constraints/selected_set/select_properties.rb +157 -0
- data/specs/constraints/set/cardinality.rb +58 -0
- data/specs/constraints/set/cardinality_properties.rb +46 -0
- data/specs/constraints/set/channel.rb +77 -0
- data/specs/constraints/set/connection.rb +176 -0
- data/specs/constraints/set/domain.rb +197 -0
- data/specs/constraints/set/include.rb +36 -0
- data/specs/constraints/set/operation.rb +132 -0
- data/specs/constraints/set/relation.rb +117 -0
- data/specs/constraints/set_elements/relation.rb +84 -0
- data/specs/constraints/set_enum/channel.rb +80 -0
- data/specs/constraints/set_enum/distinct.rb +59 -0
- data/specs/constraints/set_enum/operation.rb +111 -0
- data/specs/constraints/set_enum/select.rb +73 -0
- data/specs/enum_wrapper.rb +53 -3
- data/specs/int_var.rb +44 -25
- data/specs/model.rb +58 -1
- data/specs/model_sugar.rb +30 -0
- data/specs/search.rb +24 -5
- data/specs/selected_set.rb +39 -0
- data/specs/set_elements.rb +34 -0
- data/specs/set_var.rb +22 -8
- data/specs/spec_helper.rb +206 -6
- data/tasks/distribution.rake +22 -7
- data/tasks/svn.rake +3 -1
- metadata +219 -135
- data/lib/gecoder/interface/constraints/set_enum/selection.rb +0 -217
- data/specs/constraints/arithmetic.rb +0 -351
- data/specs/constraints/bool_enum_relation.rb +0 -160
- data/specs/constraints/cardinality.rb +0 -157
- data/specs/constraints/channel.rb +0 -454
- data/specs/constraints/connection.rb +0 -369
- data/specs/constraints/count.rb +0 -146
- data/specs/constraints/distinct.rb +0 -164
- data/specs/constraints/element.rb +0 -108
- data/specs/constraints/equality.rb +0 -31
- data/specs/constraints/int_domain.rb +0 -70
- data/specs/constraints/int_relation.rb +0 -82
- data/specs/constraints/linear.rb +0 -340
- data/specs/constraints/selection.rb +0 -292
- data/specs/constraints/set_domain.rb +0 -185
- data/specs/constraints/set_operation.rb +0 -285
- data/specs/constraints/set_relation.rb +0 -197
- 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::
|
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
|
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
|
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
|
-
|
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
|
+
|