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.



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 (readonly)

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.



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

def function_name
  @function_name
end

#termsObject (readonly)

Returns the value of attribute terms.



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

def terms
  @terms
end

#typeObject (readonly)

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



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

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

#to_sObject



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

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

#varsObject



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

def vars
  terms.vars
end