Class: Ilp::Constraint

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby-cbc/ilp/constraint.rb

Constant Summary collapse

LESS_OR_EQ =
:less_or_eq
GREATER_OR_EQ =
:greater_or_eq
EQUALS =
:equals

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(terms, type, bound) ⇒ Constraint

Returns a new instance of Constraint.



10
11
12
13
14
15
# File 'lib/ruby-cbc/ilp/constraint.rb', line 10

def initialize(terms, type, bound)
  @terms = terms - bound
  @terms.normalize!
  @bound = -1 * @terms.send(:pop_constant)
  @type = type
end

Instance Attribute Details

#boundObject

Returns the value of attribute bound.



8
9
10
# File 'lib/ruby-cbc/ilp/constraint.rb', line 8

def bound
  @bound
end

#termsObject

Returns the value of attribute terms.



8
9
10
# File 'lib/ruby-cbc/ilp/constraint.rb', line 8

def terms
  @terms
end

#typeObject

Returns the value of attribute type.



8
9
10
# File 'lib/ruby-cbc/ilp/constraint.rb', line 8

def type
  @type
end

Instance Method Details

#to_sObject



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby-cbc/ilp/constraint.rb', line 17

def to_s
  case @type
  when LESS_OR_EQ
    sign = '<='
  when GREATER_OR_EQ
    sign = '>='
  when EQUALS
    sign = '='
  else
    sign = '??'
  end
  "#{@terms.to_s} #{sign} #{@bound}"
end