Skip to content
Merged
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
32 changes: 23 additions & 9 deletions src/sets.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2702,7 +2702,11 @@ eval_jacobian(ret::AbstractVector, x::AbstractVector)::Nothing
which fills the sparse Jacobian ``\\nabla f(x)`` into `ret`.

The one-indexed sparsity structure must be provided in the `jacobian_structure`
argument.
argument and it must be independent of the point ``x``.

`jacobian_structure` is not required to be sorted and it may contain duplicates,
in which case the solver will combine the corresponding non-zero values in `ret`
by adding them together.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you meant "averaging them together" ?

"Adding them together" feels like giving [(1,1), (1,1), (1,1)] and [1.0, 1.0, 1.0] would fill the Hessian with a 3.0 instead of a 1.0 at the index 1,1.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I mean adding them together. It would fill in 3.0 at the index 1, 1.


## Hessian

Expand All @@ -2723,15 +2727,23 @@ which fills the sparse Hessian of the Lagrangian ``\\sum \\mu_i \\nabla^2 f_i(x)
into `ret`.

The one-indexed sparsity structure must be provided in the
`hessian_lagrangian_structure` argument.
`hessian_lagrangian_structure` argument and it must be independent of the point
``x``.

`hessian_lagrangian_structure` is not required to be sorted and it may contain
duplicates, in which case the solver will combine the corresponding non-zero
values in `ret` by adding them together.

Any mix of lower and upper-triangular indices is valid. Elements `(i, j)` and
`(j, i)`, if both present, are treated as duplicates.

## Example

To model the set:
```math
\\begin{align}
0 \\le & x^2 \\le 1
0 \\le & y^2 + z^3 - w \\le 0
0 \\le & x^2 \\le 1
0 \\le & y^2 + x \\cdot z^3 - w \\le 0
\\end{align}
```
do
Expand All @@ -2744,22 +2756,24 @@ julia> set = MOI.VectorNonlinearOracle(;
u = [1.0, 0.0],
eval_f = (ret, x) -> begin
ret[1] = x[2]^2
ret[2] = x[3]^2 + x[4]^3 - x[1]
ret[2] = x[3]^2 + x[2] * x[4]^3 - x[1]
return
end,
jacobian_structure = [(1, 2), (2, 1), (2, 3), (2, 4)],
jacobian_structure = [(1, 2), (2, 1), (2, 2), (2, 3), (2, 4)],
eval_jacobian = (ret, x) -> begin
ret[1] = 2.0 * x[2]
ret[2] = -1.0
ret[3] = 2.0 * x[3]
ret[4] = 3.0 * x[4]^2
ret[3] = x[4]^3
ret[4] = 2.0 * x[3]
ret[5] = 3.0 * x[2] * x[4]^2
return
end,
hessian_lagrangian_structure = [(2, 2), (3, 3), (4, 4)],
hessian_lagrangian_structure = [(2, 2), (3, 3), (4, 4), (2, 4)],
eval_hessian_lagrangian = (ret, x, u) -> begin
ret[1] = 2.0 * u[1]
ret[2] = 2.0 * u[2]
ret[3] = 6.0 * x[4] * u[2]
ret[4] = 3.0 * x[4]^2 * u[2]
return
end,
);
Expand Down
Loading