Class: ORTools::LinearExpr
- Inherits:
-
Object
- Object
- ORTools::LinearExpr
show all
- Defined in:
- lib/or_tools/linear_expr.rb
Instance Method Summary
collapse
Instance Method Details
#+(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
41
42
43
|
# File 'lib/or_tools/linear_expr.rb', line 41
def -@
ProductCst.new(self, -1)
end
|
#/(cst) ⇒ Object
37
38
39
|
# File 'lib/or_tools/linear_expr.rb', line 37
def /(cst)
ProductCst.new(self, 1.0 / other)
end
|
#<=(arg) ⇒ Object
61
62
63
64
65
66
67
|
# File 'lib/or_tools/linear_expr.rb', line 61
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
45
46
47
48
49
50
51
|
# File 'lib/or_tools/linear_expr.rb', line 45
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
53
54
55
56
57
58
59
|
# File 'lib/or_tools/linear_expr.rb', line 53
def >=(arg)
if arg.is_a?(Numeric)
LinearConstraint.new(self, arg, Float::INFINITY)
else
LinearConstraint.new(self - arg, 0.0, Float::INFINITY)
end
end
|
#coeffs ⇒ Object
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
next if current_expression.instance_of?(LinearExpr)
current_expression.add_self_to_coeff_map_or_stack(coeffs, current_multiplier, stack)
end
coeffs
end
|
#coerce(other) ⇒ Object
77
78
79
80
81
82
83
|
# File 'lib/or_tools/linear_expr.rb', line 77
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
|
#inspect ⇒ Object
73
74
75
|
# File 'lib/or_tools/linear_expr.rb', line 73
def inspect
"#<#{self.class.name} #{to_s}>"
end
|
#solution_value ⇒ Object
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_s ⇒ Object
69
70
71
|
# File 'lib/or_tools/linear_expr.rb', line 69
def to_s
"(empty)"
end
|