Class: ORTools::LinearExpr

Inherits:
Object
  • Object
show all
Defined in:
lib/or_tools/linear_expr.rb

Direct Known Subclasses

Constant, MPVariable, ProductCst, SumArray

Instance Method Summary collapse

Instance Method Details

#*(other) ⇒ Object



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

def *(other)
  ProductCst.new(self, other)
end

#+(expr) ⇒ Object



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

def +(expr)
  SumArray.new([self, expr])
end

#-(expr) ⇒ Object



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

def -(expr)
  SumArray.new([self, -expr])
end

#-@Object



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

def -@
  ProductCst.new(self, -1)
end

#/(cst) ⇒ Object



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

def /(cst)
  ProductCst.new(self, 1.0 / other)
end

#<=(arg) ⇒ Object



57
58
59
60
61
62
63
# File 'lib/or_tools/linear_expr.rb', line 57

def <=(arg)
  if arg.is_a?(Numeric)
    LinearConstraint.new(self, -Float::INFINITY, arg)
  else
    LinearConstraint.new(self - arg, -Float::INFINITY, 0.0)
  end
end

#==(arg) ⇒ Object



41
42
43
44
45
46
47
# File 'lib/or_tools/linear_expr.rb', line 41

def ==(arg)
  if arg.is_a?(Numeric)
    LinearConstraint.new(self, arg, arg)
  else
    LinearConstraint.new(self - arg, 0.0, 0.0)
  end
end

#>=(arg) ⇒ Object



49
50
51
52
53
54
55
# File 'lib/or_tools/linear_expr.rb', line 49

def >=(arg)
  if arg.is_a?(Numeric)
    LinearConstraint.new(self, arg, Float::INFINITY)
  else
    LinearConstraint.new(self - arg, 0.0, Float::INFINITY)
  end
end

#coeffsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/or_tools/linear_expr.rb', line 7

def coeffs
  coeffs = Hash.new(0.0)
  stack = [[1.0, self]]
  while stack.any?
    current_multiplier, current_expression = stack.pop

    # skip empty LinearExpr for backwards compatibility
    next if current_expression.instance_of?(LinearExpr)

    current_expression.add_self_to_coeff_map_or_stack(coeffs, current_multiplier, stack)
  end
  coeffs
end

#inspectObject



69
70
71
# File 'lib/or_tools/linear_expr.rb', line 69

def inspect
  "#<#{self.class.name} #{to_s}>"
end

#solution_valueObject



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

def solution_value
  coeffs.sum { |var, coeff| var.solution_value * coeff }
end

#to_sObject



65
66
67
# File 'lib/or_tools/linear_expr.rb', line 65

def to_s
  "(empty)"
end