To be able to edit code and run cells, you need to run the notebook yourself. Where would you like to run the notebook?

This notebook takes about 1 minute to run.

In the cloud (experimental)

Binder is a free, open source service that runs scientific notebooks in the cloud! It will take a while, usually 2-7 minutes to get a session.

On your computer

(Recommended if you want to store your changes.)

  1. Copy the notebook URL:
  2. Run Pluto

    (Also see: How to install Julia and Pluto)

  3. Paste URL in the Open box

Frontmatter

If you are publishing this notebook on the web, you can set the parameters below to provide HTML metadata. This is useful for search engines and social media.

Author 1
👀 Reading hidden code
using JuMP, Ipopt
15.7 s
setup_opt_model (generic function with 1 method)
👀 Reading hidden code
setup_opt_model() = Model(optimizer_with_attributes(Ipopt.Optimizer,
"acceptable_tol" => 1.e-8, "max_iter" => Int64(1e8),
"acceptable_constr_viol_tol" => 1.e-3, "constr_viol_tol" => 1.e-4,
"print_frequency_iter" => 50, "print_timing_statistics" => "no",
"print_level" => 0,
))
594 μs
halfsum (generic function with 1 method)
👀 Reading hidden code
function halfsum(xs::Vector{<:Real})
sum((xs .- 0.5).^2) + .001 * (sum(xs) - 50)^2
end
779 μs
halfsum_jump (generic function with 1 method)
👀 Reading hidden code
function halfsum_jump(xs...)
halfsum(collect(xs))
end
409 μs
cumsum_jump (generic function with 1 method)
👀 Reading hidden code
function cumsum_jump(xsi...)
xs = collect(xsi[1:N])
cumsum(collect(xs))
end
530 μs
200
👀 Reading hidden code
N = 200
11.4 μs
👀 Reading hidden code
begin
model_optimizer = setup_opt_model()
local m = model_optimizer
M = @variable(model_optimizer, 0.0 <= M[1:N] <= 1.0)

# Register our wrapper functions
###
register(m,
:halfsum_jump,
N,
autodiff=true
)
# Objective
###
min_objective = @NLobjective(
m, Min,
)
for i in 1:N
@NLconstraint(m,
M[i] >= i / N
)
end
7.4 s
A JuMP Model
├ solver: Ipopt
├ objective_sense: MIN_SENSE
│ └ objective_function_type: AffExpr
├ num_variables: 200
├ num_constraints: 600
│ ├ JuMP.VariableRef in MOI.GreaterThan{Float64}: 200
│ ├ JuMP.VariableRef in MOI.LessThan{Float64}: 200
│ └ Nonlinear: 200
└ Names registered in the model
  └ :M
model_optimized = let
optimize!(model_optimizer)
model_optimizer
end
👀 Reading hidden code
❔
******************************************************************************
This program contains Ipopt, a library for large-scale nonlinear optimization.
 Ipopt is released as open source code under the Eclipse Public License (EPL).
         For more information visit https://github.com/coin-or/Ipopt
******************************************************************************

9.4 s
LOCALLY_SOLVED::TerminationStatusCode = 4
termination_status(model_optimized)
👀 Reading hidden code
17.7 ms
value.(M)
👀 Reading hidden code
164 ms
begin
model_optimizer2 = setup_opt_model()
local m = model_optimizer2
M2 = @variable(m, 0.0 <= M2[1:N] <= 1.0)
# Objective
###
for i in 1:N
@NLconstraint(m,
M2[i] >= i / N
)
end
min_objective2 = @NLobjective(
m, Min,
# sum(
# (M2[i] - 0.5) ^ 2
# for i in 1:N
# )
sum(
(M2[i] - 0.5)^2
for i in 1:N) + .001 * (sum(M2[i] for i in 1:N) - 50)^2
)
min_objective2
end;
👀 Reading hidden code
75.9 ms
A JuMP Model
├ solver: Ipopt
├ objective_sense: MIN_SENSE
│ └ objective_function_type: AffExpr
├ num_variables: 200
├ num_constraints: 600
│ ├ JuMP.VariableRef in MOI.GreaterThan{Float64}: 200
│ ├ JuMP.VariableRef in MOI.LessThan{Float64}: 200
│ └ Nonlinear: 200
└ Names registered in the model
  └ :M2
model_optimized2 = let
optimize!(model_optimizer2)
model_optimizer2
end
👀 Reading hidden code
2.1 s
value.(M2)
👀 Reading hidden code
161 μs