Skip to content

Commit c85774a

Browse files
committed
mergeGraph!
1 parent 6ae1537 commit c85774a

File tree

3 files changed

+70
-17
lines changed

3 files changed

+70
-17
lines changed

src/Deprecated.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ end
119119
##==============================================================================
120120
## WIP on consolidated subgraph functions, aim to remove in 0.8
121121
##==============================================================================
122+
# Deprecate in favor of buildSubgraph, mergeGraph
123+
export getSubgraph, getSubgraphAroundNode
124+
export buildSubgraphFromLabels!
122125

123126
"""
124127
$(SIGNATURES)

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,9 +162,7 @@ export packVariableNodeData, unpackVariableNodeData
162162
export getSolvedCount, isSolved, setSolvedCount!, isInitialized
163163

164164
export getNeighborhood, getNeighbors, _getDuplicatedEmptyDFG
165-
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph
166-
# TODO Deprecate in favor of buildSubgraph
167-
export getSubgraph, getSubgraphAroundNode
165+
export copyGraph!, deepcopyGraph, deepcopyGraph!, buildSubgraph, mergeGraph!
168166
# Big Data
169167
##------------------------------------------------------------------------------
170168
export addBigDataEntry!, getBigDataEntry, updateBigDataEntry!, deleteBigDataEntry!, getBigDataEntries, getBigDataKeys
@@ -226,13 +224,10 @@ export
226224
compareFactorGraphs
227225

228226

229-
## Deprecated.jl should be listed there
227+
## Deprecated exports should be listed in Deprecated.jl if possible, otherwise here
230228

231229

232230
## needsahome.jl
233-
234-
export buildSubgraphFromLabels!
235-
236231
import Base: print
237232
export printFactor, printVariable, print
238233

src/services/AbstractDFG.jl

Lines changed: 65 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,16 @@ end
784784
"""
785785
$(SIGNATURES)
786786
Common function for copying nodes from one graph into another graph.
787-
This is overwritten in specialized implementations for performance.
787+
This is overridden in specialized implementations for performance.
788788
Orphaned factors are not added, with a warning if verbose.
789789
Set `overwriteDest` to overwrite existing variables and factors in the destination DFG.
790790
NOTE: copyGraphMetadata not supported yet.
791+
Related:
792+
- [`deepcopyGraph`](@ref)
793+
- [`deepcopyGraph!`](@ref)
794+
- [`buildSubgraph`](@ref)
795+
- [`getNeighborhood`](@ref)
796+
- [`mergeGraph!`](@ref)
791797
Dev Note:
792798
- Adapted from and replaces internal _copyIntoGraph!
793799
"""
@@ -877,6 +883,11 @@ end
877883
"""
878884
$(SIGNATURES)
879885
Build a list of all unique neighbors inside 'distance'
886+
Related:
887+
- [`copyGraph!`](@ref)
888+
- [`buildSubgraph`](@ref)
889+
- [`deepcopyGraph`](@ref)
890+
- [`mergeGraph!`](@ref)
880891
"""
881892
function getNeighborhood(dfg::AbstractDFG, label::Symbol, distance::Int)::Vector{Symbol}
882893
neighborList = Set{Symbol}([label])
@@ -896,15 +907,7 @@ function getNeighborhood(dfg::AbstractDFG, label::Symbol, distance::Int)::Vector
896907
return collect(neighborList)
897908
end
898909

899-
"""
900-
$(SIGNATURES)
901-
Build a deep subgraph copy from the DFG given a list of variables and factors and an optional distance.
902-
Note: Orphaned factors (where the subgraph does not contain all the related variables) are not returned.
903-
Dev Notes
904-
- Bulk vs node for node: a list of labels are compiled and the sugraph is copied in bulk.
905-
"""
906-
function buildSubgraph(::Type{G}, dfg::AbstractDFG, variableFactorLabels::Vector{Symbol}, distance::Int=0; solvable::Int=0, kwargs...) where G <: AbstractDFG
907-
910+
function getNeighborhood(dfg::AbstractDFG, variableFactorLabels::Vector{Symbol}, distance::Int; solvable::Int=0)::Vector{Symbol}
908911
# find neighbors at distance to add
909912
neighbors = Symbol[]
910913
if distance > 0
@@ -917,11 +920,63 @@ function buildSubgraph(::Type{G}, dfg::AbstractDFG, variableFactorLabels::Vector
917920

918921
solvable != 0 && filter!(nlbl -> (getSolvable(dfg, nlbl) >= solvable), allvarfacs)
919922

923+
return allvarfacs
924+
925+
end
926+
927+
"""
928+
$(SIGNATURES)
929+
Build a deep subgraph copy from the DFG given a list of variables and factors and an optional distance.
930+
Note: Orphaned factors (where the subgraph does not contain all the related variables) are not returned.
931+
Related:
932+
- [`copyGraph!`](@ref)
933+
- [`getNeighborhood`](@ref)
934+
- [`deepcopyGraph`](@ref)
935+
- [`mergeGraph!`](@ref)
936+
Dev Notes
937+
- Bulk vs node for node: a list of labels are compiled and the sugraph is copied in bulk.
938+
"""
939+
function buildSubgraph(::Type{G},
940+
dfg::AbstractDFG,
941+
variableFactorLabels::Vector{Symbol},
942+
distance::Int=0;
943+
solvable::Int=0,
944+
kwargs...) where G <: AbstractDFG
945+
946+
#build up the neighborhood from variableFactorLabels
947+
allvarfacs = getNeighborhood(dfg, variableFactorLabels, distance; solvable=solvable)
948+
920949
# Copy the section of graph we want
921950
destDFG = deepcopyGraph(G, dfg, allvarfacs; kwargs...)
922951
return destDFG
923952
end
924953

954+
"""
955+
$(SIGNATURES)
956+
Merger sourceDFG to destDFG given an optional list of variables and factors and distance.
957+
Notes:
958+
- Nodes already in the destination graph are updated from sourceDFG.
959+
- Orphaned factors (where the subgraph does not contain all the related variables) are not included.
960+
Related:
961+
- [`copyGraph!`](@ref)
962+
- [`buildSubgraph`](@ref)
963+
- [`getNeighborhood`](@ref)
964+
- [`deepcopyGraph`](@ref)
965+
"""
966+
function mergeGraph!(destDFG::AbstractDFG,
967+
sourceDFG::AbstractDFG,
968+
variableFactorLabels::Vector{Symbol} = union(ls(sourceDFG), lsf(sourceDFG)),
969+
distance::Int = 0;
970+
solvable::Int = 0,
971+
kwargs...)
972+
973+
# find neighbors at distance to add
974+
allvarfacs = getNeighborhood(sourceDFG, variableFactorLabels, distance; solvable=solvable)
975+
976+
copyGraph!(destDFG, sourceDFG, allvarfacs; deepcopyNodes=true, overwriteDest=true, kwargs...)
977+
978+
return destDFG
979+
end
925980

926981
##==============================================================================
927982
## Variable Data: VND and PPE

0 commit comments

Comments
 (0)