Class: Quicopt::Variable
- Inherits:
-
Object
- Object
- Quicopt::Variable
- Includes:
- Operators
- Defined in:
- lib/quicopt/model.rb
Overview
A decision variable, owned by the Model that created it.
index is the variable's position in its model; it also fixes the order of a
quadratic term's two factors, so x * y and y * x land on the same
coefficient.
Instance Attribute Summary collapse
-
#domain ⇒ Symbol
readonly
:CONTINUOUS,:INTEGERor:BINARY. -
#index ⇒ Integer
readonly
The variable's position in its model.
-
#lower ⇒ Float
readonly
The lower bound (may be
-Float::INFINITY). -
#model ⇒ Model
readonly
The model that declared this variable.
-
#name ⇒ String
readonly
The variable's name; solutions come back keyed by it.
-
#start ⇒ Float
readonly
The starting point handed to the solver.
-
#upper ⇒ Float
readonly
The upper bound (may be
Float::INFINITY).
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
Identity equality, kept separate from
==(which builds a constraint) so variables stay usable as Hash and Set keys. -
#hash ⇒ Object
Hashes by identity, to match
eql?. -
#initialize(model, name, domain, lower, upper, start, index) ⇒ Variable
constructor
A new instance of Variable.
-
#inspect ⇒ String
Name, domain and bounds.
-
#to_expr ⇒ Expression
This variable as a degree-1 expression.
-
#to_s ⇒ String
The variable's name.
Methods included from Operators
#!=, #*, #**, #+, #+@, #-, #-@, #/, #<=, #==, #>=, #coerce
Constructor Details
#initialize(model, name, domain, lower, upper, start, index) ⇒ Variable
Returns a new instance of Variable.
189 190 191 192 193 194 195 196 197 198 |
# File 'lib/quicopt/model.rb', line 189 def initialize(model, name, domain, lower, upper, start, index) @model = model @name = name @domain = domain @lower = lower @upper = upper @start = start @index = index freeze end |
Instance Attribute Details
#domain ⇒ Symbol (readonly)
Returns :CONTINUOUS, :INTEGER or :BINARY.
179 180 181 |
# File 'lib/quicopt/model.rb', line 179 def domain @domain end |
#index ⇒ Integer (readonly)
Returns the variable's position in its model.
187 188 189 |
# File 'lib/quicopt/model.rb', line 187 def index @index end |
#lower ⇒ Float (readonly)
Returns the lower bound (may be -Float::INFINITY).
181 182 183 |
# File 'lib/quicopt/model.rb', line 181 def lower @lower end |
#model ⇒ Model (readonly)
Returns the model that declared this variable.
175 176 177 |
# File 'lib/quicopt/model.rb', line 175 def model @model end |
#name ⇒ String (readonly)
Returns the variable's name; solutions come back keyed by it.
177 178 179 |
# File 'lib/quicopt/model.rb', line 177 def name @name end |
#start ⇒ Float (readonly)
Returns the starting point handed to the solver.
185 186 187 |
# File 'lib/quicopt/model.rb', line 185 def start @start end |
#upper ⇒ Float (readonly)
Returns the upper bound (may be Float::INFINITY).
183 184 185 |
# File 'lib/quicopt/model.rb', line 183 def upper @upper end |
Instance Method Details
#eql?(other) ⇒ Boolean
Identity equality, kept separate from == (which builds a constraint) so
variables stay usable as Hash and Set keys.
207 208 209 |
# File 'lib/quicopt/model.rb', line 207 def eql?(other) equal?(other) end |
#hash ⇒ Object
Hashes by identity, to match eql?.
212 213 214 |
# File 'lib/quicopt/model.rb', line 212 def hash object_id.hash end |
#inspect ⇒ String
Returns name, domain and bounds.
222 223 224 |
# File 'lib/quicopt/model.rb', line 222 def inspect "#<Quicopt::Variable #{@name} #{@domain} [#{@lower}, #{@upper}]>" end |
#to_expr ⇒ Expression
Returns this variable as a degree-1 expression.
201 202 203 |
# File 'lib/quicopt/model.rb', line 201 def to_expr Expression.new(linear: { self => 1.0 }) end |
#to_s ⇒ String
Returns the variable's name.
217 218 219 |
# File 'lib/quicopt/model.rb', line 217 def to_s @name end |