Class: Gecode::Bool::ShortCircuitEqualityOperand

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

Overview

An operand that short circuits boolean equality.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from BoolOperand

#&, #*, #+, #-, #^, #implies, #method_missing, #|

Methods included from Operand

#must, #must_not

Methods included from BoolLinearOperations

#*, #+, #-

Constructor Details

#initialize(model) ⇒ ShortCircuitEqualityOperand

Returns a new instance of ShortCircuitEqualityOperand.



100
101
102
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 100

def initialize(model)
  @model = model
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Bool::BoolOperand

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



98
99
100
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 98

def model
  @model
end

Instance Method Details

#construct_receiver(params) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 104

def construct_receiver(params)
  params.update(:lhs => self)
  receiver = BoolConstraintReceiver.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_bool_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_bool_varObject



131
132
133
134
135
136
137
138
139
# File 'lib/gecoder/interface/constraints/bool_var_constraints.rb', line 131

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