Skip to content

Commit 27a4696

Browse files
committed
More docs
1 parent f0ce71f commit 27a4696

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

docs/src/submodules/Nonlinear/overview.md

+22
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,28 @@ julia> MOI.set(model, MOI.NLPBlock(), block);
362362
Only call [`NLPBlockData`](@ref) once you have finished modifying the
363363
problem in `model`.
364364

365+
Putting everything together, you can create a nonlinear optimization problem in
366+
MathOptInterface as follows:
367+
```@example
368+
import MathOptInterface
369+
const MOI = MathOptInterface
370+
371+
function build_model(model; backend)
372+
x = MOI.add_variable(model)
373+
y = MOI.add_variable(model)
374+
MOI.set(model, MOI.ObjectiveSense(), MOI.MIN_SENSE)
375+
data = MOI.Nonlinear.NonlinearData()
376+
MOI.Nonlinear.set_objective(data, :($x^2 + $y^2))
377+
MOI.Nonlinear.set_differentiation_backend(data, backend, [x, y])
378+
MOI.set(model, MOI.NLPBlock(), MOI.NLPBlockData(data))
379+
return
380+
end
381+
382+
# Replace `model` and `backend` with your optimizer and backend of choice.
383+
model = MOI.Utilities.UniversalFallback(MOI.Utilities.Model{Float64}())
384+
build_model(model; backend = MOI.Nonlinear.ExprGraphOnly())
385+
```
386+
365387
## Expression-graph representation
366388

367389
[`Nonlinear.Model`](@ref) stores nonlinear expressions in

0 commit comments

Comments
 (0)