33 alg::PermutationOrAlgorithm=DEFAULT_ELIMINATION_ALGORITHM,
44 snd::SupernodeType=DEFAULT_SUPERNODE_TYPE)
55
6- Construct a structured decomposition of a simple graph. See [`junctiontree `](@ref) for the meaning of `alg` and `snd`.
6+ Construct a structured decomposition of a simple graph. See [`cliquetree `](@ref) for the meaning of `alg` and `snd`.
77"""
88function StrDecomp(graph:: HasGraph ; alg:: PermutationOrAlgorithm = DEFAULT_ELIMINATION_ALGORITHM, snd:: SupernodeType = DEFAULT_SUPERNODE_TYPE)
9- label, tree = junctiontree(adjacency_matrix(graph); alg, snd)
10- relative!(tree)
9+ label, tree = cliquetree(symmetrize(graph); alg, snd)
1110 n = length(tree)
1211 shape = Graph(n)
1312
14- for i in 1 : n - 1
15- add_edge!(shape, parentindex(tree, i), i)
13+ for i in 1 : n
14+ j = parentindex(tree, i)
15+
16+ if ! isnothing(j)
17+ add_edge!(shape, j, i)
18+ end
1619 end
1720
1821 diagram = FinDomFunctor(homomorphisms(graph, label, tree). .. , ∫(shape))
1922 StrDecomp(shape, diagram, Decomposition, dom(diagram))
2023end
2124
2225
23- function homomorphisms(graph:: HasGraph , label:: AbstractVector , tree:: JunctionTree )
26+ function homomorphisms(graph:: HasGraph , label:: AbstractVector , tree:: CliqueTree )
2427 m = length(collect(rootindices(tree)))
2528 n = length(tree)
29+ relative = relatives(tree)
2630 subgraph = Vector{Any}(undef, 2 n - m)
2731 homomorphism = Vector{Any}(undef, 2 n - 2 m)
2832
@@ -43,7 +47,7 @@ function homomorphisms(graph::HasGraph, label::AbstractVector, tree::JunctionTre
4347 subgraph[n + k] = induced_subgraph(graph, view(label, separator(tree, i)))
4448
4549 # separator(i) → bag(j)
46- homomorphism[k] = induced_homomorphism(subgraph[n + k], subgraph[j], relative(tree , i))
50+ homomorphism[k] = induced_homomorphism(subgraph[n + k], subgraph[j], CliqueTrees . neighbors(relative , i))
4751
4852 # separator(i) → bag(i)
4953 homomorphism[n - m + k] = induced_homomorphism(subgraph[n + k], subgraph[i], length(residual(tree, i)) .+ eachindex(separator(tree, i)))
@@ -72,24 +76,13 @@ function induced_homomorphism(domain::HasGraph, codomain::HasGraph, V::AbstractV
7276end
7377
7478
75- # Construct the adjacency matrix of an undirected graph.
76- function adjacency_matrix(graph:: HasGraph )
77- symmetric = SymmetricGraph(nv(graph))
78- add_edges!(symmetric, src(graph), tgt(graph))
79- adjacency_matrix(symmetric)
79+ function symmetrize(graph:: AbstractSymmetricGraph )
80+ graph
8081end
8182
8283
83- function adjacency_matrix(graph:: AbstractSymmetricGraph )
84- matrix = spzeros(Bool, Int, nv(graph), nv(graph))
85- sizehint!(rowvals(matrix), ne(graph))
86-
87- for v in vertices(graph)
88- append!(rowvals(matrix), neighbors(graph, v))
89- getcolptr(matrix)[v + 1 ] = length(rowvals(matrix)) + 1
90- end
91-
92- resize!(nonzeros(matrix), ne(graph))
93- fill!(nonzeros(matrix), true )
94- matrix
84+ function symmetrize(graph:: HasGraph )
85+ symmetric = SymmetricGraph(nv(graph))
86+ add_edges!(symmetric, src(graph), tgt(graph))
87+ symmetric
9588end
0 commit comments