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
47 48 49 50 51 |
# File 'lib/rulp/expression.rb', line 47 def self.[](value) return Expressions.new([Fragment.new(value, 1)]) if value.kind_of?(LV) return Expressions.new([value]) if value.kind_of?(Fragment) return value if value.kind_of?(Expressions) end |
Instance Method Details
#+(other) ⇒ Object
11 12 13 |
# File 'lib/rulp/expression.rb', line 11 def +(other) return Expressions.new(@expressions + [other]) end |
#-(other) ⇒ Object
38 39 40 41 |
# File 'lib/rulp/expression.rb', line 38 def -(other) other = -other self + other end |
#-@ ⇒ Object
33 34 35 36 |
# File 'lib/rulp/expression.rb', line 33 def -@ -self.expressions[0] self end |
#evaluate ⇒ Object
53 54 55 |
# File 'lib/rulp/expression.rb', line 53 def evaluate self.expressions.map(&:evaluate).inject(:+) end |
#to_s ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/rulp/expression.rb', line 15 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
23 24 25 |
# File 'lib/rulp/expression.rb', line 23 def variables @expressions.map(&:variable) end |