Sha256: 7baa641b15577af7eeec6a0a750c21120c01baa6d3da443e7a05cf876461a1ff

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

module Gecode::Constraints::IntEnum
  class Expression
    # Posts a channel constraint on the variables in the enum with the specified
    # other enum.
    def channel(enum, options = {})
      if @params[:negate]
        raise Gecode::MissingConstraintError, 'A negated channel constraint ' + 
          'is not implemented.'
      end
    
      @params.update(Gecode::Constraints::Util.decode_options(options))
      @params.update(:rhs => enum)
      @model.add_constraint Channel::ChannelConstraint.new(@model, @params)
    end
  end
  
  # A module that gathers the classes and modules used in channel constraints.
  module Channel
    # Describes a channel constraint.
    class ChannelConstraint < Gecode::Constraints::Constraint
      def post
        lhs, rhs, strength = @params.values_at(:lhs, :rhs, :strength)
      
        # Bind both sides.
        lhs = lhs.to_int_var_array
        rhs = rhs.to_int_var_array
        
        Gecode::Raw::channel(@model.active_space, lhs, rhs, strength)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
gecoder-0.4.0 lib/gecoder/interface/constraints/int_enum/channel.rb
gecoder-0.5.0 lib/gecoder/interface/constraints/int_enum/channel.rb