|
| 1 | +# # Nonconvex quadratically constrained quadratic programs |
| 2 | + |
| 3 | +#md # [](@__BINDER_ROOT_URL__/generated/Polynomial Optimization/nonconvex_qcqp.ipynb) |
| 4 | +#md # [](@__NBVIEWER_ROOT_URL__/generated/Polynomial Optimization/nonconvex_qcqp.ipynb) |
| 5 | +# **Adapted from**: [Hesse1973](@cite), [Floudas1999; Section 3.4](@cite), [Laurent2008; Example 6.22](@cite) and [Lasserre2009; Table 5.1](@cite) |
| 6 | + |
| 7 | +# We consider the nonconvex Quadratically Constrained Quadratic Programs (QCQP) |
| 8 | +# introduced in [H73]. |
| 9 | +# Consider now the polynomial optimization problem [Laurent2008; Example 6.22](@cite) of |
| 10 | +# maximizing the convex quadratic function |
| 11 | +# (hence nonconvex since convex programs should either maximize concave functions |
| 12 | +# or minimize convex functions) |
| 13 | +# $25(x_1 - 2)^2 + (x_2 - 2)^2 + (x_3 - 1)^2 + (x_4 - 4)^2 + (x_5 - 1)^2 + (x_6 - 4)^2$ |
| 14 | +# over the basic semialgebraic set defined by the nonconvex quadratic inequalities |
| 15 | +# $(x_3 - 3)^2 + x_4 \ge 4$, |
| 16 | +# $(x_5 - 3)^2 + x_6 \ge 4$, |
| 17 | +# and linear inequalities |
| 18 | +# $x_1 - 3x_2 \le 2$, |
| 19 | +# $-x_1 + x_2 \le 2$, |
| 20 | +# $2 \le x_1 + x_2 \le 6$, |
| 21 | +# $0 \le x_1, x_2$, |
| 22 | +# $1 \le x_3 \le 5$, |
| 23 | +# $0 \le x_4 \le 6$, |
| 24 | +# $1 \le x_5 \le 5$, |
| 25 | +# $0 \le x_6 \le 10$, |
| 26 | +# $x_2 \le 4x_1^4 - 32x_1^3 + 88x_1^2 - 96x_1 + 36$ and the box constraints |
| 27 | +# $0 \le x_1 \le 3$ and $0 \le x_2 \le 4$, |
| 28 | + |
| 29 | +using Test #src |
| 30 | +using DynamicPolynomials |
| 31 | +@polyvar x[1:6] |
| 32 | +centers = [2, 2, 1, 4, 1, 4] |
| 33 | +weights = [25, 1, 1, 1, 1, 1] |
| 34 | +p = -weights' * (x .- centers).^2 |
| 35 | +using SumOfSquares |
| 36 | +K = @set x[1] >= 0 && x[2] >= 0 && |
| 37 | + x[3] >= 1 && x[3] <= 5 && |
| 38 | + x[4] >= 0 && x[4] <= 6 && |
| 39 | + x[5] >= 1 && x[5] <= 5 && |
| 40 | + x[6] >= 0 && x[6] <= 10 && |
| 41 | + (x[3] - 3)^2 + x[4] >= 4 && |
| 42 | + (x[5] - 3)^2 + x[6] >= 4 && |
| 43 | + x[1] - 3x[2] <= 2 && |
| 44 | + -x[1] + x[2] <= 2 && |
| 45 | + x[1] + x[2] <= 6 && |
| 46 | + x[1] + x[2] >= 2 |
| 47 | + |
| 48 | +# We will now see how to find the optimal solution using Sum of Squares Programming. |
| 49 | +# We first need to pick an SDP solver, see [here](https://jump.dev/JuMP.jl/v1.12/installation/#Supported-solvers) for a list of the available choices. |
| 50 | + |
| 51 | +import Clarabel |
| 52 | +solver = Clarabel.Optimizer |
| 53 | + |
| 54 | +# A Sum-of-Squares certificate that $p \ge \alpha$ over the domain `S`, ensures that $\alpha$ is a lower bound to the polynomial optimization problem. |
| 55 | +# The following function searches for the largest lower bound and finds zero using the `d`th level of the hierarchy`. |
| 56 | + |
| 57 | +function solve(d) |
| 58 | + model = SOSModel(solver) |
| 59 | + @variable(model, α) |
| 60 | + @objective(model, Max, α) |
| 61 | + @constraint(model, c, p >= α, domain = K, maxdegree = d) |
| 62 | + optimize!(model) |
| 63 | + println(solution_summary(model)) |
| 64 | + return model |
| 65 | +end |
| 66 | + |
| 67 | +# The first level of the hierarchy cannot find any lower bound. |
| 68 | + |
| 69 | +model2 = solve(2) |
| 70 | +nothing # hide |
| 71 | +@test termination_status(model2) == MOI.INFEASIBLE #src |
| 72 | + |
| 73 | +# The second level of the hierarchy finds the lower bound of `-310`. |
| 74 | + |
| 75 | +model3 = solve(4) |
| 76 | +nothing # hide |
| 77 | +@test termination_status(model3) == MOI.OPTIMAL #src |
| 78 | +@test objective_value(model3) ≈ -310 rtol=1e-4 #src |
0 commit comments