Class: Quicopt::Constraint
- Inherits:
-
Object
- Object
- Quicopt::Constraint
- Defined in:
- lib/quicopt/model.rb
Overview
One constraint row: a residual expression compared against zero.
expr is lhs - rhs, so the row is expr <= 0, expr >= 0 or expr == 0.
Quicopt::Wire then splits that into the body (the variable terms) and the
numeric bound (the constant, moved to the other side), which is the form
Quicopt sends.
Constant Summary collapse
- SENSES =
The comparison operator each sense renders as.
{ le: "<=", ge: ">=", eq: "==" }.freeze
Instance Attribute Summary collapse
-
#expr ⇒ Expression
readonly
The residual
lhs - rhs. -
#sense ⇒ Symbol
readonly
:le,:geor:eq.
Class Method Summary collapse
-
.build(lhs, rhs, sense) ⇒ Object
Build a row from the two sides of a comparison.
Instance Method Summary collapse
-
#body ⇒ Expression
The row body: the variable terms alone, with the constant moved to
bound. -
#bound ⇒ Float
The right-hand side after moving the constant across.
-
#initialize(expr, sense) ⇒ Constraint
constructor
A new instance of Constraint.
-
#inspect ⇒ String
The row, tagged with the class.
-
#to_s ⇒ Object
Renders the row as
body <op> bound.
Constructor Details
#initialize(expr, sense) ⇒ Constraint
Returns a new instance of Constraint.
414 415 416 417 418 419 420 |
# File 'lib/quicopt/model.rb', line 414 def initialize(expr, sense) raise ArgumentError, "unknown constraint sense #{sense.inspect}" unless SENSES.key?(sense) @expr = expr @sense = sense freeze end |
Instance Attribute Details
#expr ⇒ Expression (readonly)
Returns the residual lhs - rhs.
405 406 407 |
# File 'lib/quicopt/model.rb', line 405 def expr @expr end |
#sense ⇒ Symbol (readonly)
Returns :le, :ge or :eq.
407 408 409 |
# File 'lib/quicopt/model.rb', line 407 def sense @sense end |
Class Method Details
.build(lhs, rhs, sense) ⇒ Object
Build a row from the two sides of a comparison.
410 411 412 |
# File 'lib/quicopt/model.rb', line 410 def self.build(lhs, rhs, sense) new(Expression.cast(lhs).plus(Expression.cast(rhs).scale(-1.0)), sense) end |
Instance Method Details
#body ⇒ Expression
The row body: the variable terms alone, with the constant moved to bound.
425 426 427 |
# File 'lib/quicopt/model.rb', line 425 def body Expression.new(linear: @expr.linear, quadratic: @expr.quadratic) end |
#bound ⇒ Float
The right-hand side after moving the constant across.
432 433 434 |
# File 'lib/quicopt/model.rb', line 432 def bound -@expr.constant end |
#inspect ⇒ String
Returns the row, tagged with the class.
442 443 444 |
# File 'lib/quicopt/model.rb', line 442 def inspect "#<Quicopt::Constraint #{self}>" end |