Skip to content

Commit

Permalink
[docs] clarify explanation of Parameter set (#3916)
Browse files Browse the repository at this point in the history
  • Loading branch information
artkuo authored Jan 19, 2025
1 parent 99cdc4c commit 7c45f40
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions docs/src/manual/variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand All @@ -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)
Expand Down

0 comments on commit 7c45f40

Please sign in to comment.