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
SIGN_TO_STRING =
{
  LESS_OR_EQ => "<=",
  GREATER_OR_EQ => ">=",
  EQUALS => "="
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(terms, type, bound) ⇒ Constraint

Returns a new instance of Constraint.



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

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.



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

def bound
  @bound
end

#function_nameObject

Returns the value of attribute function_name.



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

def function_name
  @function_name
end

#termsObject

Returns the value of attribute terms.



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

def terms
  @terms
end

#typeObject

Returns the value of attribute type.



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

def type
  @type
end

Instance Method Details

#to_function_sObject



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

def to_function_s
  "#{function_name || 'constraint'}(#{vars.map!(&:name).join(', ')})"
end

#to_sObject



30
31
32
33
# File 'lib/ruby-cbc/ilp/constraint.rb', line 30

def to_s
  sign = SIGN_TO_STRING[@type] || "??"
  "#{@terms} #{sign} #{@bound}"
end

#varsObject



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

def vars
  terms.vars
end