You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Retrieve a deep subgraph copy around a given variable or factor.
179
+
Optionally provide a distance to specify the number of edges should be followed.
180
+
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
181
+
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
182
+
Note: Always returns the node at the center, but filters around it if solvable is set.
Get a deep subgraph copy from the DFG given a list of variables and factors.
205
+
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
206
+
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
207
+
"""
208
+
functiongetSubgraph(dfg::G,
209
+
variableFactorLabels::Vector{Symbol},
210
+
includeOrphanFactors::Bool=false,
211
+
addToDFG::H=_getDuplicatedEmptyDFG(dfg))::Hwhere {G <:AbstractDFG, H <:AbstractDFG}
212
+
213
+
Base.depwarn("getSubgraph is deprecated use buildSubgraph", :getSubgraph)
214
+
215
+
for label in variableFactorLabels
216
+
if!exists(dfg, label)
217
+
error("Variable/factor with label '$(label)' does not exist in the factor graph")
#TODO needsahome: home should be in IIF, calling just deepcopyGraph, or copyGraph
227
+
# Into, Labels, Subgraph are all implied from the parameters.
228
+
# can alies names but like Sam suggested only on copy is needed.
229
+
230
+
231
+
"""
232
+
$SIGNATURES
233
+
Construct a new factor graph object as a subgraph of `dfg <: AbstractDFG` based on the
234
+
variable labels `syms::Vector{Symbols}`.
235
+
236
+
SamC: Can we not just use _copyIntoGraph! for this? Looks like a small refactor to make it work.
237
+
Will paste in as-is for now and we can figure it out as we go.
238
+
DF: Absolutely agree that subgraph functions should use `DFG._copyIntoGraph!` as a single dependency in the code base. There have been a repeated new rewrites of IIF.buildSubGraphFromLabels (basic wrapper is fine) but nominal should be to NOT duplicate DFG functionality in IIF -- rather use/improve the existing features in DFG. FYI, I have repeatedly refactored this function over and over to use DFG properly but somehow this (add/delete/Variable/Factor) version keeps coming back without using `_copyIntoGraph`!!??? See latest effort commented out below `buildSubgraphFromLabels!_SPECIAL`...
239
+
240
+
Notes
241
+
- Slighly messy internals, but gets the job done -- some room for performance improvement.
242
+
- Defaults to GraphDFG, but likely to change to LightDFG in future.
243
+
- since DFG v0.6 LightDFG is the default.
244
+
245
+
DevNotes
246
+
- TODO: still needs to be consolidated with `DFG._copyIntoGraph`
247
+
248
+
Related
249
+
250
+
listVariables, _copyIntoGraph!
251
+
"""
252
+
functionbuildSubgraphFromLabels!(dfg::G,
253
+
syms::Vector{Symbol};
254
+
subfg::AbstractDFG=(G <:InMemoryDFGTypes? G : GraphsDFG)(params=getSolverParams(dfg)),
255
+
solvable::Int=0,
256
+
allowedFactors::Union{Nothing, Vector{Symbol}}=nothing )::AbstractDFGwhere G <:AbstractDFG
257
+
#
258
+
Base.depwarn("buildSubgraphFromLabels! is deprecated use copyGraph, buildSubgraph or buildCliqueSubgraph!(IIF)", :buildSubgraphFromLabels!)
259
+
# add a little too many variables (since we need the factors)
@@ -255,42 +255,6 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int=0)::Vector{Sy
255
255
returnmap(n -> n.dfgNode.label, neighbors)
256
256
end
257
257
258
-
#NOTE Replaced by abstract function in services/AbstractDFG.jl
259
-
# """
260
-
# $(SIGNATURES)
261
-
# Retrieve a deep subgraph copy around a given variable or factor.
262
-
# Optionally provide a distance to specify the number of edges should be followed.
263
-
# Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
264
-
# Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
265
-
# """
266
-
# function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}(); solvable::Int=0)::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
267
-
# if !haskey(dfg.labelDict, node.label)
268
-
# error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
269
-
# end
270
-
#
271
-
# # Build a list of all unique neighbors inside 'distance'
includeOrphanFactors && (@error"Adding orphaned factors is not supported")
269
+
#TODO copy LightDFG to LightDFG overwrite
270
+
# function copyGraph!(destDFG::LightDFG,
271
+
# sourceDFG::LightDFG,
272
+
# variableFactorLabels::Vector{Symbol};
273
+
# copyGraphMetadata::Bool=false,
274
+
# overwriteDest::Bool=false,
275
+
# deepcopyNodes::Bool=false,
276
+
# verbose::Bool = true)
271
277
272
-
#kan ek die in bulk copy, soos graph en dan nuwe map maak
273
-
# Add all variables first,
274
-
labels = [sourceDFG.g.labels[i] for i in ns]
278
+
functionbuildSubgraph(::Type{G}, dfg::LightDFG, variableFactorLabels::Vector{Symbol}, distance::Int=0; solvable::Int=0, kwargs...) where G <:AbstractDFG
# where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
326
-
327
-
functiongetSubgraph(dfg::LightDFG{P,V,F}, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}())::LightDFGwhere {P <:AbstractParams, V <:AbstractDFGVariable, F <:AbstractDFGFactor}
328
-
for label in variableFactorLabels
329
-
if!exists(dfg, label)
330
-
error("Variable/factor with label '$(label)' does not exist in the factor graph")
331
-
end
332
-
end
333
-
334
-
variableFactorInts = [dfg.g.labels[s] for s in variableFactorLabels]
0 commit comments