From 19e52909ac44c32e8be9ae5db5a7dc973f9e90b5 Mon Sep 17 00:00:00 2001 From: kalmarek Date: Wed, 5 Sep 2018 08:58:46 +0200 Subject: [PATCH] move Laplacians to separate file --- src/Laplacians.jl | 58 +++++++++++++++++++++++++++++++++++++++++++++++ src/PropertyT.jl | 30 ++---------------------- 2 files changed, 60 insertions(+), 28 deletions(-) create mode 100644 src/Laplacians.jl diff --git a/src/Laplacians.jl b/src/Laplacians.jl new file mode 100644 index 0000000..ab037ac --- /dev/null +++ b/src/Laplacians.jl @@ -0,0 +1,58 @@ +############################################################################### +# +# Laplacians +# +############################################################################### + +function spLaplacian(RG::GroupRing, S, T::Type=Float64) + result = RG(T) + result[RG.group()] = T(length(S)) + for s in S + result[s] -= one(T) + end + return result +end + +function spLaplacian(RG::GroupRing{R}, S, T::Type=Float64) where {R<:Ring} + result = RG(T) + result[one(RG.group)] = T(length(S)) + for s in S + result[s] -= one(T) + end + return result +end + +function computeLaplacian(S::Vector{E}, radius) where E<:AbstractAlgebra.RingElem + R = parent(first(S)) + return computeLaplacian(S, one(R), radius) +end + +function computeLaplacian(S::Vector{E}, radius) where E<:AbstractAlgebra.GroupElem + G = parent(first(S)) + return computeLaplacian(S, G(), radius) +end + +function computeLaplacian(S, Id, radius) + info("Generating metric ball of radius $radius...") + @time E_R, sizes = Groups.generate_balls(S, Id, radius=2radius) + info("Generated balls of sizes $sizes.") + + info("Creating product matrix...") + @time pm = GroupRings.create_pm(E_R, GroupRings.reverse_dict(E_R), sizes[radius]; twisted=true) + + RG = GroupRing(parent(Id), E_R, pm) + Δ = spLaplacian(RG, S) + return Δ +end + +function loadLaplacian(name::String, G::Group) + if exists(filename(name, :Δ)) && exists(filename(name, :pm)) + info("Loading precomputed Δ...") + RG = GroupRing(G, load(filename(name, :pm), "pm")) + Δ = GroupRingElem(load(filename(name, :Δ), "Δ")[:, 1], RG) + else + throw("You need to precompute $(filename(name, :pm)) and $(filename(name, :Δ)) to load it!") + end + return Δ +end + diff --git a/src/PropertyT.jl b/src/PropertyT.jl index eec314f..e40f074 100644 --- a/src/PropertyT.jl +++ b/src/PropertyT.jl @@ -12,54 +12,26 @@ using JuMP import MathProgBase.SolverInterface.AbstractMathProgSolver -function loadLaplacian(name::String, G::Group) - if exists(filename(name, :Δ)) && exists(filename(name, :pm)) - info("Loading precomputed Δ...") - RG = GroupRing(G, load(filename(name, :pm), "pm")) - Δ = GroupRingElem(load(filename(name, :Δ), "Δ")[:, 1], RG) - else - throw("You need to precompute $(filename(name, :pm)) and $(filename(name, :Δ)) to load it!") - end - return Δ -end ############################################################################### # # Settings and filenames # ############################################################################### -function computeLaplacian(S::Vector{E}, radius) where E<:AbstractAlgebra.RingElem - R = parent(first(S)) - return computeLaplacian(S, one(R), radius) -end -function computeLaplacian(S::Vector{E}, radius) where E<:AbstractAlgebra.GroupElem - G = parent(first(S)) - return computeLaplacian(S, G(), radius) -end mutable struct Settings{Gr<:Group, GEl<:GroupElem, Sol<:AbstractMathProgSolver} name::String G::Gr S::Vector{GEl} radius::Int -function computeLaplacian(S, Id, radius) - info("Generating metric ball of radius $radius...") - @time E_R, sizes = Groups.generate_balls(S, Id, radius=2radius) - info("Generated balls of sizes $sizes.") solver::Sol upper_bound::Float64 tol::Float64 warmstart::Bool - info("Creating product matrix...") - @time pm = GroupRings.create_pm(E_R, GroupRings.reverse_dict(E_R), sizes[radius]; twisted=true) autS::Group - RG = GroupRing(parent(Id), E_R, pm) - Δ = spLaplacian(RG, S) - return Δ -end function loadλandP(name::String) λ_fname = filename(name, :λ) @@ -187,6 +159,8 @@ function interpret_results(name::String, Δ::GroupRingElem, radius::Integer, len return false end + +include("Laplacians.jl") include("SDPs.jl") include("CheckSolution.jl") include("Orbit-wise.jl")