1
0
mirror of https://github.com/kalmarek/PropertyT.jl.git synced 2024-11-29 09:45:27 +01:00

parametrize Settings by {Symmetric, Naive}

This commit is contained in:
kalmarek 2018-09-09 13:21:33 +02:00
parent 23449ed3c0
commit 592f0bf7a5
2 changed files with 60 additions and 57 deletions

View File

@ -21,31 +21,36 @@ import MathProgBase.SolverInterface.AbstractMathProgSolver
struct Symmetrize end
struct Naive end
mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver}
struct Settings{T} where T<:Union{Symmetrize, Naive}
name::String
G::Gr
S::Vector{GEl}
G::Group
S::Vector{GroupElem}
radius::Int
solver::Sol
solver::AbstractMathProgSolver
upper_bound::Float64
tol::Float64
warmstart::Bool
autS::Group
function Settings(name, G::Gr, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws) where {Gr, GEl, Sol}
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws)
function Settings(name::String,
G::Group, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws) where
{GEl<:GroupElem, Sol<:AbstractMathProgSolver}
return new{Naive}(name, G, S, r, sol, ub, tol, ws)
end
function Settings(name, G::Gr, S::Vector{GEl}, r::Int,
function Settings(name::String,
G::Group, S::Vector{GEl}, r::Int,
sol::Sol, ub, tol, ws, autS) where {Gr, GEl, Sol}
return new{Gr, GEl, Sol}(name, G, S, r, sol, ub, tol, ws, autS)
return new{Symmetrize}(name, G, S, r, sol, ub, tol, ws, autS)
end
end
prefix(s::Settings) = s.name
prefix(s::Settings{Naive}) = s.name
prefix(s::Settings{Symmetrize}) = "o"*s.name
suffix(s::Settings) = "$(s.upper_bound)"
prepath(s::Settings) = prefix(s)
fullpath(s::Settings) = joinpath(prefix(s), suffix(s))
@ -72,9 +77,7 @@ filename(prefix, s::Symbol) = filename(prefix, Val{s})
end
end
for T in [:Naive, :Symmetrize]
@eval begin
function check_property_T(::Type{$T}, sett::Settings)
function check_property_T(sett::Settings{$T})
if exists(filename(prepath(sett),:pm)) &&
exists(filename(prepath(sett),))
@ -100,7 +103,7 @@ for T in [:Naive, :Symmetrize]
ws = nothing
end
λ, P, ws = computeλandP($T, Δ, sett,
λ, P, ws = computeλandP(sett, Δ,
solverlog=filename(fullpath(sett), :solverlog))
saveλandP(fullpath(sett), λ, P, ws)
@ -122,8 +125,6 @@ for T in [:Naive, :Symmetrize]
return interpret_results(sett, sgap)
end
end
end
Kazhdan(λ::Number, N::Integer) = sqrt(2*λ/N)

View File

@ -62,7 +62,8 @@ end
#
###############################################################################
function computeλandP(::Type{Naive}, Δ::GroupRingElem, sett::Settings, ws=nothing; solverlog=tempname()*".log")
function computeλandP(sett::Settings{Naive},
Δ::GroupRingElem, ws=nothing; solverlog=tempname()*".log")
info("Creating SDP problem...")
SDP_problem, varλ, varP = SOS_problem(Δ^2, Δ, upper_bound=sett.upper_bound)
JuMP.setsolver(SDP_problem, sett.solver)
@ -73,7 +74,8 @@ function computeλandP(::Type{Naive}, Δ::GroupRingElem, sett::Settings, ws=noth
return λ, P, ws
end
function computeλandP(::Type{Symmetrize}, Δ::GroupRingElem, sett::Settings, ws=nothing; solverlog=tempname()*".log")
function computeλandP(sett::Settings{Symmetrize},
Δ::GroupRingElem, ws=nothing; solverlog=tempname()*".log")
pdir = prepath(sett)
files_exist = exists(filename(pdir,:Uπs)) && exists(filename(pdir,:orbits)) && exists(filename(pdir,:preps))