Skip to content

Commit 6e6973f

Browse files
committed
special snowflake buildSubgraphFromLabels
1 parent 963b972 commit 6e6973f

File tree

1 file changed

+67
-11
lines changed

1 file changed

+67
-11
lines changed

src/needsahome.jl

Lines changed: 67 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,26 +11,25 @@ Will paste in as-is for now and we can figure it out as we go.
1111
1212
Notes
1313
- Slighly messy internals, but gets the job done -- some room for performance improvement.
14+
- Defaults to GraphDFG, but likely to change to LightDFG in future.
15+
1416
Related
15-
getVariableIds
17+
18+
getVariableIds, _copyIntoGraph!
1619
"""
1720
function buildSubgraphFromLabels!(dfg::G,
1821
syms::Vector{Symbol},
19-
destType::Type{<:AbstractDFG}=GraphsDFG; #Which one? I don't have a strong opinion on this.
22+
destType::Type{<:AbstractDFG}=GraphsDFG;
2023
solvable::Int=0)::G where G <: AbstractDFG
21-
24+
#
25+
#Same type
26+
LocalGraphType = G <: InMemoryDFGTypes ? G : destType{typeof(getSolverParms(dfg))}
2227
# data structure for cliq sub graph
23-
if G <: InMemoryDFGTypes
24-
#Same type
25-
cliqSubFg = G(params=getSolverParams(dfg))
26-
else
27-
#Default if not in-memory
28-
cliqSubFg = destType{typeof(getSolverParms(dfg))}(params=getSolverParams(dfg))
29-
end
28+
cliqSubFg = LocalGraphType(params=getSolverParams(dfg))
3029

3130
# add a little too many variables (since we need the factors)
3231
for sym in syms
33-
if getSolvable(dfg, sym) >= solvable
32+
if solvable <= getSolvable(dfg, sym)
3433
getSubgraphAroundNode(dfg, getVariable(dfg, sym), 2, false, cliqSubFg, solvable=solvable)
3534
end
3635
end
@@ -50,3 +49,60 @@ function buildSubgraphFromLabels!(dfg::G,
5049

5150
return cliqSubFg
5251
end
52+
53+
54+
"""
55+
$SIGNATURES
56+
57+
IIF clique specific version of building subgraphs.
58+
59+
Notes
60+
- Special snowflake that adds only factors related to `frontals`.
61+
62+
DevNotes
63+
- DF: Could we somehow better consolidate the functionality of this method into `buildSubgraphFromLabels!` above, which in turn should be consolidated as SamC suggests.
64+
- Since this function has happened more than once, it seems the name `buildSubgraphFromLabels!` might stick around, even if it just becomes a wrapper.
65+
66+
Related
67+
68+
_copyIntoGraph!
69+
"""
70+
function buildSubgraphFromLabels!(dfg::AbstractDFG,
71+
cliqSubFg::AbstractDFG,
72+
frontals::Vector{Symbol},
73+
separators::Vector{Symbol};
74+
solvable::Int=0)
75+
#
76+
for sym in separators
77+
(solvable <= getSolvable(dfg, sym)) && DFG.addVariable!(cliqSubFg, deepcopy(DFG.getVariable(dfg, sym)))
78+
end
79+
80+
addfac = Symbol[]
81+
for sym in frontals
82+
if solvable <= getSolvable(dfg, sym)
83+
DFG.addVariable!(cliqSubFg, deepcopy(DFG.getVariable(dfg, sym)))
84+
append!(addfac, getNeighbors(dfg,sym))
85+
end
86+
end
87+
88+
allvars = ls(cliqSubFg)
89+
for sym in addfac
90+
fac = DFG.getFactor(dfg, sym)
91+
vos = fac._variableOrderSymbols
92+
#TODO don't add duplicates to start with
93+
if !exists(cliqSubFg,fac) && vos allvars && solvable <= getSolvable(dfg, sym)
94+
DFG.addFactor!(cliqSubFg, fac._variableOrderSymbols, deepcopy(fac))
95+
end
96+
end
97+
98+
# remove orphans
99+
for fct in DFG.getFactors(cliqSubFg)
100+
# delete any neighboring factors first
101+
if length(getNeighbors(cliqSubFg, fct)) != length(fct._variableOrderSymbols)
102+
DFG.deleteFactor!(cliqSubFg, fc)
103+
@error "deleteFactor! this should not happen"
104+
end
105+
end
106+
107+
return cliqSubFg
108+
end

0 commit comments

Comments
 (0)