Skip to content

Commit

Permalink
Moved things around.
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelsonric committed Nov 17, 2024
1 parent a485644 commit 8ab8137
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 21 deletions.
4 changes: 2 additions & 2 deletions src/Decompositions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -236,12 +236,12 @@ function Decompositions.StrDecomp(sgraph::AbstractSymmetricGraph, stree::Superno
for i in 1:n
snd = supernode(stree, i)
sep = seperator[i]
objects[i] = induced_subgraph(sgraph, order(stree.ograph, [snd; sep]))
objects[i] = induced_subgraph(sgraph, order(stree.graph, [snd; sep]))
end

for i in 1:n - 1
sep = seperator[i]
objects[n + i] = induced_subgraph(sgraph, order(stree.ograph, sep))
objects[n + i] = induced_subgraph(sgraph, order(stree.graph, sep))
end

for i in 1:n - 1
Expand Down
16 changes: 8 additions & 8 deletions src/junction_trees/elimination_trees.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Nodes i in T correspond to vertices σ(i) in G.
struct EliminationTree{T <: Union{Tree, PostorderTree}}
tree::T # elimination tree
ograph::OrderedGraph # ordered graph
graph::OrderedGraph # ordered graph
end


Expand All @@ -15,27 +15,27 @@ end


# Construct the elimination tree of an ordered graph.
function EliminationTree(ograph::OrderedGraph)
EliminationTree(Tree(etree(ograph)), ograph)
function EliminationTree(graph::OrderedGraph)
EliminationTree(Tree(etree(graph)), graph)
end


# Postorder an elimination tree.
function EliminationTree{PostorderTree}(etree::EliminationTree, order::Order)
EliminationTree(PostorderTree(etree.tree, order), OrderedGraph(etree.ograph, order))
EliminationTree(PostorderTree(etree.tree, order), OrderedGraph(etree.graph, order))
end


# A Compact Row Storage Scheme for Cholesky Factors Using Elimination Trees
# Liu
# Algorithm 4.2: Elimination Tree by Path Compression.
function etree(ograph::OrderedGraph)
n = nv(ograph)
function etree(graph::OrderedGraph)
n = nv(graph)
parent = collect(1:n)
ancestor = collect(1:n)

for i in 1:n
for k in inneighbors(ograph, i)
for k in inneighbors(graph, i)
r = k

while ancestor[r] != r && ancestor[r] != i
Expand Down Expand Up @@ -102,7 +102,7 @@ function supcnt(etree::EliminationTree{PostorderTree})
for p in 1:n - 1
wt[parentindex(etree.tree, p)] -= 1

for u in outneighbors(etree.ograph, p)
for u in outneighbors(etree.graph, p)
if firstdescendant(etree.tree, p) > prev_nbr[u]
wt[p] += 1
pp = prev_p[u]
Expand Down
22 changes: 11 additions & 11 deletions src/junction_trees/supernode_trees.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# An ordered graph (G, σ) equipped with a supernodal elimination tree T.
struct SupernodeTree
tree::PostorderTree # supernodal elimination tree
ograph::OrderedGraph # ordered graph
graph::OrderedGraph # ordered graph
representative::Vector{Int} # representative vertex
cardinality::Vector{Int} # supernode cardinality
ancestor::Vector{Int} # first ancestor
Expand All @@ -28,7 +28,7 @@ function SupernodeTree(etree::EliminationTree, stype::SupernodeType=DEFAULT_SUPE
tree = PostorderTree(tree, sorder)

order = Order(vcat(snode[sorder]...))
ograph = OrderedGraph(etree.ograph, order)
graph = OrderedGraph(etree.graph, order)

n = length(tree)
representative = zeros(Int, n)
Expand All @@ -49,7 +49,7 @@ function SupernodeTree(etree::EliminationTree, stype::SupernodeType=DEFAULT_SUPE
_degree[n] = degree[n]
_ancestor[n] = ancestor[n]

SupernodeTree(tree, ograph, representative, cardinality, _ancestor, _degree)
SupernodeTree(tree, graph, representative, cardinality, _ancestor, _degree)
end


Expand Down Expand Up @@ -93,31 +93,31 @@ end

# Construct an elimination graph.
function eliminationgraph(stree::SupernodeTree)
ograph = deepcopy(stree.ograph)
graph = deepcopy(stree.graph)
n = length(stree.tree)

for i in 1:n - 1
for u in supernode(stree, i)[1:end - 1]
v = u + 1

for w in outneighbors(ograph, u)
for w in outneighbors(graph, u)
if v < w
add_edge!(ograph, v, w)
add_edge!(graph, v, w)
end
end
end

u = last(supernode(stree, i))
v = first(supernode(stree, parentindex(stree.tree, i)))

for w in outneighbors(ograph, u)
for w in outneighbors(graph, u)
if v < w
add_edge!(ograph, v, w)
add_edge!(graph, v, w)
end
end
end

ograph
graph
end


Expand All @@ -139,10 +139,10 @@ end
function seperators(stree::SupernodeTree)
n = length(stree.tree)
seperator = Vector{Vector{Int}}(undef, n)
ograph = eliminationgraph(stree)
graph = eliminationgraph(stree)

for i in 1:n
clique = collect(outneighbors(ograph, stree.representative[i]))
clique = collect(outneighbors(graph, stree.representative[i]))
filter!(j -> stree.ancestor[i] <= j, clique)
seperator[i] = clique
end
Expand Down

0 comments on commit 8ab8137

Please sign in to comment.