From 7c45f4072f8d19f91612869548ab592e44e16b62 Mon Sep 17 00:00:00 2001 From: Art Kuo <2893800+artkuo@users.noreply.github.com> Date: Sun, 19 Jan 2025 12:16:46 -0700 Subject: [PATCH] [docs] clarify explanation of Parameter set (#3916) --- docs/src/manual/variables.md | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/docs/src/manual/variables.md b/docs/src/manual/variables.md index 0753668e0cd..c35efe378fe 100644 --- a/docs/src/manual/variables.md +++ b/docs/src/manual/variables.md @@ -1318,40 +1318,35 @@ requires `MOI.add_constrained_variables`. Some solvers have explicit support for parameters, which are constants in the model that can be efficiently updated between solves. -JuMP implements parameters by a decision variable constrained on creation to the -[`Parameter`](@ref) set. +JuMP implements parameters by a decision variable constrained on creation to a +value of the [`Parameter`](@ref) set. For example, the following creates two +parameters, `p[1]` and `p[2]`, with parameter values `2.0` and `4.0`: ```jldoctest nonlinear_parameters julia> model = Model(); julia> @variable(model, x); -julia> @variable(model, p[i = 1:2] in Parameter(i)) +julia> @variable(model, p[i in 1:2] in Parameter(2.0 * i)) 2-element Vector{VariableRef}: p[1] p[2] ``` -Create anonymous parameters using the `set` keyword: -```jldoctest nonlinear_parameters -julia> anon_parameter = @variable(model, set = Parameter(1.0)) -_[4] -``` - Use [`parameter_value`](@ref) and [`set_parameter_value`](@ref) to query or update the value of a parameter. ```jldoctest nonlinear_parameters julia> parameter_value.(p) 2-element Vector{Float64}: - 1.0 2.0 + 4.0 julia> set_parameter_value(p[2], 3.0) julia> parameter_value.(p) 2-element Vector{Float64}: - 1.0 + 2.0 3.0 ``` @@ -1369,6 +1364,12 @@ julia> ParameterRef(p[2]) p[2] ∈ MathOptInterface.Parameter{Float64}(3.0) ``` +Create anonymous parameters using the `set` keyword: +```jldoctest nonlinear_parameters +julia> anon_parameter = @variable(model, set = Parameter(1.0)) +_[4] +``` + ### Limitations Parameters are implemented as decision variables belonging to the [`Parameter`](@ref)