Quadratically constrained programs
A simple quadratically constrained program based on an example from Gurobi.
using JuMP
import Ipopt
import Test
function example_qcp(; verbose = true)
model = Model(Ipopt.Optimizer)
set_silent(model)
@variable(model, x)
@variable(model, y >= 0)
@variable(model, z >= 0)
@objective(model, Max, x)
@constraint(model, x + y + z == 1)
@constraint(model, x * x + y * y - z * z <= 0)
@constraint(model, x * x - y * z <= 0)
optimize!(model)
if verbose
print(model)
println("Objective value: ", objective_value(model))
println("x = ", value(x))
println("y = ", value(y))
end
Test.@test termination_status(model) == MOI.LOCALLY_SOLVED
Test.@test primal_status(model) == MOI.FEASIBLE_POINT
Test.@test objective_value(model) ≈ 0.32699 atol = 1e-5
Test.@test value(x) ≈ 0.32699 atol = 1e-5
Test.@test value(y) ≈ 0.25707 atol = 1e-5
return
end
example_qcp()
Max x Subject to x + y + z = 1.0 x² + y² - z² ≤ 0.0 x² - z*y ≤ 0.0 y ≥ 0.0 z ≥ 0.0 Objective value: 0.3269928349138724 x = 0.3269928349138724 y = 0.2570658388068964
This page was generated using Literate.jl.