Class: ORTools::ProductCst
- Inherits:
-
LinearExpr
- Object
- LinearExpr
- ORTools::ProductCst
- Defined in:
- lib/or_tools/product_cst.rb
Instance Attribute Summary collapse
-
#coef ⇒ Object
readonly
Returns the value of attribute coef.
-
#expr ⇒ Object
readonly
Returns the value of attribute expr.
Instance Method Summary collapse
- #add_self_to_coeff_map_or_stack(coeffs, multiplier, stack) ⇒ Object
- #cast_to_lin_exp(v) ⇒ Object
-
#initialize(expr, coef) ⇒ ProductCst
constructor
A new instance of ProductCst.
- #to_s ⇒ Object
Methods inherited from LinearExpr
#*, #+, #-, #-@, #/, #<=, #==, #>=, #coeffs, #inspect, #solution_value
Constructor Details
#initialize(expr, coef) ⇒ ProductCst
Returns a new instance of ProductCst.
5 6 7 8 9 10 |
# File 'lib/or_tools/product_cst.rb', line 5 def initialize(expr, coef) @expr = cast_to_lin_exp(expr) # TODO improve message raise TypeError, "expected numeric" unless coef.is_a?(Numeric) @coef = coef end |
Instance Attribute Details
#coef ⇒ Object (readonly)
Returns the value of attribute coef.
3 4 5 |
# File 'lib/or_tools/product_cst.rb', line 3 def coef @coef end |
#expr ⇒ Object (readonly)
Returns the value of attribute expr.
3 4 5 |
# File 'lib/or_tools/product_cst.rb', line 3 def expr @expr end |
Instance Method Details
#add_self_to_coeff_map_or_stack(coeffs, multiplier, stack) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/or_tools/product_cst.rb', line 20 def add_self_to_coeff_map_or_stack(coeffs, multiplier, stack) current_multiplier = multiplier * @coef if current_multiplier stack << [current_multiplier, @expr] end end |
#cast_to_lin_exp(v) ⇒ Object
27 28 29 |
# File 'lib/or_tools/product_cst.rb', line 27 def cast_to_lin_exp(v) v.is_a?(Numeric) ? Constant.new(v) : v end |
#to_s ⇒ Object
12 13 14 15 16 17 18 |
# File 'lib/or_tools/product_cst.rb', line 12 def to_s if @coef == -1 "-#{@expr}" else "(#{@coef} * #{@expr})" end end |