Where is K
from? The condition number is quite large:
julia> LinearAlgebra.cond(K)
5.806497173635263e6
The likely issue is that your K
matrix has a bunch of very small (but non-zero) elements like 2.530735066695972e-12
.
I got it to solve with Clarabel.jl and by using || f ||_2 instead of ||f||^2
julia> using JuMP, Clarabel, DelimitedFiles
julia> function main(K_filename, g_filename, α = 1)
K = DelimitedFiles.readdlm(K_filename, ',')
g = vec(DelimitedFiles.readdlm(g_filename))
model = Model(Clarabel.Optimizer)
@variable(model, f[1:size(K, 2)] >= 0)
@variable(model, t[1:2])
@constraint(model, [t[1]; g - K * f] in SecondOrderCone())
@constraint(model, [t[2]; f] in SecondOrderCone())
@objective(model, Min, t[1] + α * t[2])
optimize!(model)
@assert is_solved_and_feasible(model)
return value.(f)
end
main (generic function with 3 methods)
julia> f = main("K.dat", "g.dat");
-------------------------------------------------------------
Clarabel.jl v0.7.1 - Clever Acronym
(c) Paul Goulart
University of Oxford, 2022
-------------------------------------------------------------
problem:
variables = 4098
constraints = 8419
nnz(P) = 0
nnz(A) = 929794
cones (total) = 3
: Nonnegative = 1, numel = 4096
: SecondOrder = 2, numel = (4097,226)
settings:
linear algebra: direct / qdldl, precision: Float64
max iter = 200, time limit = Inf, max step = 0.990
tol_feas = 1.0e-08, tol_gap_abs = 1.0e-08, tol_gap_rel = 1.0e-08,
static reg : on, ϵ1 = 1.0e-08, ϵ2 = 4.9e-32
dynamic reg: on, ϵ = 1.0e-13, δ = 2.0e-07
iter refine: on, reltol = 1.0e-13, abstol = 1.0e-12,
max iter = 10, stop ratio = 5.0
equilibrate: on, min_scale = 1.0e-05, max_scale = 1.0e+05
max iter = 10
iter pcost dcost gap pres dres k/t μ step
---------------------------------------------------------------------------------------------
0 0.0000e+00 -0.0000e+00 0.00e+00 9.34e-01 7.06e-03 1.00e+00 3.61e+05 ------
1 1.0070e+05 2.0599e+05 1.05e+00 8.38e-01 1.70e-03 1.05e+05 3.03e+05 4.32e-01
2 1.9181e+05 2.2772e+05 1.87e-01 7.39e-01 1.17e-03 3.59e+04 3.00e+05 6.55e-02
3 1.0162e+05 1.3146e+05 2.94e-01 7.30e-01 1.46e-03 2.98e+04 2.96e+05 7.11e-02
4 5.3457e+04 6.4570e+04 2.08e-01 5.89e-01 1.08e-03 1.11e+04 2.46e+05 2.74e-01
5 5.4281e+04 6.7608e+04 2.46e-01 6.08e-01 1.23e-03 1.33e+04 2.39e+05 9.16e-02
6 2.9245e+04 3.5426e+04 2.11e-01 4.88e-01 1.03e-03 6.18e+03 1.91e+05 3.24e-01
7 1.4755e+04 1.6753e+04 1.35e-01 3.00e-01 6.18e-04 2.00e+03 1.12e+05 5.45e-01
8 1.3096e+04 1.4807e+04 1.31e-01 2.65e-01 5.34e-04 1.71e+03 9.18e+04 3.47e-01
9 6.5932e+03 7.2587e+03 1.01e-01 1.57e-01 3.91e-04 6.66e+02 5.95e+04 4.53e-01
10 4.1205e+03 4.2171e+03 2.34e-02 5.19e-02 1.54e-04 9.65e+01 2.74e+04 6.84e-01
11 3.9859e+03 4.0721e+03 2.16e-02 4.65e-02 1.43e-04 8.62e+01 2.50e+04 2.51e-01
12 3.6129e+03 3.6233e+03 2.88e-03 1.51e-02 5.13e-05 1.04e+01 1.44e+04 6.24e-01
13 3.5228e+03 3.5283e+03 1.58e-03 7.64e-03 2.67e-05 5.56e+00 7.97e+03 5.59e-01
14 3.5025e+03 3.5049e+03 6.95e-04 4.61e-03 1.61e-05 2.43e+00 5.22e+03 6.07e-01
15 3.5121e+03 3.5135e+03 3.80e-04 2.38e-03 8.32e-06 1.33e+00 2.65e+03 6.16e-01
16 3.5788e+03 3.5803e+03 4.10e-04 2.15e-03 7.39e-06 1.47e+00 1.46e+03 6.39e-01
17 3.6455e+03 3.6467e+03 3.22e-04 1.72e-03 5.84e-06 1.17e+00 1.00e+03 4.10e-01
18 3.7313e+03 3.7324e+03 2.81e-04 1.38e-03 4.65e-06 1.05e+00 6.23e+02 4.66e-01
19 3.8366e+03 3.8375e+03 2.46e-04 1.12e-03 3.73e-06 9.43e-01 3.95e+02 4.52e-01
20 3.9598e+03 3.9606e+03 2.11e-04 9.08e-04 2.99e-06 8.34e-01 2.53e+02 4.62e-01
21 4.1338e+03 4.1346e+03 1.91e-04 7.20e-04 2.34e-06 7.90e-01 1.43e+02 5.57e-01
22 4.5426e+03 4.5434e+03 1.74e-04 4.54e-04 1.43e-06 7.88e-01 5.34e+01 7.13e-01
23 4.7120e+03 4.7125e+03 9.11e-05 3.23e-04 1.02e-06 4.29e-01 4.02e+01 5.15e-01
24 5.0253e+03 5.0257e+03 7.27e-05 2.18e-04 6.80e-07 3.65e-01 2.03e+01 5.79e-01
25 5.1793e+03 5.1797e+03 8.31e-05 1.98e-04 6.12e-07 4.31e-01 1.31e+01 4.95e-01
26 5.5708e+03 5.5714e+03 9.43e-05 1.50e-04 4.50e-07 5.25e-01 5.86e+00 6.36e-01
27 6.1250e+03 6.1253e+03 5.93e-05 7.72e-05 2.26e-07 3.63e-01 2.22e+00 8.70e-01
28 6.3219e+03 6.3223e+03 5.55e-05 6.35e-05 1.85e-07 3.51e-01 1.51e+00 5.40e-01
29 6.7292e+03 6.7294e+03 1.95e-05 2.11e-05 6.12e-08 1.32e-01 5.52e-01 9.74e-01
30 6.8932e+03 6.8933e+03 1.39e-05 1.45e-05 4.17e-08 9.60e-02 3.28e-01 6.41e-01
31 7.0217e+03 7.0218e+03 4.64e-06 4.55e-06 1.30e-08 3.26e-02 1.06e-01 8.70e-01
32 7.0633e+03 7.0633e+03 2.15e-06 2.05e-06 5.86e-09 1.52e-02 4.93e-02 9.80e-01
33 7.0787e+03 7.0787e+03 1.00e-06 9.37e-07 2.67e-09 7.08e-03 2.24e-02 7.28e-01
34 7.0879e+03 7.0879e+03 4.44e-07 4.09e-07 1.17e-09 3.14e-03 9.76e-03 8.75e-01
35 7.0915e+03 7.0915e+03 1.23e-07 1.13e-07 3.23e-10 8.75e-04 2.70e-03 8.90e-01
36 7.0927e+03 7.0927e+03 3.39e-08 3.11e-08 8.87e-11 2.40e-04 7.42e-04 8.50e-01
37 7.0930e+03 7.0930e+03 7.87e-09 7.23e-09 2.06e-11 5.58e-05 1.72e-04 8.25e-01
---------------------------------------------------------------------------------------------
Terminated with status = solved
solve time = 8.88s
The Ipopt code would be:
function main(K_filename, g_filename, α = 1)
K = DelimitedFiles.readdlm(K_filename, ',')
g = vec(DelimitedFiles.readdlm(g_filename))
model = Model(Ipopt.Optimizer)
@variable(model, f[1:size(K, 2)] >= 0)
@variable(model, y[1:size(K, 1)])
@constraint(model, y .== g .- K * f)
@objective(model, Min, sum(y.^2) + α * sum(f.^2))
optimize!(model)
@assert is_solved_and_feasible(model)
return value.(f)
end
but the numerics are not nice.