lib/gecoder/interface/constraints/set_enum/distinct.rb in gecoder-0.7.1 vs lib/gecoder/interface/constraints/set_enum/distinct.rb in gecoder-0.8.0
- old
+ new
@@ -1,26 +1,7 @@
module Gecode::Constraints::SetEnum
class Expression
- # Adds a distinct constraint on the sets in the enum. The "option" :size
- # must be specified, the sets will be constrained to that size.
- def distinct(options = {})
- unless options.has_key? :size
- raise ArgumentError, 'Option :size has to be specified.'
- end
- unless options.size == 1
- raise ArgumentError, 'Only the option :size is accepted, got ' +
- "#{options.keys.join(', ')}."
- end
- if @params[:negate]
- raise Gecode::MissingConstraintError, 'A negated distinct is not ' +
- 'implemented.'
- end
-
- @model.add_constraint Distinct::DistinctConstraint.new(
- @model, @params.update(options))
- end
-
# Adds a constraint on the sets that specifies that they must have at most
# one element in common. The "option" :size must be specified, the sets
# will be constrained to that size.
def at_most_share_one_element(options = {})
unless options.has_key? :size
@@ -40,26 +21,9 @@
end
end
# A module that gathers the classes and modules used in distinct constraints.
module Distinct #:nodoc:
- # Describes a set distinct constraint, which constrains all set variables
- # in the enumeration to be distinct and of a specified size. Providing a
- # size is not optional.
- #
- # Neither negation nor reification is supported.
- #
- # == Examples
- #
- # # All set variables in +sets+ must have cardinality 4 and be different.
- # sets.must_be.distinct(:size => 4)
- class DistinctConstraint < Gecode::Constraints::Constraint
- def post
- sets, size = @params.values_at(:lhs, :size)
- Gecode::Raw::distinct(@model.active_space, sets.to_set_var_array, size)
- end
- end
-
# Describes an at most one constraint, which constrains all pairs of set
# variables in the enumeration to at most have one element in common and be
# of a specified size. Providing a size is not optional.
#
# Neither negation nor reification is supported.
\ No newline at end of file