Class: Gecode::Int::ShortCircuitRelationsOperand
- Inherits:
-
Object
- Object
- Gecode::Int::ShortCircuitRelationsOperand
- Includes:
- IntOperand
- Defined in:
- lib/gecoder/interface/constraints/int_var_constraints.rb
Overview
An operand that short circuits integer relation constraints.
Direct Known Subclasses
Bool::Linear::ExpressionTree, Linear::ExpressionTree, Gecode::IntEnum::Count::IntEnumCountOperand
Instance Attribute Summary collapse
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Instance Method Summary collapse
- #construct_receiver(params) ⇒ Object
-
#initialize(model) ⇒ ShortCircuitRelationsOperand
constructor
A new instance of ShortCircuitRelationsOperand.
-
#relation_constraint(relation, int_operand_or_fix, params) ⇒ Object
Returns a constraint that constrains this operand to have relation
relation
toint_operand_or_fix
, which is either an integer operand or a fixnum, given the specified hashparams
of parameters. - #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) ⇒ 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
#model ⇒ Object (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.
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 |