Sha256: db9bd93bb13ced0103b054d92dbe0d5b532aa8d6dea4e46536af2ded336a67bb

Contents?: true

Size: 1.29 KB

Versions: 3

Compression:

Stored size: 1.29 KB

Contents

module Gecode::Constraints::IntEnum
  class Expression
    # Posts an equality constraint on the variables in the enum.
    def equal(options = {})
      if @params[:negate]
        # The best we could implement it as from here would be a bunch of 
        # reified pairwise inequality constraints.
        raise Gecode::MissingConstraintError, 'A negated equality is not ' + 
          'implemented.'
      end
    
      @model.add_constraint Equality::EqualityConstraint.new(@model, 
        @params.update(Gecode::Constraints::Util.decode_options(options)))
    end
  end
  
  # A module that gathers the classes and modules used in equality constraints.
  module Equality #:nodoc:
    # Describes an equality constraint, which constrains all variables in an
    # integer enumeration to be equal. Neither negation nor reification is 
    # supported.
    # 
    # == Example
    # 
    #   # Constrains all variables in +int_enum+ to be equal.
    #   int_enum.must_be.equal
    class EqualityConstraint < Gecode::Constraints::Constraint
      def post
        # Bind lhs.
        @params[:lhs] = @params[:lhs].to_int_var_array
        
        # Fetch the parameters to Gecode.
        params = @params.values_at(:lhs, :strength)
        Gecode::Raw::eq(@model.active_space, *params)
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
gecoder-with-gecode-0.7.1-mswin32 lib/gecoder/interface/constraints/int_enum/equality.rb
gecoder-0.7.1 lib/gecoder/interface/constraints/int_enum/equality.rb
gecoder-with-gecode-0.7.1 lib/gecoder/interface/constraints/int_enum/equality.rb