Class: Amor::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/amor/constraint.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#indexObject

Returns the value of attribute index.



4
5
6
# File 'lib/amor/constraint.rb', line 4

def index
  @index
end

#lhsObject (readonly)

Returns the value of attribute lhs.



3
4
5
# File 'lib/amor/constraint.rb', line 3

def lhs
  @lhs
end

#relationObject (readonly)

Returns the value of attribute relation.



3
4
5
# File 'lib/amor/constraint.rb', line 3

def relation
  @relation
end

#rhsObject (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_nameObject



26
27
28
# File 'lib/amor/constraint.rb', line 26

def lp_name
  "c#{index+1}"
end

#lp_stringObject



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_sObject



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