Class: Gecode::Int::Arithmetic::IntAbsOperand

Inherits:
ShortCircuitEqualityOperand show all
Defined in:
lib/gecoder/interface/constraints/int/arithmetic.rb

Overview

:nodoc:

Instance Attribute Summary

Attributes inherited from ShortCircuitEqualityOperand

#model

Instance Method Summary collapse

Methods inherited from ShortCircuitEqualityOperand

#construct_receiver, #to_int_var

Methods included from IntOperand

#*, #+, #-, #abs, #method_missing, #pre_arith_mult, #square_root, #squared

Methods included from Operand

#model, #must, #must_not

Constructor Details

#initialize(model, int_op) ⇒ IntAbsOperand

:nodoc:



59
60
61
62
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 59

def initialize(model, int_op)
  super model
  @int = int_op
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Gecode::Int::IntOperand

Instance Method Details

#constrain_equal(int_operand, constrain, propagation_options) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 64

def constrain_equal(int_operand, constrain, propagation_options)
  int_op = @int.to_int_var
  if constrain
    bounds = [int_op.min.abs, int_op.max.abs]
    bounds << 0 if int_op.min < 0
    int_operand.must_be.in bounds.min..bounds.max
  end
  
  Gecode::Raw::abs(@model.active_space, int_op.to_int_var.bind, 
    int_operand.to_int_var.bind, *propagation_options)
end