Finite Parameters
A technical manual for finite parameters in InfiniteOpt
. See the respective guide for more information.
Definition
InfiniteOpt.@finite_parameter
— Macro@finite_parameter(model::InfiniteModel, value, kwargs...)
Define and add an anonymous finite parameter to model
and return its parameter reference. Its value is equal to value
.
@finite_parameter(model::InfiniteModel, param_expr == value_expr, kwargs...)
Define and add a finite parameter(s) to model
and return appropriate parameter reference(s). The parameter(s) has/have value(s) indicated by the value_expr
. The expression param_expr
can be of the form:
paramname
creating a scalar parameter of nameparamname
paramname[...]
or[...]
creating a container of parameters
The expression value_expr
simply expresses the value of the parameter(s). This is typically a number but could be an array indexed using an index defined in param_expr
.
The recognized keyword arguments in kwargs
are the following:
base_name
: Sets the name prefix used to generate parameter names. It corresponds to the parameter name for scalar parameter, otherwise, the parameter names are set tobase_name[...]
for each index...
of the axesaxes
.container
: Specify the container type, defaults toAuto
.
Examples
julia> par = @finite_parameter(model, 2)
noname
julia> vals = [3, 2];
julia> pars = @finite_parameter(model, [i = 1:2] == vals[i], base_name = "par")
2-element Array{ParameterRef,1}:
par[1]
par[2]
julia> @finite_parameter(model, par2 == 42)
par2
InfiniteOpt.FiniteParameter
— TypeFiniteParameter <: ScalarParameter
A DataType
for storing finite parameters meant to be nested in expressions and replaced with their values at runtime.
Fields
value::Float64
: The parameter value.
InfiniteOpt.build_parameter
— Methodbuild_parameter(_error::Function, value::Real)::FiniteParameter
Returns a FiniteParameter
given the appropriate information. This is analagous to JuMP.build_variable
. This is meant to primarily serve as a helper method for @finite_parameter
.
Example
julia> build_parameter(error, 1)
FiniteParameter(1.0)
InfiniteOpt.add_parameter
— Methodadd_parameter(model::InfiniteModel, p::FiniteParameter,
[name::String = ""])::GeneralVariableRef
Returns a GeneralVariableRef
associated with the parameter p
that is added to model
. This adds a parameter to the model in a manner similar to JuMP.add_variable
. This is to add parameters with the use of @finite_parameter
. build_parameter
should be used to construct p
.
Example
julia> p = build_parameter(error, 42);
julia> param_ref = add_parameter(model, p, "name")
name
InfiniteOpt.FiniteParameterIndex
— TypeFiniteParameterIndex <: ObjectIndex
A DataType
for storing the index of a FiniteParameter
.
Fields
value::Int64
: The index value.
InfiniteOpt.FiniteParameterRef
— TypeFiniteParameterRef <: FiniteRef
A DataType
for finite parameters references who are replaced with their values at the transcription step.
Fields
model::InfiniteModel
: Infinite model.index::FiniteParameterIndex
: Index of the parameter in model.
Methods
Many methods are shared with independent infinite parameters since both finite and independent infinite parameters are scalar. See the infinite parameter technical manual for the remainder of the methods available for finite parameters (i.e., any method typed for ScalarParameterRef
s)
InfiniteOpt.parameter_value
— Methodparameter_value(pref::FiniteParameterRef)::Float64
Return the value of a finite parameter reference pref
. Errors if it is an infinite parameter.
Example
julia> value(cost)
42.0
JuMP.set_value
— MethodJuMP.set_value(pref::FiniteParameterRef, value::Real)::Nothing
Set the value of pref
so long as it is a finite parameter. Errors if it is an infinite parameter.
Example
julia> set_value(cost, 27)
julia> value(cost)
27.0
InfiniteOpt.used_by_objective
— Methodused_by_objective(pref::FiniteParameterRef)::Bool
Return true if pref
is used by the objective function.
Example
InfiniteOpt.core_object
— Methodcore_object(pref::FiniteParameterRef)::FiniteParameter
Retrieve the underlying core [FiniteParameter
] object for pref
. This is intended as an advanced method for developers.