-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Welcome to the StatusSwitchingQP.jl wiki!
StatusSwitchingQP.jl solves the following convex quadratic programming problems (called SSQP
):
with positive semi-definite symmetric matrix
Given an optimal solution DN
, UP
and IN
, respectively.
Using OE
; when it is active, it is represented by the state EO
.
Remark: make sure that J > 0 || any(isfinite.(d)) || any(isfinite.(u))
. Otherwise, there are no any inequalities or bounds, there are only equality constraints. For QP, there is a known closed-form solution, and for LP, the solution is unbounded.
using StatusSwitchingQP
c = [-3.0, -2]
d = [0.0, 0]
u = [Inf, Inf]
G = [-1.0 3; 1 -5]
g = [12.0; 5]
A = zeros(0, 2)
b = zeros(0)
Q = LP(c, A, b; d=d, u=u, G=G, g=g) #define the LP model
x, S, status = solveLP(Q) #solved by Status Switching method
display((x, S, status))
z = SimplexLP(Q) #solved by Simplex method
display(z)
outputs
([12.0, 8.0], Status[IN, IN, EO, OE], 3)
([5.0, 0.0], Status[IN, DN, OE, EO], 3)
where
x : solution, N x 1 vector
S : Vector{Status}, (N+J)x1
status : 1 unique; 0 infeasible; 2 infinitely many sol; 3 unbounded; -1 numerical errors; -maxIter, not done
using StatusSwitchingQP
V = [1/100 1/80 1/100
1/80 1/16 1/40
1/100 1/40 1/25]
E = [109 / 100; 23 / 20; 119 / 100]
up = [0.7; +Inf; 0.7] #Inf means no bounded
P = QP(V; u=up) #default q=0, Ax=b => 1'x=1, G=[], g =[], d = 0
display(P) # V A G q b g d u N M J
z, S, iter = solveQP(P)
display((z, S, iter))
P2 = QP(P, E, 0.25) #set q = -0.25*E
display(P2)
z2, S2, iter2 = solveQP(P2)
display((z2, S2, iter2))
outputs
QP{Float64}([0.01 0.0125 0.01; 0.0125 0.0625 0.025; 0.01 0.025 0.04], [1.0 1.0 1.0], Matrix{Float64}(undef, 0, 3), [0.0, 0.0, 0.0], [1.0], Float64[], [0.0, 0.0, 0.0], [0.7, Inf, 0.7], 3, 1, 0)
([0.7, 0.05238095238095242, 0.24761904761904768], Status[UP, IN, IN], 2)
QP{Float64}([0.01 0.0125 0.01; 0.0125 0.0625 0.025; 0.01 0.025 0.04], [1.0 1.0 1.0], Matrix{Float64}(undef, 0, 3), [-0.2725, -0.2875, -0.2975], [1.0], Float64[], [0.0, 0.0, 0.0], [0.7, Inf, 0.7], 3, 1, 0)
([0.22105263157895372, 0.07894736842105071, 0.7], Status[IN, IN, UP], 6)
where
status : > 0 if successful (=iter_count); = 0 if infeasibility detected; < 0 fail (=-1 if numerical error, =-maxIter if not converged)