lib/gecoder/interface/constraints/int_enum/count.rb in gecoder-0.7.0 vs lib/gecoder/interface/constraints/int_enum/count.rb in gecoder-0.7.1
- old
+ new
@@ -14,13 +14,13 @@
end
end
end
# A module that gathers the classes and modules used in count constraints.
-module Gecode::Constraints::IntEnum::Count
+module Gecode::Constraints::IntEnum::Count #:nodoc:
# Describes an expression
- class Expression < Gecode::Constraints::IntEnum::Expression
+ class Expression < Gecode::Constraints::IntEnum::Expression #:nodoc:
def initialize(model, params)
super
unless params[:negate]
@method_relations = Gecode::Constraints::Util::RELATION_TYPES
else
@@ -45,10 +45,27 @@
end_code
end
alias_comparison_methods
end
- # Describes a count constraint.
+ # Describes a count constraint, which constrains the number of times a value
+ # (constant or a variable) may occurr in an enumeration of integer variable.
+ #
+ # All relations available for +SimpleRelationConstraint+ can be used with
+ # count constraints. Negation and reification is supported.
+ #
+ # == Examples
+ #
+ # # Constrain +int_enum+ to not contain 0 exactly once.
+ # int_enum.count(0).must_not == 1
+ #
+ # # Constrain +int_enum+ to contain +x+ exactly +x_count+ times.
+ # int_enum.count(x).must == x_count
+ #
+ # # Reifies the constraint that +int_enum+ has +x+ zeros with the boolean
+ # # variable +has_x_zeros+ and selects the strength +domain+.
+ # int_enum.count(0).must.equal(x, :reify => has_x_zeros,
+ # :strength => :domain)
class CountConstraint < Gecode::Constraints::ReifiableConstraint
def post
lhs, element, relation_type, rhs, strength, reif_var =
@params.values_at(:lhs, :element, :relation_type, :rhs, :strength,
:reif)
\ No newline at end of file