Class: Gecode::Int::ShortCircuitEqualityOperand

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

Overview

An operand that short circuits integer equality.

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) ⇒ ShortCircuitEqualityOperand

Returns a new instance of ShortCircuitEqualityOperand.



69
70
71
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 69

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.



67
68
69
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 67

def model
  @model
end

Instance Method Details

#construct_receiver(params) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 73

def construct_receiver(params)
  params.update(:lhs => self)
  receiver = IntConstraintReceiver.new(@model, params)
  op = self
  receiver.instance_eval{ @short_circuit = op }
  class <<receiver
    alias_method :equality_without_short_circuit, :==
    def ==(operand, options = {})
      if !@params[:negate] and options[:reify].nil? and 
          operand.respond_to? :to_int_var
        # Short circuit the constraint.
        @params.update Gecode::Util.decode_options(options)
        @model.add_constraint(Gecode::BlockConstraint.new(
            @model, @params) do
          @short_circuit.constrain_equal(operand, false,
            @params.values_at(:strength, :kind))
        end)
      else
        equality_without_short_circuit(operand, options)
      end
    end
    alias_comparison_methods
  end

  return receiver
end

#to_int_varObject



100
101
102
103
104
105
106
107
108
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 100

def to_int_var
  variable = model.int_var
  options = 
    Gecode::Util.decode_options({}).values_at(:strength, :kind)
  model.add_interaction do
    constrain_equal(variable, true, options)
  end
  return variable
end