Skip to content

Commit 6f2027e

Browse files
committed
Add elimination algorithms mcs, rcm, and mmd.
1 parent dab3ca9 commit 6f2027e

File tree

6 files changed

+37
-1
lines changed

6 files changed

+37
-1
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ version = "0.35.6"
88
ApproxManifoldProducts = "9bbbb610-88a1-53cd-9763-118ce10c1f89"
99
BSON = "fbb218c0-5317-5bc6-957e-2ee96dd4b1f0"
1010
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
11+
CliqueTrees = "60701a23-6482-424a-84db-faee86b9b1f8"
1112
Combinatorics = "861a8166-3701-5b0c-9a16-15d98fcdc6aa"
1213
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1314
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
@@ -67,6 +68,7 @@ IncrInfrInterpolationsExt = "Interpolations"
6768
AMD = "0.5"
6869
ApproxManifoldProducts = "0.9"
6970
BSON = "0.2, 0.3"
71+
CliqueTrees = "0.4"
7072
Combinatorics = "1.0"
7173
DataStructures = "0.16, 0.17, 0.18"
7274
DelimitedFiles = "1"

src/IncrementalInference.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module IncrementalInference
22

33
# @info "Multithreaded convolutions possible, Threads.nthreads()=$(Threads.nthreads()). See `addFactor!(.;threadmodel=MultiThreaded)`."
44

5+
import CliqueTrees
6+
57
using Distributed
68
using Reexport
79

src/services/BayesNet.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,15 @@ function getEliminationOrder(
5050
# cons[findall(x -> x in constraints, permuteds)] .= 1
5151
# p = Ccolamd.ccolamd(adjMat, cons)
5252
@warn "Integration via AMD.ccolamd under development and replaces pre-Julia 1.9 direct ccall approach." maxlog=5
53+
elseif ordering == :mcs
54+
# maximum cardinality search
55+
p, _ = CliqueTrees.permutation(A'A, CliqueTrees.MCS())
56+
elseif ordering == :rcm
57+
# reverse Cuthill-Mckee
58+
p, _ = CliqueTrees.permutation(A'A, CliqueTrees.RCM())
59+
elseif ordering == :mmd
60+
# multiple minimum degree
61+
p, _ = CliqueTrees.permutation(A'A, CliqueTrees.MMD())
5362
else
5463
@error("getEliminationOrder -- cannot do the requested ordering $(ordering)")
5564
end

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ include("testStateMachine.jl")
6666
include("testBasicCSM.jl")
6767
include("testCliqueFactors.jl")
6868
include("testCcolamdOrdering.jl")
69+
include("testCliqueTreesOrderings.jl")
6970
include("testBasicGraphs.jl")
7071
include("testJointEnforcement.jl")
7172
include("testHasPriors913.jl")

test/testCcolamdOrdering.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,4 @@ vo = getEliminationOrder(fg, constraints=[:x3;:l2], ordering=:ccolamd)
2828
# end
2929

3030
##
31-
end
31+
end

test/testCliqueTreesOrderings.jl

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using AMD
2+
using IncrementalInference
3+
using Test
4+
5+
@testset "Test mcs, lexbfs, and rcm orderings" begin
6+
7+
fg = generateGraph_Kaess(graphinit=false)
8+
9+
vo = getEliminationOrder(fg, ordering=:mcs)
10+
@test length(vo) == length(Set(vo))
11+
@test length(vo) == length(ls(fg))
12+
13+
vo = getEliminationOrder(fg, ordering=:rcm)
14+
@test length(vo) == length(Set(vo))
15+
@test length(vo) == length(ls(fg))
16+
17+
vo = getEliminationOrder(fg, ordering=:mmd)
18+
@test length(vo) == length(Set(vo))
19+
@test length(vo) == length(ls(fg))
20+
21+
22+
end

0 commit comments

Comments
 (0)