Module: ORTools::ExpressionMethods

Included in:
Expression, Variable
Defined in:
lib/or_tools/expression.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#partsObject (readonly)

Returns the value of attribute parts.



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

def parts
  @parts
end

Instance Method Details

#!=(other) ⇒ Object



41
42
43
# File 'lib/or_tools/expression.rb', line 41

def !=(other)
  Comparison.new(self, :!=, other)
end

#*(other) ⇒ Object



17
18
19
# File 'lib/or_tools/expression.rb', line 17

def *(other)
  Expression.new([Product.new(self, Expression.to_expression(other))])
end

#+(other) ⇒ Object



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

def +(other)
  Expression.new((parts || [self]) + [Expression.to_expression(other)])
end

#-(other) ⇒ Object



9
10
11
# File 'lib/or_tools/expression.rb', line 9

def -(other)
  Expression.new((parts || [self]) + [-Expression.to_expression(other)])
end

#-@Object



13
14
15
# File 'lib/or_tools/expression.rb', line 13

def -@
  -1 * self
end

#<(other) ⇒ Object



25
26
27
# File 'lib/or_tools/expression.rb', line 25

def <(other)
  Comparison.new(self, :<, other)
end

#<=(other) ⇒ Object



33
34
35
# File 'lib/or_tools/expression.rb', line 33

def <=(other)
  Comparison.new(self, :<=, other)
end

#==(other) ⇒ Object



37
38
39
# File 'lib/or_tools/expression.rb', line 37

def ==(other)
  Comparison.new(self, :==, other)
end

#>(other) ⇒ Object



21
22
23
# File 'lib/or_tools/expression.rb', line 21

def >(other)
  Comparison.new(self, :>, other)
end

#>=(other) ⇒ Object



29
30
31
# File 'lib/or_tools/expression.rb', line 29

def >=(other)
  Comparison.new(self, :>=, other)
end

#coerce(other) ⇒ Object

keep order



54
55
56
57
58
59
60
# File 'lib/or_tools/expression.rb', line 54

def coerce(other)
  if other.is_a?(Numeric)
    [Constant.new(other), self]
  else
    raise TypeError, "#{self.class} can't be coerced into #{other.class}"
  end
end

#inspectObject



45
46
47
# File 'lib/or_tools/expression.rb', line 45

def inspect
  @parts.reject { |v| v.is_a?(Constant) && v.value == 0 }.map(&:inspect).join(" + ").gsub(" + -", " - ")
end

#to_sObject



49
50
51
# File 'lib/or_tools/expression.rb', line 49

def to_s
  inspect
end

#varsObject



62
63
64
# File 'lib/or_tools/expression.rb', line 62

def vars
  @vars ||= @parts.flat_map(&:vars)
end