Class: Gecode::Bool::ShortCircuitEqualityOperand
- Inherits:
-
Object
- Object
- Gecode::Bool::ShortCircuitEqualityOperand
- Includes:
- BoolOperand
- Defined in:
- lib/gecoder/interface/constraints/bool_var_constraints.rb
Overview
An operand that short circuits boolean equality.
Direct Known Subclasses
Gecode::BoolEnum::Relation::BoolEnumConjunctionOperand, Gecode::BoolEnum::Relation::BoolEnumDisjunctionOperand
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_bool_var ⇒ Object
Methods included from BoolOperand
#&, #*, #+, #-, #^, #implies, #method_missing, #|
Methods included from Operand
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
#model ⇒ Object (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, = {}) if !@params[:negate] and [:reify].nil? and operand.respond_to? :to_bool_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_bool_var ⇒ Object
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 = Gecode::Util.({}).values_at(:strength, :kind) model.add_interaction do constrain_equal(variable, true, ) end return variable end |