Module: Gecode::Int::IntOperand

Includes:
Operand
Included in:
ShortCircuitEqualityOperand, ShortCircuitRelationsOperand, Gecode::IntVar
Defined in:
lib/gecoder/interface/constraints/int_var_constraints.rb,
lib/gecoder/interface/constraints/int/linear.rb,
lib/gecoder/interface/constraints/int/arithmetic.rb

Overview

A IntOperand is a combination of variables on which the constraints defined in IntConstraintReceiver can be placed.

Integer operands can be created either by using Gecode::Mixin#int_var et al, or by using properties that produce integer operands. The operands, no matter how they were created, all respond to the properties defined by IntOperand.

Examples

Produces a single integer operand (more specifically an IntVar) with domain 0..9 inside a problem formulation, using Gecode::Mixin#int_var:

int_operand = int_var(0..9)

Uses the IntOperand#+ property to produce a new integer operand representing int_operand1 plus int_operand2:

new_int_operand = int_operand1 + int_operand2

Uses the IntEnumOperand#max property to produce a new integer operand representing the maximum value of the integer operands in the enumeration int_enum:

new_int_operand = int_enum.max

Uses the IntEnumOperand#[] property to produce a new integer operand representing the integer operand at the index decided by int_operand (which can change during search) in the enumeration int_enum:

new_int_operand = int_enum[int_operand]

Uses the SetOperand#size property to produce a new integer operand representing the size of set_operand:

new_int_operand = set_operand.size

– Classes that mix in IntOperand must define #model and #to_int_var .

Instance Method Summary collapse

Methods included from Operand

#model, #must, #must_not

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

:nodoc:



48
49
50
51
52
53
54
55
# File 'lib/gecoder/interface/constraints/int_var_constraints.rb', line 48

def method_missing(method, *args) #:nodoc:
  if Gecode::IntVar.instance_methods.include? method.to_s
    # Delegate to the int var.
    to_int_var.method(method).call(*args)
  else
    super
  end
end

Instance Method Details

#*(int_operand) ⇒ Object

Produces a new IntOperand representing this operand times int_operand.

Examples

# The value of +int_op1+ times +int_op2+.
int_op1 * int_op2


38
39
40
41
42
43
44
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 38

def *(fixnum)
  if fixnum.kind_of? Fixnum
    int_linear_expression_operation(:*, fixnum)
  else
    raise TypeError, "Expected fixnum, got #{fixnum.class}."
  end
end

#+(int_operand_or_fixnum) ⇒ Object

Produces a new IntOperand representing this operand plus int_operand_or_fixnum.

Examples

# +int1+ plus +int2+
int1 + int2

# +int+ plus 17
int + 17


13
14
15
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 13

def +(int_operand_or_fixnum)
  int_linear_expression_operation(:+, int_operand_or_fixnum)
end

#-(int_operand_or_fixnum) ⇒ Object

Produces a new IntOperand representing this operand minus int_operand_or_fixnum.

Examples

# +int1+ minus +int2+
int1 - int2

# +int+ minus 17
int - 17


27
28
29
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 27

def -(int_operand_or_fixnum)
  int_linear_expression_operation(:-, int_operand_or_fixnum)
end

#absObject

Produces an IntOperand representing the absolute value of this operand.

Examples

# The absolute value of +int_op+.
int_op.abs


10
11
12
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 10

def abs
  Arithmetic::IntAbsOperand.new(@model, self)
end

#pre_arith_multObject

Produces a new IntOperand representing this operand times a constant.

Examples

# +int+ times 17
int * 17


37
38
39
40
41
42
43
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 37

def *(fixnum)
  if fixnum.kind_of? Fixnum
    int_linear_expression_operation(:*, fixnum)
  else
    raise TypeError, "Expected fixnum, got #{fixnum.class}."
  end
end

#square_rootObject Also known as: sqrt

Produces an IntOperand representing the square root of this operand rounded down.

Examples

# The square root of +int_op+, rounded down.
int_op.square_root


31
32
33
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 31

def square_root
  Arithmetic::IntSquareRootOperand.new(@model, self)
end

#squaredObject

Produces an IntOperand representing this operand squared.

Examples

# The value of +int_op*int_op+.
int_op.squared


20
21
22
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 20

def squared
  Arithmetic::IntSquaredOperand.new(@model, self)
end