Class: ORTools::SatLinearExpr
- Inherits:
-
Object
- Object
- ORTools::SatLinearExpr
- Includes:
- ComparisonOperators
- Defined in:
- lib/or_tools/sat_linear_expr.rb
Instance Attribute Summary collapse
-
#vars ⇒ Object
readonly
Returns the value of attribute vars.
Instance Method Summary collapse
- #*(other) ⇒ Object
- #+(other) ⇒ Object
- #-(other) ⇒ Object
-
#initialize(vars = []) ⇒ SatLinearExpr
constructor
A new instance of SatLinearExpr.
- #inspect ⇒ Object
Constructor Details
#initialize(vars = []) ⇒ SatLinearExpr
Returns a new instance of SatLinearExpr.
7 8 9 |
# File 'lib/or_tools/sat_linear_expr.rb', line 7 def initialize(vars = []) @vars = vars end |
Instance Attribute Details
#vars ⇒ Object (readonly)
Returns the value of attribute vars.
5 6 7 |
# File 'lib/or_tools/sat_linear_expr.rb', line 5 def vars @vars end |
Instance Method Details
#*(other) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/or_tools/sat_linear_expr.rb', line 19 def *(other) if vars.size == 1 self.class.new([[vars[0][0], vars[0][1] * other]]) else raise ArgumentError, "Multiplication not allowed here" end end |
#+(other) ⇒ Object
11 12 13 |
# File 'lib/or_tools/sat_linear_expr.rb', line 11 def +(other) add(other, 1) end |
#-(other) ⇒ Object
15 16 17 |
# File 'lib/or_tools/sat_linear_expr.rb', line 15 def -(other) add(other, -1) end |
#inspect ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/or_tools/sat_linear_expr.rb', line 27 def inspect vars.map do |v| k = v[0] k = k.respond_to?(:name) ? k.name : k.inspect if v[1] == 1 k else "#{k} * #{v[1]}" end end.join(" + ").sub(" + -", " - ") end |