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

#function_nameObject

Returns the value of attribute function_name.



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

def function_name
  @function_name
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_function_sObject



21
22
23
# File 'lib/ruby-cbc/ilp/constraint.rb', line 21

def to_function_s
  "#{function_name || 'constraint'}(#{vars.join(', ')})"
end

#to_sObject



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ruby-cbc/ilp/constraint.rb', line 25

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

#varsObject



17
18
19
# File 'lib/ruby-cbc/ilp/constraint.rb', line 17

def vars
  terms.vars.uniq
end