Class: Gecode::Int::ShortCircuitEqualityOperand
- Inherits:
-
Object
- Object
- Gecode::Int::ShortCircuitEqualityOperand
- Includes:
- IntOperand
- Defined in:
- lib/gecoder/interface/constraints/int_var_constraints.rb
Overview
An operand that short circuits integer equality.
Direct Known Subclasses
FixnumEnum::Element::ElementIntOperand, Arithmetic::IntAbsOperand, Arithmetic::IntMultOperand, Arithmetic::IntSquareRootOperand, Arithmetic::IntSquaredOperand, Gecode::IntEnum::Arithmetic::IntEnumMaxOperand, Gecode::IntEnum::Arithmetic::IntEnumMinOperand, Gecode::IntEnum::Element::ElementIntOperand, Set::Cardinality::SetSizeOperand
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #construct_receiver(params) ⇒ Object
-
#initialize(model) ⇒ ShortCircuitEqualityOperand
constructor
A new instance of ShortCircuitEqualityOperand.
- #to_int_var ⇒ Object
Methods included from IntOperand
#*, #+, #-, #abs, #method_missing, #pre_arith_mult, #square_root, #squared
Methods included from Operand
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
#model ⇒ Object (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, = {}) if !@params[:negate] and [:reify].nil? and operand.respond_to? :to_int_var # Short circuit the constraint. @params.update Gecode::Util.() @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, ) end end alias_comparison_methods end return receiver end |
#to_int_var ⇒ Object
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 = Gecode::Util.({}).values_at(:strength, :kind) model.add_interaction do constrain_equal(variable, true, ) end return variable end |