Closed innuo closed 2 years ago
The syntax >=
is a bit confusing. It's maybe best that you don't use SOSModel
but Model
instead to distable this syntax.
What you are doing is the following
model = Model(solver)
@polyvar x
@variable(model, 0 <= γ <= 1)
@objective(model, Min, γ)
S = @set x >= 0 && x <= 1
@constraint(model, x*x - 0.2 in SOSCone(), domain = S)
@constraint(model, y - x in SOSCone(), domain = S)
This searches for a value of y such that y - x
is SOS over S
and x^2 - 0.2
is SOS over S
.
Note that at x = 0
which is in S
, x^2 - 0.2 = -0.2
is negative so x^2 - 0.2
cannot be SOS over S
hence this is infeasible.
What you can do is as follows:
model = Model(solver)
@polyvar x y
@variable(model, lb)
@objective(model, Max, lb)
S = @set x >= 0 && x <= 1 && x^2 >= 0.2 && x <= y && y >= 0 && y <= 1
@constraint(model, y - lb in SOSCone(), domain = S, maxdegree = d)
This will give you lower bounds to the optimization problem you want to solve. The lower bound will get better as you increase d
. For large enough d
, you will get the minimizer, see https://jump.dev/SumOfSquares.jl/stable/generated/Polynomial%20Optimization/polynomial_optimization/
@blegat Thanks for your response. Indeed the <= syntax was the cause for my confusion. I had assumed that the optimization is conducted over the intersection of the constraint and the domain. Your way of specifying the constraint as a polynomial in an SOSCone makes the infeasibility clear.
As a follow-up question, is there a way to create the domain sequentially? In other words, can the domain object be passed around between different julia functions to iteratively append constraints to it? Is there an example to which you could point me?
Yes, you can do as follows:
julia> using SemialgebraicSets
julia> using DynamicPolynomials
julia> @polyvar x y
(x, y)
julia> S = @set x >= 0 && x <= 1
Basic semialgebraic Set defined by no equality
2 inequalities
x ≥ 0
-x + 1 ≥ 0
julia> S = S ∩ @set(x^2 >= 0.2)
Basic semialgebraic Set defined by no equality
3 inequalities
x ≥ 0
-x + 1.0 ≥ 0
x^2 - 0.2 ≥ 0
julia> S = S ∩ @set(x <= y && y >= 0 && y <= 1)
Basic semialgebraic Set defined by no equality
6 inequalities
x ≥ 0
-x + 1.0 ≥ 0
x^2 - 0.2 ≥ 0
-x + y ≥ 0
y ≥ 0
-y + 1.0 ≥ 0
Closing because this seems resolved, and there doesn't seem to be anything actionable here.
I have been having trouble getting my SOS polynomial program to solve. I have reproduced the issue in the the following simple optimization problem which fails with a primal infeasibility.
It is very likely that I am doing something wrong. I would greatly appreciate it if someone could set me straight.
The problem that the following function implements is
Which produces: