Class: ORTools::Product

Inherits:
Expression show all
Defined in:
lib/or_tools/product.rb

Instance Attribute Summary collapse

Attributes included from ExpressionMethods

#parts

Instance Method Summary collapse

Methods inherited from Expression

to_expression

Methods included from ExpressionMethods

#!=, #*, #+, #-, #-@, #<, #<=, #==, #>, #>=, #coerce, #to_s

Constructor Details

#initialize(left, right) ⇒ Product

Returns a new instance of Product.



5
6
7
8
# File 'lib/or_tools/product.rb', line 5

def initialize(left, right)
  @left = left
  @right = right
end

Instance Attribute Details

#leftObject (readonly)

Returns the value of attribute left.



3
4
5
# File 'lib/or_tools/product.rb', line 3

def left
  @left
end

#rightObject (readonly)

Returns the value of attribute right.



3
4
5
# File 'lib/or_tools/product.rb', line 3

def right
  @right
end

Instance Method Details

#inspectObject



10
11
12
13
14
15
16
# File 'lib/or_tools/product.rb', line 10

def inspect
  if @left.is_a?(Constant) && @right.is_a?(Variable) && left.value == -1
     "-#{inspect_part(@right)}"
  else
    "#{inspect_part(@left)} * #{inspect_part(@right)}"
  end
end

#varsObject



18
19
20
# File 'lib/or_tools/product.rb', line 18

def vars
  @vars ||= (@left.vars + @right.vars).uniq
end