Class: Quicopt::Extremum Private
- Inherits:
-
Object
- Object
- Quicopt::Extremum
- 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.
The smaller or the larger of several expressions. One factor of an
Expression.
Instance Attribute Summary collapse
-
#args ⇒ Array<Expression>
readonly
private
The arguments, in the order given.
- #model ⇒ Model readonly private
-
#op ⇒ Symbol
readonly
private
:minor:max. -
#order ⇒ Array
readonly
private
Where this term sorts among a model's terms.
Class Method Summary collapse
-
.build(op, args) ⇒ Object
private
The interned
opoverargsas an expression, or the number itself when every argument is one.
Instance Method Summary collapse
-
#initialize(model, op, args, order) ⇒ Extremum
constructor
private
A new instance of Extremum.
-
#to_s ⇒ String
private
The term as written, e.g.
-
#variables ⇒ Array<Variable>
private
The variables the arguments mention.
Constructor Details
#initialize(model, op, args, order) ⇒ Extremum
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 Extremum.
217 218 219 220 221 222 223 |
# File 'lib/quicopt/indicators.rb', line 217 def initialize(model, op, args, order) @model = model @op = op @args = args @order = order freeze end |
Instance Attribute Details
#args ⇒ Array<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 arguments, in the order given.
198 199 200 |
# File 'lib/quicopt/indicators.rb', line 198 def args @args 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.
194 195 196 |
# File 'lib/quicopt/indicators.rb', line 194 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 :min or :max.
196 197 198 |
# File 'lib/quicopt/indicators.rb', line 196 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.
200 201 202 |
# File 'lib/quicopt/indicators.rb', line 200 def order @order end |
Class Method Details
.build(op, args) ⇒ Object
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.
The interned op over args as an expression, or the number itself when
every argument is one.
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/quicopt/indicators.rb', line 204 def self.build(op, args) raise ArgumentError, "#{op} takes at least two arguments, got #{args.size}" if args.size < 2 exprs = args.map { |a| Expression.cast(a) } if exprs.all?(&:constant?) values = exprs.map(&:constant) return Expression.new(constant: op == :min ? values.min : values.max) end model = Conditions.owner(exprs.flat_map(&:factors)) key = [:extremum, op, exprs.map { |e| Conditions.argument_key(e) }] Expression.new(linear: { model.intern(key) { new(model, op, exprs.freeze, model.next_order) } => 1.0 }) 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 written, e.g. min(1, a.active + b.active).
232 233 234 |
# File 'lib/quicopt/indicators.rb', line 232 def to_s "#{@op}(#{@args.join(', ')})" 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 arguments mention.
226 227 228 |
# File 'lib/quicopt/indicators.rb', line 226 def variables @args.flat_map(&:variables).uniq end |