Class: Gecode::Int::ShortCircuitRelationsOperand

Inherits:
Object
  • Object
show all
Includes:
IntOperand
Defined in:
lib/gecoder/interface/constraints/int_var_constraints.rb

Overview

An operand that short circuits integer relation constraints.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from IntOperand

#*, #+, #-, #abs, #method_missing, #pre_arith_mult, #square_root, #squared

Methods included from Operand

#must, #must_not

Constructor Details

#initialize(model) ⇒ ShortCircuitRelationsOperand

Returns a new instance of ShortCircuitRelationsOperand.



126
127
128
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 126

def initialize(model)
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Int::IntOperand

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



124
125
126
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 124

def model
  @model
end

Instance Method Details

#construct_receiver(params) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# File 'lib/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) ⇒ Object

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.

Raises:

  • (NotImplementedError)


168
169
170
# File 'lib/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_varObject



157
158
159
160
161
162
163
# File 'lib/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