class Gecode::Int::ShortCircuitRelationsOperand

An operand that short circuits integer relation constraints.

Attributes

model[R]

Public Instance Methods

construct_receiver(params) click to toggle source
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/int_var_constraints.rb, line 130
def construct_receiver(params)
  receiver = IntConstraintReceiver.new(@model, params)
  op = self
  receiver.instance_eval{ @short_circuit = op }
  class <<receiver
    Gecode::Util::COMPARISON_ALIASES.keys.each do |comp|
      eval <<-end_code
        alias_method :alias_#{comp.to_i}_without_short_circuit, :#{comp}
        def #{comp}(operand, options = {})
          if operand.respond_to?(:to_int_var) or operand.kind_of? Fixnum
            # Short circuit the constraint.
            @params.update Gecode::Util.decode_options(options)
            @model.add_constraint(
              @short_circuit.relation_constraint(
                :#{comp}, operand, @params))
          else
            alias_#{comp.to_i}_without_short_circuit(operand, options)
          end
        end
      end_code
    end
    alias_comparison_methods
  end

  return receiver
end
relation_constraint(relation, int_operand_or_fix, params) click to toggle source

Returns a constraint that constrains this operand to have relation relation to int_operand_or_fix, which is either an integer operand or a fixnum, given the specified hash params of parameters.

# File doc/tmp/rdoc_dev/gecoder/interface/constraints/int_var_constraints.rb, line 168
def relation_constraint(relation, int_operand_or_fix, params)
  raise NotImplementedError, 'Abstract method has not been implemented.'
end
to_int_var() click to toggle source
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/int_var_constraints.rb, line 157
def to_int_var
  variable = model.int_var
  params = {}
  params.update Gecode::Util.decode_options({})
  model.add_constraint relation_constraint(:==, variable, params)
  return variable
end

Public Class Methods

new(model) click to toggle source
# File doc/tmp/rdoc_dev/gecoder/interface/constraints/int_var_constraints.rb, line 126
def initialize(model)
  @model = model
end