mirror of
https://github.com/kalmarek/PropertyT.jl.git
synced 2024-12-25 10:20:30 +01:00
rework lambdaandP && solve_SDP
This commit is contained in:
parent
13f49027dd
commit
0d17e4b877
@ -126,60 +126,37 @@ function λandP(name::String)
|
||||
return λ, P
|
||||
end
|
||||
|
||||
function λandP(name::String, SDP_problem::JuMP.Model, varλ, varP, warmstart=false)
|
||||
function λandP(name::String, SDP::JuMP.Model, varλ, varP, warmstart=true)
|
||||
|
||||
handler = DefaultHandler(
|
||||
joinpath(name, "solver_$(string(now())).log"),
|
||||
DefaultFormatter("{date}| {msg}")
|
||||
)
|
||||
handler.levels.x = LOGGER_SOLVER.levels
|
||||
LOGGER_SOLVER.handlers["solver_log"] = handler
|
||||
|
||||
if warmstart && isfile(joinpath(name, "warmstart.jld"))
|
||||
ws = load(joinpath(name, "warmstart.jld"), "warmstart")
|
||||
if warmstart && isfile(filename(name, :warm))
|
||||
ws = load(filename(name, :warm), "warmstart")
|
||||
else
|
||||
ws = nothing
|
||||
end
|
||||
|
||||
λ, P, warmstart = compute_λandP(SDP_problem, varλ, varP, warmstart=ws)
|
||||
solver_log = solverlogger(name)
|
||||
|
||||
delete!(LOGGER_SOLVER.handlers, "solver_log")
|
||||
Base.Libc.flush_cstdio()
|
||||
o = redirect_stdout(solver_log.handlers["solver_log"].io)
|
||||
Base.Libc.flush_cstdio()
|
||||
|
||||
λ, P, warmstart = solve_SDP(SDP, varλ, varP, warmstart=ws)
|
||||
|
||||
Base.Libc.flush_cstdio()
|
||||
redirect_stdout(o)
|
||||
|
||||
delete!(solver_log.handlers, "solver_log")
|
||||
|
||||
if λ > 0
|
||||
save(filename(name, :λ), "λ", λ)
|
||||
save(filename(name, :P), "P", P)
|
||||
save(joinpath(name, "warmstart.jld"), "warmstart", warmstart)
|
||||
save(filename(name, :warm), "warmstart", warmstart)
|
||||
else
|
||||
throw(ErrorException("Solver did not produce a valid solution: λ = $λ"))
|
||||
end
|
||||
return λ, P
|
||||
end
|
||||
|
||||
function compute_λandP(m, varλ, varP; warmstart=nothing)
|
||||
λ = 0.0
|
||||
P = nothing
|
||||
|
||||
traits = JuMP.ProblemTraits(m, relaxation=false)
|
||||
|
||||
JuMP.build(m, traits=traits)
|
||||
if warmstart != nothing
|
||||
p_sol, d_sol, s = warmstart
|
||||
MathProgBase.SolverInterface.setwarmstart!(m.internalModel, p_sol; dual_sol = d_sol, slack=s);
|
||||
end
|
||||
solve_SDP(m)
|
||||
λ = MathProgBase.getobjval(m.internalModel)
|
||||
|
||||
warmstart = (m.internalModel.primal_sol, m.internalModel.dual_sol,
|
||||
m.internalModel.slack)
|
||||
|
||||
fillfrominternal!(m, traits)
|
||||
|
||||
P = JuMP.getvalue(varP)
|
||||
λ = JuMP.getvalue(varλ)
|
||||
|
||||
return λ, P, warmstart
|
||||
end
|
||||
|
||||
Kazhdan_from_sgap(λ,N) = sqrt(2*λ/N)
|
||||
|
||||
function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)
|
||||
|
32
src/SDPs.jl
32
src/SDPs.jl
@ -55,23 +55,29 @@ function create_SDP_problem(Δ::GroupRingElem, matrix_constraints; upper_bound=I
|
||||
return m, λ, P
|
||||
end
|
||||
|
||||
function solve_SDP(SDP_problem)
|
||||
info(LOGGER, Base.repr(SDP_problem))
|
||||
function solve_SDP(m, varλ, varP; warmstart=nothing)
|
||||
|
||||
o = redirect_stdout(LOGGER_SOLVER.handlers["solver_log"].io)
|
||||
Base.Libc.flush_cstdio()
|
||||
traits = JuMP.ProblemTraits(m, relaxation=false)
|
||||
|
||||
@logtime LOGGER solution_status = MathProgBase.optimize!(SDP_problem.internalModel)
|
||||
Base.Libc.flush_cstdio()
|
||||
|
||||
redirect_stdout(o)
|
||||
|
||||
if solution_status != :Optimal
|
||||
warn(LOGGER, "The solver did not solve the problem successfully!")
|
||||
JuMP.build(m, traits=traits)
|
||||
if warmstart != nothing
|
||||
p_sol, d_sol, s = warmstart
|
||||
MathProgBase.SolverInterface.setwarmstart!(m.internalModel, p_sol; dual_sol = d_sol, slack=s);
|
||||
end
|
||||
info(LOGGER, solution_status)
|
||||
|
||||
return 0
|
||||
MathProgBase.optimize!(m.internalModel)
|
||||
|
||||
λ = MathProgBase.getobjval(m.internalModel)
|
||||
|
||||
warmstart = (m.internalModel.primal_sol, m.internalModel.dual_sol,
|
||||
m.internalModel.slack)
|
||||
|
||||
fillfrominternal!(m, traits)
|
||||
|
||||
P = JuMP.getvalue(varP)
|
||||
λ = JuMP.getvalue(varλ)
|
||||
|
||||
return λ, P, warmstart
|
||||
end
|
||||
|
||||
function fillfrominternal!(m::JuMP.Model, traits)
|
||||
|
Loading…
Reference in New Issue
Block a user