Class: ORTools::LinearConstraint
- Inherits:
-
Object
- Object
- ORTools::LinearConstraint
- Defined in:
- lib/or_tools/linear_constraint.rb
Instance Attribute Summary collapse
-
#expr ⇒ Object
readonly
Returns the value of attribute expr.
-
#lb ⇒ Object
readonly
Returns the value of attribute lb.
-
#ub ⇒ Object
readonly
Returns the value of attribute ub.
Instance Method Summary collapse
- #extract(solver) ⇒ Object
-
#initialize(expr, lb, ub) ⇒ LinearConstraint
constructor
A new instance of LinearConstraint.
- #inspect ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(expr, lb, ub) ⇒ LinearConstraint
Returns a new instance of LinearConstraint.
5 6 7 8 9 |
# File 'lib/or_tools/linear_constraint.rb', line 5 def initialize(expr, lb, ub) @expr = expr @lb = lb @ub = ub end |
Instance Attribute Details
#expr ⇒ Object (readonly)
Returns the value of attribute expr.
3 4 5 |
# File 'lib/or_tools/linear_constraint.rb', line 3 def expr @expr end |
#lb ⇒ Object (readonly)
Returns the value of attribute lb.
3 4 5 |
# File 'lib/or_tools/linear_constraint.rb', line 3 def lb @lb end |
#ub ⇒ Object (readonly)
Returns the value of attribute ub.
3 4 5 |
# File 'lib/or_tools/linear_constraint.rb', line 3 def ub @ub end |
Instance Method Details
#extract(solver) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/or_tools/linear_constraint.rb', line 31 def extract(solver) coeffs = @expr.coeffs constant = coeffs.delete(OFFSET_KEY) || 0.0 lb = -solver.infinity ub = solver.infinity if @lb > -Float::INFINITY lb = @lb - constant end if @ub < Float::INFINITY ub = @ub - constant end constraint = solver.constraint(lb, ub) coeffs.each do |v, c| constraint.set_coefficient(v, c.to_f) end constraint end |
#inspect ⇒ Object
27 28 29 |
# File 'lib/or_tools/linear_constraint.rb', line 27 def inspect "#<#{self.class.name} #{to_s}>" end |
#to_s ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/or_tools/linear_constraint.rb', line 11 def to_s if @lb > -Float::INFINITY && @ub < Float::INFINITY if @lb == @ub "#{@expr} == #{@lb}" else "#{@lb} <= #{@expr} <= #{@ub}" end elsif @lb > -Float::INFINITY "#{@expr} >= #{@lb}" elsif @ub < Float::INFINITY "#{@expr} <= #{@ub}" else "Trivial inequality (always true)" end end |