Class: Gecode::Int::Arithmetic::IntMultOperand

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, op1, op2) ⇒ IntMultOperand

Returns a new instance of IntMultOperand.



78
79
80
81
82
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 78

def initialize(model, op1, op2)
  super model
  @op1 = op1
  @op2 = op2
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



84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 84

def constrain_equal(int_operand, constrain, propagation_options)
  int_op1, int_op2 = @op1.to_int_var, @op2.to_int_var
  if constrain
    a_min = int_op1.min; a_max = int_op1.max
    b_min = int_op2.min; b_max = int_op2.max
    products = [a_min*b_min, a_min*b_max, a_max*b_min, a_max*b_max]
    int_operand.must_be.in products.min..products.max
  end

  Gecode::Raw::mult(@model.active_space, int_op1.to_int_var.bind, 
    int_op2.to_int_var.bind, int_operand.to_int_var.bind, 
    *propagation_options)
end