Skip to content

Commit d019f5f

Browse files
committed
More documentation
1 parent 928ce50 commit d019f5f

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

docs/src/manual/constraints.md

+26
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,8 @@ con : 2 x ∈ [-4.0, -2.0]
614614

615615
## Modify a variable coefficient
616616

617+
### Scalar constraints
618+
617619
To modify the coefficients for a linear term (modifying the coefficient of a
618620
quadratic term is not supported) in a constraint, use
619621
[`set_normalized_coefficient`](@ref). To query the current coefficient, use
@@ -635,6 +637,30 @@ julia> normalized_coefficient(con, x[2])
635637
[`set_normalized_coefficient`](@ref) sets the coefficient of the normalized
636638
constraint. See [Normalization](@ref) for more details.
637639

640+
### Vector constraints
641+
642+
To modify the coefficients of a vector-valued constraint, use
643+
[`set_normalized_coefficients`](@ref).
644+
```jldoctest
645+
julia> model = Model();
646+
647+
julia> @variable(model, x)
648+
x
649+
650+
julia> @constraint(model, con, [2x + 3x, 4x] in MOI.Nonnegatives(2))
651+
con : [5 x, 4 x] ∈ MathOptInterface.Nonnegatives(2)
652+
653+
julia> set_normalized_coefficients(con, x, [(1, 3.0)])
654+
655+
julia> con
656+
con : [3 x, 4 x] ∈ MathOptInterface.Nonnegatives(2)
657+
658+
julia> set_normalized_coefficients(con, x, [(1, 2.0), (2, 5.0)])
659+
660+
julia> con
661+
con : [2 x, 5 x] ∈ MathOptInterface.Nonnegatives(2)
662+
```
663+
638664
## Delete a constraint
639665

640666
Use [`delete`](@ref) to delete a constraint from a model. Use [`is_valid`](@ref)

src/constraints.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,8 @@ end
690690
)
691691
692692
Set the coefficients of `variable` in the constraint `con_ref` to
693-
`new_coefficients`.
693+
`new_coefficients`, where each element in `new_coefficients` is a tuple which
694+
maps the row to a new coefficient.
694695
695696
Note that prior to this step, during constraint creation, JuMP will aggregate
696697
multiple terms containing the same variable.

test/constraint.jl

-2
Original file line numberDiff line numberDiff line change
@@ -835,8 +835,6 @@ function test_Model_change_coefficient(::Any, ::Any)
835835
end
836836

837837
function test_Model_change_coefficients(::Any, ::Any)
838-
model = JuMP.Model()
839-
x = @variable(model)
840838
model = Model()
841839
@variable(model, x)
842840
@constraint(model, con, [2x + 3x, 4x] in MOI.Nonnegatives(2))

0 commit comments

Comments
 (0)