Class: Quicopt::Condition Private
- Inherits:
-
Object
- Object
- Quicopt::Condition
- Defined in:
- lib/quicopt/indicators.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
A 0/1 term: indicator(e) (1 when e ≠ 0), step(e) (1 when e ≥ 0) or
the near test step(tol − |e|). One factor of an Expression.
Instance Attribute Summary collapse
-
#argument ⇒ Expression
readonly
private
The expression tested.
- #model ⇒ Model readonly private
-
#op ⇒ Symbol
readonly
private
:indicator,:stepor:near. -
#order ⇒ Array
readonly
private
Where this term sorts among a model's terms.
-
#tol ⇒ Float
readonly
private
The tolerance of
:near, 0 otherwise.
Instance Method Summary collapse
-
#initialize(model, op, argument, tol, order) ⇒ Condition
constructor
private
A new instance of Condition.
-
#to_s ⇒ String
private
The term as sent, e.g.
-
#variables ⇒ Array<Variable>
private
The variables the tested expression mentions.
Constructor Details
#initialize(model, op, argument, tol, order) ⇒ Condition
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Condition.
161 162 163 164 165 166 167 168 |
# File 'lib/quicopt/indicators.rb', line 161 def initialize(model, op, argument, tol, order) @model = model @op = op @argument = argument @tol = tol @order = order freeze end |
Instance Attribute Details
#argument ⇒ Expression (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the expression tested.
155 156 157 |
# File 'lib/quicopt/indicators.rb', line 155 def argument @argument end |
#model ⇒ Model (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
151 152 153 |
# File 'lib/quicopt/indicators.rb', line 151 def model @model end |
#op ⇒ Symbol (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns :indicator, :step or :near.
153 154 155 |
# File 'lib/quicopt/indicators.rb', line 153 def op @op end |
#order ⇒ Array (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns where this term sorts among a model's terms.
159 160 161 |
# File 'lib/quicopt/indicators.rb', line 159 def order @order end |
#tol ⇒ Float (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the tolerance of :near, 0 otherwise.
157 158 159 |
# File 'lib/quicopt/indicators.rb', line 157 def tol @tol end |
Instance Method Details
#to_s ⇒ String
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the term as sent, e.g. step(x + y - 1); the
indicator of a bare variable reads x.active.
177 178 179 180 181 182 183 184 185 |
# File 'lib/quicopt/indicators.rb', line 177 def to_s = @argument.constant.zero? && @argument.quadratic.empty? && @argument.linear.size == 1 && @argument.linear.first[0].is_a?(Variable) && @argument.linear.first[1] == 1.0 case @op when :indicator then ? "#{@argument}.active" : "indicator(#{@argument})" when :step then "step(#{@argument})" when :near then "step(#{Format.number(@tol)} - |#{@argument}|)" end end |
#variables ⇒ Array<Variable>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns the variables the tested expression mentions.
171 172 173 |
# File 'lib/quicopt/indicators.rb', line 171 def variables @argument.variables end |