1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-19 15:25:29 +01:00

rework lambdaandP && solve_SDP

This commit is contained in:
kalmarek 2018-01-02 02:52:45 +01:00
parent 13f49027dd
commit 0d17e4b877
2 changed files with 34 additions and 51 deletions

View File

@ -126,60 +126,37 @@ function λandP(name::String)
return λ, P return λ, P
end 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( if warmstart && isfile(filename(name, :warm))
joinpath(name, "solver_$(string(now())).log"), ws = load(filename(name, :warm), "warmstart")
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")
else else
ws = nothing ws = nothing
end 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 if λ > 0
save(filename(name, ), "λ", λ) save(filename(name, ), "λ", λ)
save(filename(name, :P), "P", P) save(filename(name, :P), "P", P)
save(joinpath(name, "warmstart.jld"), "warmstart", warmstart) save(filename(name, :warm), "warmstart", warmstart)
else else
throw(ErrorException("Solver did not produce a valid solution: λ = ")) throw(ErrorException("Solver did not produce a valid solution: λ = "))
end end
return λ, P return λ, P
end 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) Kazhdan_from_sgap(λ,N) = sqrt(2*λ/N)
function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius) function check_property_T(name::String, S, Id, solver, upper_bound, tol, radius)

View File

@ -55,23 +55,29 @@ function create_SDP_problem(Δ::GroupRingElem, matrix_constraints; upper_bound=I
return m, λ, P return m, λ, P
end end
function solve_SDP(SDP_problem) function solve_SDP(m, varλ, varP; warmstart=nothing)
info(LOGGER, Base.repr(SDP_problem))
o = redirect_stdout(LOGGER_SOLVER.handlers["solver_log"].io) traits = JuMP.ProblemTraits(m, relaxation=false)
Base.Libc.flush_cstdio()
@logtime LOGGER solution_status = MathProgBase.optimize!(SDP_problem.internalModel) JuMP.build(m, traits=traits)
Base.Libc.flush_cstdio() if warmstart != nothing
p_sol, d_sol, s = warmstart
redirect_stdout(o) MathProgBase.SolverInterface.setwarmstart!(m.internalModel, p_sol; dual_sol = d_sol, slack=s);
if solution_status != :Optimal
warn(LOGGER, "The solver did not solve the problem successfully!")
end 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 end
function fillfrominternal!(m::JuMP.Model, traits) function fillfrominternal!(m::JuMP.Model, traits)