Hey there,
I’m new to JuMP but I need to solve an optimization problem which I am not being able to run.
Let’s say I have a circumference with a given radius of 5 and such a circumference is built from the a and b components. Let’s say that the a component has a positive cost of 1, while b has a negative cost of -2 when a given binary variable x is true and 0 when this x variable is false. I would like to find the a and b components which would maximize my revenue, so I would describe my problem as:
Max: -2 * b * x + a
Subject to: c^2 - (a^2 + b^2) = 0
c - 5 = 0
If I leave my x variable fixed to 1, I’m able to run the code:
using JuMP, Juniper, Ipopt, GLPK
optimizer = Juniper.Optimizer
params = Dict{Symbol, Any}()
params[:nl_solver] = with_optimizer(Ipopt.Optimizer, print_level=0)
params[:mip_solver] = with_optimizer(GLPK.Optimizer)
m = Model(with_optimizer(optimizer, params))
@variable(m, a)
@variable(m, b)
@variable(m, c == 5)
@variable(m, x == 1, Bin)
@NLconstraint(m, c^2 == a^2 + b^2)
@objective(m, Max, a - 2 * b * x)
optimize!(m)
I get the values a = 2.2360679774997894, b = -4.47213595499958 and obj = 11.180339887498949.
But now let’s say I want x to be true when a is smaller than 3:
using JuMP, Juniper, Ipopt, GLPK
optimizer = Juniper.Optimizer
params = Dict{Symbol, Any}()
params[:nl_solver] = with_optimizer(Ipopt.Optimizer, print_level=0)
params[:mip_solver] = with_optimizer(GLPK.Optimizer)
m = Model(with_optimizer(optimizer, params))
@variable(m, a)
@variable(m, b)
@variable(m, c == 5)
@variable(m, x, Bin)
@NLconstraint(m, c^2 == a^2 + b^2)
@NLconstraint(m, x == ifelse(a >= 3, 0, 1))
@objective(m, Max, a - 2 * b * x)
optimize!(m)
Now I got an AssertionError:
ERROR: AssertionError: length(hess_I) > 0
Stacktrace:
[1] JuMP._FunctionStorage(::Array{JuMP._Derivatives.NodeData,1}, ::Array{Float64,1}, ::Int64, ::JuMP._Derivatives.Coloring.IndexedSet, ::Bool, ::Array{JuMP._Subexpress
ionStorage,1}, ::Array{Int64,1}, ::Array{JuMP._Derivatives.Linearity,1}, ::Array{Set{Tuple{Int64,Int64}},1}, ::Array{Array{Int64,1},1}, ::Dict{MathOptInterface.Variable
Index,Int64}) at /home/daniel/.julia/packages/JuMP/MsUSY/src/nlp.jl:283
[2] initialize(::NLPEvaluator, ::Array{Symbol,1}) at /home/daniel/.julia/packages/JuMP/MsUSY/src/nlp.jl:407
[3] optimize!(::Ipopt.Optimizer) at /home/daniel/.julia/packages/Ipopt/ruIXY/src/MOI_wrapper.jl:795
[4] optimize!(::MathOptInterface.Bridges.LazyBridgeOptimizer{Ipopt.Optimizer}) at /home/daniel/.julia/packages/MathOptInterface/A2UPd/src/Bridges/bridge_optimizer.jl:2
25
[5] optimize!(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities.
Model{Float64}}}) at /home/daniel/.julia/packages/MathOptInterface/A2UPd/src/Utilities/cachingoptimizer.jl:189
[6] #optimize!#78(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(optimize!), ::Model, ::OptimizerFactory) at /home/da
niel/.julia/packages/JuMP/MsUSY/src/optimizer_interface.jl:141
[7] optimize! at /home/daniel/.julia/packages/JuMP/MsUSY/src/optimizer_interface.jl:111 [inlined]
[8] #optimize_get_status_backend#7(::OptimizerFactory, ::typeof(Juniper.optimize_get_status_backend), ::Model) at /home/daniel/.julia/packages/Juniper/i4qvA/src/util.j
l:280
[9] #optimize_get_status_backend at ./Base.jl:0 [inlined]
[10] solve_root_model!(::Juniper.JuniperProblem) at /home/daniel/.julia/packages/Juniper/i4qvA/src/model.jl:63
[11] optimize!(::Juniper.Optimizer) at /home/daniel/.julia/packages/Juniper/i4qvA/src/MOI_wrapper/MOI_wrapper.jl:331
[12] optimize!(::MathOptInterface.Bridges.LazyBridgeOptimizer{Juniper.Optimizer}) at /home/daniel/.julia/packages/MathOptInterface/A2UPd/src/Bridges/bridge_optimizer.j
l:225
[13] optimize!(::MathOptInterface.Utilities.CachingOptimizer{MathOptInterface.AbstractOptimizer,MathOptInterface.Utilities.UniversalFallback{MathOptInterface.Utilities
.Model{Float64}}}) at /home/daniel/.julia/packages/MathOptInterface/A2UPd/src/Utilities/cachingoptimizer.jl:189
[14] #optimize!#78(::Bool, ::Bool, ::Base.Iterators.Pairs{Union{},Union{},Tuple{},NamedTuple{(),Tuple{}}}, ::typeof(optimize!), ::Model, ::Nothing) at /home/daniel/.ju
lia/packages/JuMP/MsUSY/src/optimizer_interface.jl:141
[15] optimize! at /home/daniel/.julia/packages/JuMP/MsUSY/src/optimizer_interface.jl:111 [inlined] (repeats 2 times)
[16] top-level scope at none:1
Am I missing something?
Many thanks!
EDIT 1: Forgot to say I’m using julia v1.3.0, GLPK v.0.12.0, Juniper v.0.5.2, Ipopt v.0.6.1 and JuMP v.0.20.1.