Sha256: d5a0a9c3b9a98f83130f124f6ca248384d17fc393a088db2759bf5a4894b8e30

Contents?: true

Size: 1.71 KB

Versions: 14

Compression:

Stored size: 1.71 KB

Contents

module Gecode::Int
  class IntConstraintReceiver
    alias_method :pre_channel_equals, :==
    
    # Constrains the integer operand to be equal to the specified boolean 
    # operand. I.e. constrains the integer operand to be 1 when the boolean
    # operand is true and 0 if the boolean operand is false.
    #
    # ==== Examples 
    #
    #   # The integer operand +int+ must be one exactly when the boolean 
    #   # operand +bool+ is true.
    #   int.must == bool
    def ==(bool, options = {})
      unless @params[:lhs].respond_to? :to_int_var and 
          bool.respond_to? :to_bool_var
        return pre_channel_equals(bool, options)
      end
      
      if @params[:negate]
        raise Gecode::MissingConstraintError, 'A negated channel constraint ' +
          'is not implemented.'
      end
      unless options[:reify].nil?
        raise ArgumentError, 'Reification is not supported by the channel ' + 
          'constraint.'
      end
      
      @params.update(Gecode::Util.decode_options(options))
      @params[:rhs] = bool
      @model.add_constraint Channel::ChannelConstraint.new(@model, @params)
    end
    
    alias_comparison_methods
    
    # Provides commutativity with BoolEnumConstraintReceiver#channel .
    provide_commutativity(:channel){ |rhs, _| rhs.respond_to? :to_bool_enum }
  end
  
  # A module that gathers the classes and modules used in channel constraints
  # involving a single integer operand.
  module Channel #:nodoc:
    class ChannelConstraint < Gecode::Constraint #:nodoc:
      def post
        lhs, rhs = @params.values_at(:lhs, :rhs)
        Gecode::Raw::channel(@model.active_space, lhs.to_int_var.bind, 
          rhs.to_bool_var.bind, *propagation_options)
      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/int/channel.rb
gecoder-with-gecode-1.1.1 lib/gecoder/interface/constraints/int/channel.rb
gecoder-1.1.1 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-1.1.0 lib/gecoder/interface/constraints/int/channel.rb
gecoder-1.1.0 lib/gecoder/interface/constraints/int/channel.rb
gecoder-0.9.1 lib/gecoder/interface/constraints/int/channel.rb
gecoder-0.9.0 lib/gecoder/interface/constraints/int/channel.rb
gecoder-1.0.0 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-0.9.0-x86-mswin32-60 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-0.9.0 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-0.9.1-x86-mswin32-60 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-1.0.0-x86-mswin32-60 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-0.9.1 lib/gecoder/interface/constraints/int/channel.rb
gecoder-with-gecode-1.0.0 lib/gecoder/interface/constraints/int/channel.rb