Class: Ilp::Constraint
- Inherits:
-
Object
- Object
- Ilp::Constraint
- 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
-
#bound ⇒ Object
Returns the value of attribute bound.
-
#function_name ⇒ Object
Returns the value of attribute function_name.
-
#terms ⇒ Object
Returns the value of attribute terms.
-
#type ⇒ Object
Returns the value of attribute type.
Instance Method Summary collapse
-
#initialize(terms, type, bound) ⇒ Constraint
constructor
A new instance of Constraint.
- #to_function_s ⇒ Object
- #to_s ⇒ Object
- #vars ⇒ Object
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
#bound ⇒ Object
Returns the value of attribute bound.
8 9 10 |
# File 'lib/ruby-cbc/ilp/constraint.rb', line 8 def bound @bound end |
#function_name ⇒ Object
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 |
#terms ⇒ Object
Returns the value of attribute terms.
8 9 10 |
# File 'lib/ruby-cbc/ilp/constraint.rb', line 8 def terms @terms end |
#type ⇒ Object
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_s ⇒ Object
21 22 23 |
# File 'lib/ruby-cbc/ilp/constraint.rb', line 21 def to_function_s "#{function_name || 'constraint'}(#{vars.join(', ')})" end |
#to_s ⇒ Object
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 |
#vars ⇒ Object
17 18 19 |
# File 'lib/ruby-cbc/ilp/constraint.rb', line 17 def vars terms.vars.uniq end |