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.
The lowering in Quicopt::Wire splits that into the body f (the variable
terms) and the numeric bound (the constant, moved to the other side), which
is the shape the wire's function-in-set rows take.
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.
410 411 412 413 414 415 416 |
# File 'lib/quicopt/model.rb', line 410 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.
401 402 403 |
# File 'lib/quicopt/model.rb', line 401 def expr @expr end |
#sense ⇒ Symbol (readonly)
Returns :le, :ge or :eq.
403 404 405 |
# File 'lib/quicopt/model.rb', line 403 def sense @sense end |
Class Method Details
.build(lhs, rhs, sense) ⇒ Object
Build a row from the two sides of a comparison.
406 407 408 |
# File 'lib/quicopt/model.rb', line 406 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.
421 422 423 |
# File 'lib/quicopt/model.rb', line 421 def body Expression.new(linear: @expr.linear, quadratic: @expr.quadratic) end |
#bound ⇒ Float
The right-hand side after moving the constant across.
428 429 430 |
# File 'lib/quicopt/model.rb', line 428 def bound -@expr.constant end |
#inspect ⇒ String
Returns the row, tagged with the class.
438 439 440 |
# File 'lib/quicopt/model.rb', line 438 def inspect "#<Quicopt::Constraint #{self}>" end |