Class: Gecode::FreeIntVar

Inherits:
Object
  • Object
show all
Includes:
Constraints::LeftHandSideMethods
Defined in:
lib/gecoder/interface/variables.rb,
lib/gecoder/interface/constraints/int/linear.rb,
lib/gecoder/interface/constraints/int/arithmetic.rb,
lib/gecoder/interface/constraints/int_var_constraints.rb

Overview

Describes an integer variable. Each integer variable has a domain of several integers which represent the possible values that the variable may take. An integer variable is said to be assigned once the domain only contains a single element, at which point #value can be used to retrieve the value.

Instance Method Summary collapse

Methods included from Constraints::LeftHandSideMethods

#must, #must_not

Instance Method Details

#*(var) ⇒ Object

Begins a multiplication constraint involving the two int variable.



13
14
15
16
17
18
19
20
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 13

def *(int)
  if int.kind_of? Fixnum
    Gecode::Constraints::Int::Linear::ExpressionNode.new(self, 
      @model) * int
  else
    pre_linear_mult(int) if respond_to? :pre_linear_mult
  end
end

#+(var) ⇒ Object

Creates a linear expression where the int variables are summed.



4
5
6
7
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 4

def +(var)
  Gecode::Constraints::Int::Linear::ExpressionNode.new(self, 
    @model) + var
end

#-(var) ⇒ Object

Creates a linear expression where the specified variable is subtracted from this one.



24
25
26
27
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 24

def -(var)
  Gecode::Constraints::Int::Linear::ExpressionNode.new(self, 
    @model) - var
end

#absObject

Initiates an arithmetic absolute value constraint.



3
4
5
6
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 3

def abs
  Gecode::Constraints::Int::Arithmetic::AbsExpressionStub.new(@model, 
    :lhs => self)
end

#pre_arith_multObject

Creates a linear expression where the int variable is multiplied with a constant integer.



22
23
24
25
26
27
28
29
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 22

def *(int)
  if int.kind_of? Fixnum
    Gecode::Constraints::Int::Linear::ExpressionNode.new(self, 
      @model) * int
  else
    pre_linear_mult(int) if respond_to? :pre_linear_mult
  end
end

#pre_linear_multObject



9
# File 'lib/gecoder/interface/constraints/int/linear.rb', line 9

alias_method :pre_linear_mult, :*

#sqrtObject Also known as: square_root

Initiates an arithmetic squared root constraint.



15
16
17
18
# File 'lib/gecoder/interface/constraints/int/arithmetic.rb', line 15

def sqrt
  Gecode::Constraints::Int::Arithmetic::SquareRootExpressionStub.new(@model, 
    :lhs => self)
end

#squaredObject

Initiates an arithmetic squared value constraint.



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

def squared
  Gecode::Constraints::Int::Arithmetic::SquaredExpressionStub.new(@model, 
    :lhs => self)
end

#valueObject

Gets the value of the assigned integer variable (a Fixnum). The variable must be assigned, if it isn’t then a RuntimeError is raised.



96
97
98
99
# File 'lib/gecoder/interface/variables.rb', line 96

def value
  raise 'No value is assigned.' unless assigned?
  send_bound(:val)
end