Class: Expressions
Overview
An LP Expression. A mathematical expression. Can be a constraint or can be the objective function of a LP or MIP problem.
Instance Attribute Summary collapse
-
#expressions ⇒ Object
Returns the value of attribute expressions.
Class Method Summary collapse
Instance Method Summary collapse
- #+(other) ⇒ Object
- #-(other) ⇒ Object
- #-@ ⇒ Object
- #evaluate ⇒ Object
-
#initialize(expressions) ⇒ Expressions
constructor
A new instance of Expressions.
- #to_s ⇒ Object
- #variables ⇒ Object
Constructor Details
#initialize(expressions) ⇒ Expressions
Returns a new instance of Expressions.
7 8 9 |
# File 'lib/rulp/expression.rb', line 7 def initialize(expressions) @expressions = expressions end |
Instance Attribute Details
#expressions ⇒ Object
Returns the value of attribute expressions.
6 7 8 |
# File 'lib/rulp/expression.rb', line 6 def expressions @expressions end |
Class Method Details
.[](value) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/rulp/expression.rb', line 43 def self.[](value) case value when LV then Expressions.new([Fragment.new(value, 1)]) when Fragment then Expressions.new([value]) when Expressions then value end end |
Instance Method Details
#+(other) ⇒ Object
39 40 41 |
# File 'lib/rulp/expression.rb', line 39 def +(other) Expressions.new(self.expressions + Expressions[other].expressions) end |
#-(other) ⇒ Object
34 35 36 37 |
# File 'lib/rulp/expression.rb', line 34 def -(other) other = -other self + other end |
#-@ ⇒ Object
29 30 31 32 |
# File 'lib/rulp/expression.rb', line 29 def -@ -self.expressions[0] self end |
#evaluate ⇒ Object
51 52 53 |
# File 'lib/rulp/expression.rb', line 51 def evaluate self.expressions.map(&:evaluate).inject(:+) end |
#to_s ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/rulp/expression.rb', line 11 def to_s as_str = @expressions[0].to_s[3..-1] (@expressions.length - 1).times do |i| as_str << @expressions[i + 1].to_s end as_str end |
#variables ⇒ Object
19 20 21 |
# File 'lib/rulp/expression.rb', line 19 def variables @expressions.map(&:variable) end |