Skip to content

Commit

Permalink
added symrcm ordering
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelsonric committed Dec 16, 2024
1 parent db66855 commit 4241127
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ MLStyle = "d8e11817-5142-5d16-987a-aa16d5891078"
Metis = "2679e427-3c69-5b7f-982b-ece356f1e94b"
PartialFunctions = "570af359-4316-4cb7-8c74-252c00c2016b"
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
SymRCM = "286e6d88-80af-4590-acc9-0001b223b9bd"
TreeWidthSolver = "7d267fc5-9ace-409f-a54c-cd2374872a55"

[compat]
Expand Down
3 changes: 2 additions & 1 deletion src/JunctionTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import Catlab.BasicGraphs
import CuthillMcKee
import LinkedLists: ListNode, LinkedList
import Metis
import SymRCM
import TreeWidthSolver

using AbstractTrees
Expand All @@ -23,7 +24,7 @@ export Order


# Elimination Algorithms
export AMDJL_AMD, CuthillMcKeeJL_RCM, MetisJL_ND, TreeWidthSolverJL_BT, MCS
export AMDJL_AMD, CuthillMcKeeJL_RCM, SymRCMJL_RCM, MetisJL_ND, TreeWidthSolverJL_BT, MCS


# Ordered Graphs
Expand Down
15 changes: 15 additions & 0 deletions src/junction_trees/elimination_algorithms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
A graph elimination algorithm. The options are
- [`CuthillMcKeeJL_RCM`](@ref)
- [`SymRCMJL_RCM`](@ref)
- [`AMDJL_AMD`](@ref)
- [`MetisJL_ND`](@ref)
- [`TreeWidthSolverJL_BT`](@ref)
Expand All @@ -19,6 +20,14 @@ The reverse Cuthill-McKee algorithm. Uses CuthillMckee.jl.
struct CuthillMcKeeJL_RCM <: EliminationAlgorithm end


"""
SymRCMJL_RCM <: EliminationAlgorithm
The reverse Cuthill-McKee algorithm. Uses SymRCM.jl.
"""
struct SymRCMJL_RCM <: EliminationAlgorithm end


"""
AMDJL_AMD <: EliminationAlgorithm
Expand Down Expand Up @@ -74,6 +83,12 @@ function Order(graph::AbstractMatrix, ealg::CuthillMcKeeJL_RCM)
end


function Order(graph::AbstractMatrix, ealg::SymRCMJL_RCM)
order = SymRCM.symrcm(graph)
Order(order)
end


# Construct an order using the approximate minimum degree algorithm. Uses AMD.jl.
function Order(graph::AbstractMatrix, ealg::AMDJL_AMD)
order = AMD.symamd(graph)
Expand Down
15 changes: 9 additions & 6 deletions test/JunctionTrees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,25 @@ add_edges!(graph,
[1, 1, 1, 1, 2, 2, 5, 5, 6, 6, 7, 7, 7, 10, 10, 10, 10, 12, 12, 12, 12, 15],
[3, 4, 5, 15, 3, 4, 9, 16, 9, 16, 8, 9, 15, 11, 13, 14, 17, 13, 14, 16, 17, 17])

order = JunctionTrees.Order(graph, CuthillMcKeeJL_RCM())
order = Order(graph, CuthillMcKeeJL_RCM())
@test length(order) == 17

order = JunctionTrees.Order(graph, AMDJL_AMD())
order = Order(graph, SymRCMJL_RCM())
@test length(order) == 17

order = JunctionTrees.Order(graph, MetisJL_ND())
order = Order(graph, AMDJL_AMD())
@test length(order) == 17

order = JunctionTrees.Order(graph, TreeWidthSolverJL_BT())
order = Order(graph, MetisJL_ND())
@test length(order) == 17

order = JunctionTrees.Order(graph, MCS())
order = Order(graph, TreeWidthSolverJL_BT())
@test length(order) == 17

order = JunctionTrees.Order(1:17)
order = Order(graph, MCS())
@test length(order) == 17

order = Order(1:17)
@test length(order) == 17

# Figure 4.3
Expand Down

0 comments on commit 4241127

Please sign in to comment.