Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JunctionTrees and NestedUWDs #5

Merged
merged 2 commits into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
name = "StructuredDecompositions"
uuid = "ba32925c-6e4c-4640-bed9-b00febeea19a"
authors = ["benjaminmerlinbumpus <[email protected]>"]
version = "0.1.0"
version = "0.2.0"

[deps]
AMD = "14f7f29c-3bd6-536c-9a0b-7339e30b5a3e"
AbstractTrees = "1520ce14-60c1-5f80-bbc7-55ef81b5835c"
Catlab = "134e5e36-593f-5add-ad60-77f754baafbe"
CuthillMcKee = "17f17636-5e38-52e3-a803-7ae3aaaf3da9"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Metis = "2679e427-3c69-5b7f-982b-ece356f1e94b"
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"

[compat]
Catlab = "^0.14"
MLStyle = "^0.4"
PartialFunctions = "^1.1"
julia = "^1.7"
Catlab = "0.16"
MLStyle = "0.4"
PartialFunctions = "1.1"
julia = "1.7"
8 changes: 4 additions & 4 deletions src/Decompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ adhesionSpans(d) = adhesionSpans(d, false)

function elements_graph(el::Elements)
F = FinFunctor(Dict(:V => :El, :E => :Arr), Dict(:src => :src, :tgt => :tgt), SchGraph, SchElements)
ΔF = DeltaMigration(F, Elements{Symbol}, Graph)
return ΔF(el)
ΔF = DeltaMigration(F)
return migrate(Graph, el, ΔF)
end

"""Syntactic sugar for costrucitng the category of elements of a graph.
Expand All @@ -152,8 +152,8 @@ function ∫(G::Elements) FinCat(elements_graph(G)) end
#reverse direction of the edges
function op_graph(g::Graph)::Graph
F = FinFunctor(Dict(:V => :V, :E => :E), Dict(:src => :tgt, :tgt => :src), SchGraph, SchGraph)
ΔF = DeltaMigration(F, Graph, Graph)
return ΔF(g)
ΔF = DeltaMigration(F)
return migrate(Graph, g, ΔF)
end

"""
Expand Down
2 changes: 2 additions & 0 deletions src/StructuredDecompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module StructuredDecompositions
include("Decompositions.jl")
include("FunctorUtils.jl")
include("DecidingSheaves.jl")
include("junction_trees/JunctionTrees.jl")
include("nested_uwds/NestedUWDs.jl")


end
83 changes: 83 additions & 0 deletions src/junction_trees/JunctionTrees.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
module JunctionTrees


import AMD
import CuthillMcKee
import Metis

using AbstractTrees
using Catlab.BasicGraphs
using DataStructures
using SparseArrays

# Elimination Algorithms
export EliminationAlgorithm, AMDJL_AMD, CuthillMcKeeJL_RCM, MetisJL_ND, MCS

# Supernodes
export Supernode, Node, MaximalSupernode, FundamentalSupernode

# Orders
export Order

# Elimination Trees
export EliminationTree
export getwidth, getsupernode, getsubtree, getlevel

# Junction Trees
export JunctionTree
export getseperator, getresidual


# Add an element x to a sorted set v.
# Returns true if x ∉ v.
# Returns false if x ∈ v.
function insertsorted!(v::Vector, x::Integer)
i = searchsortedfirst(v, x)

if i > length(v) || v[i] != x
insert!(v, i, x)
true
else
false
end
end


# Delete an element x from a sorted set v.
# Returns true if x ∈ v.
# Returns false if x ∉ v.
function deletesorted!(v::Vector, x::Integer)
i = searchsortedfirst(v, x)

if i <= length(v) && v[i] == x
deleteat!(v, i)
true
else
false
end
end


# Delete the elements xs from a sorted set v.
# Returns true if xs and v intersect.
# Returns false if xs and v are disjoint.
function deletesorted!(v::Vector, xs::AbstractVector)
isintersecting = true

for x in xs
isintersecting = deletesorted!(v, x) || isintersecting
end

isintersecting
end


include("elimination_algorithms.jl")
include("supernodes.jl")
include("orders.jl")
include("trees.jl")
include("elimination_trees.jl")
include("junction_trees.jl")


end
45 changes: 45 additions & 0 deletions src/junction_trees/elimination_algorithms.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
"""
EliminationAlgorithm

A graph elimination algorithm. The options are
- [`CuthillMcKeeJL_RCM`](@ref)
- [`AMDJL_AMD`](@ref)
- [`MetisJL_ND`](@ref)
- [`MCS`](@ref)
"""
abstract type EliminationAlgorithm end


"""
CuthillMcKeeJL_RCM <: EliminationAlgorithm

The reverse Cuthill-McKee algorithm. Uses CuthillMckee.jl.
"""
struct CuthillMcKeeJL_RCM <: EliminationAlgorithm end


"""
AMDJL_AMD <: EliminationAlgorithm

The approximate minimum degree algorithm. Uses AMD.jl.
"""
struct AMDJL_AMD <: EliminationAlgorithm end


"""
MetisJL_ND <: EliminationAlgorithm

The nested dissection heuristic. Uses Metis.jl.
"""
struct MetisJL_ND <: EliminationAlgorithm end


"""
MCS <: EliminationAlgorithm

The maximum cardinality search algorithm.
"""
struct MCS <: EliminationAlgorithm end


const DEFAULT_ELIMINATION_ALGORITHM = AMDJL_AMD()
Loading