Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update variables.md explanation of parameters #3916

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading