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
45 46 47 48 49 |
# File 'lib/rulp/expression.rb', line 45 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
36 37 38 39 |
# File 'lib/rulp/expression.rb', line 36 def -(other) other = -other self + other end |
#-@ ⇒ Object
31 32 33 34 |
# File 'lib/rulp/expression.rb', line 31 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
15 16 17 18 19 |
# File 'lib/rulp/expression.rb', line 15 def to_s @expressions.map{|expression| [expression.operand < 0 ? " " : " + ", expression.to_s] }.flatten[1..-1].join("") end |
#variables ⇒ Object
21 22 23 |
# File 'lib/rulp/expression.rb', line 21 def variables @expressions.map(&:variable) end |