Sha256: f6c9730aff258392119a858b9e353b5124c15ad667e75501bc335d838c8cfa0c

Contents?: true

Size: 1.79 KB

Versions: 14

Compression:

Stored size: 1.79 KB

Contents

module Gecode::Set
  class SetConstraintReceiver
    # Constrains this set to channel +bool_enum+. The set is constrained
    # to include value i exactly when the operand at index i in the
    # boolean enumeration is true.
    # 
    # Neither reification nor negation is supported. The boolean enum and set
    # can be interchanged.
    #
    # ==== Examples 
    #
    #   # Constrains the enumeration of boolean operands called +bools+ to at
    #   # least have the first and third operands set to true 
    #   set.must_be.superset_of [0, 2]
    #   set.must.channel bools
    #
    #   # An alternative way of writing the above.
    #   set.must_be.superset_of [0, 2]
    #   bools.must.channel set
    def channel(bool_enum, options = {})
      if @params[:negate]
        raise Gecode::MissingConstraintError, 'A negated channel constraint ' + 
          'is not implemented.'
      end
      if options.has_key? :reify
        raise ArgumentError, 'The channel constraint does not support the ' + 
          'reification option.'
      end
      unless bool_enum.respond_to? :to_bool_enum
        raise TypeError, 'Expected an enum of bool operands, ' + 
          "got #{bool_enum.class}."
      end
      
      @params.update(:rhs => bool_enum)
      @params.update Gecode::Set::Util.decode_options(options)
      @model.add_constraint Channel::ChannelConstraint.new(@model, @params)
    end
  end
  
  # A module that gathers the classes and modules used in channel constraints
  # involving one set operand and a boolean enum.
  module Channel #:nodoc:
    class ChannelConstraint < Gecode::Constraint #:nodoc:
      def post
        lhs, rhs = @params.values_at(:lhs, :rhs)
        Gecode::Raw::channel(@model.active_space, rhs.to_bool_enum.bind_array, 
          lhs.to_set_var.bind)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 2 rubygems

Version Path
gecoder-with-gecode-1.1.1.1 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-1.1.1 lib/gecoder/interface/constraints/set/channel.rb
gecoder-1.1.1 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-1.1.0 lib/gecoder/interface/constraints/set/channel.rb
gecoder-1.1.0 lib/gecoder/interface/constraints/set/channel.rb
gecoder-0.9.0 lib/gecoder/interface/constraints/set/channel.rb
gecoder-0.9.1 lib/gecoder/interface/constraints/set/channel.rb
gecoder-1.0.0 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-0.9.0-x86-mswin32-60 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-0.9.1-x86-mswin32-60 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-0.9.0 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-1.0.0-x86-mswin32-60 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-0.9.1 lib/gecoder/interface/constraints/set/channel.rb
gecoder-with-gecode-1.0.0 lib/gecoder/interface/constraints/set/channel.rb