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 canonical
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 wire 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 wire name.
Methods included from Operators
#!=, #*, #**, #+, #+@, #-, #-@, #/, #<=, #==, #>=, #coerce
Constructor Details
#initialize(model, name, domain, lower, upper, start, index) ⇒ Variable
Returns a new instance of Variable.
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/quicopt/model.rb', line 186 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.
176 177 178 |
# File 'lib/quicopt/model.rb', line 176 def domain @domain end |
#index ⇒ Integer (readonly)
Returns the variable's position in its model.
184 185 186 |
# File 'lib/quicopt/model.rb', line 184 def index @index end |
#lower ⇒ Float (readonly)
Returns the lower bound (may be -Float::INFINITY).
178 179 180 |
# File 'lib/quicopt/model.rb', line 178 def lower @lower end |
#model ⇒ Model (readonly)
Returns the model that declared this variable.
172 173 174 |
# File 'lib/quicopt/model.rb', line 172 def model @model end |
#name ⇒ String (readonly)
Returns the wire name; solutions come back keyed by it.
174 175 176 |
# File 'lib/quicopt/model.rb', line 174 def name @name end |
#start ⇒ Float (readonly)
Returns the starting point handed to the solver.
182 183 184 |
# File 'lib/quicopt/model.rb', line 182 def start @start end |
#upper ⇒ Float (readonly)
Returns the upper bound (may be Float::INFINITY).
180 181 182 |
# File 'lib/quicopt/model.rb', line 180 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.
204 205 206 |
# File 'lib/quicopt/model.rb', line 204 def eql?(other) equal?(other) end |
#hash ⇒ Object
Hashes by identity, to match eql?.
209 210 211 |
# File 'lib/quicopt/model.rb', line 209 def hash object_id.hash end |
#inspect ⇒ String
Returns name, domain and bounds.
219 220 221 |
# File 'lib/quicopt/model.rb', line 219 def inspect "#<Quicopt::Variable #{@name} #{@domain} [#{@lower}, #{@upper}]>" end |
#to_expr ⇒ Expression
Returns this variable as a degree-1 expression.
198 199 200 |
# File 'lib/quicopt/model.rb', line 198 def to_expr Expression.new(linear: { self => 1.0 }) end |
#to_s ⇒ String
Returns the variable's wire name.
214 215 216 |
# File 'lib/quicopt/model.rb', line 214 def to_s @name end |