Class: Amor::Constraint
- Inherits:
-
Object
- Object
- Amor::Constraint
- Defined in:
- lib/amor/constraint.rb
Instance Attribute Summary collapse
-
#index ⇒ Object
Returns the value of attribute index.
-
#lhs ⇒ Object
readonly
Returns the value of attribute lhs.
-
#relation ⇒ Object
readonly
Returns the value of attribute relation.
-
#rhs ⇒ Object
readonly
Returns the value of attribute rhs.
Instance Method Summary collapse
-
#initialize(lhs, relation, rhs) ⇒ Constraint
constructor
A new instance of Constraint.
- #lp_name ⇒ Object
- #lp_string ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(lhs, relation, rhs) ⇒ Constraint
Returns a new instance of Constraint.
6 7 8 9 10 |
# File 'lib/amor/constraint.rb', line 6 def initialize(lhs, relation, rhs) @lhs = Expression.new(lhs) @rhs = Expression.new(rhs) @relation = relation end |
Instance Attribute Details
#index ⇒ Object
Returns the value of attribute index.
4 5 6 |
# File 'lib/amor/constraint.rb', line 4 def index @index end |
#lhs ⇒ Object (readonly)
Returns the value of attribute lhs.
3 4 5 |
# File 'lib/amor/constraint.rb', line 3 def lhs @lhs end |
#relation ⇒ Object (readonly)
Returns the value of attribute relation.
3 4 5 |
# File 'lib/amor/constraint.rb', line 3 def relation @relation end |
#rhs ⇒ Object (readonly)
Returns the value of attribute rhs.
3 4 5 |
# File 'lib/amor/constraint.rb', line 3 def rhs @rhs end |
Instance Method Details
#lp_name ⇒ Object
26 27 28 |
# File 'lib/amor/constraint.rb', line 26 def lp_name "c#{index+1}" end |
#lp_string ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/amor/constraint.rb', line 12 def lp_string temp_lhs = (@lhs - @rhs).simplified relation_string = case @relation when :greater_equal ">=" when :lesser_equal "<=" else "=" end "#{lp_name}: #{temp_lhs.remove_constants.lp_string} #{relation_string} #{-temp_lhs.constant_factor}" end |
#to_s ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/amor/constraint.rb', line 30 def to_s relation_string = case @relation when :greater_equal ">=" when :lesser_equal "<=" else "==" end "#{@lhs} #{relation_string} #{@rhs}" end |