@@ -784,10 +784,16 @@ end
784
784
"""
785
785
$(SIGNATURES)
786
786
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.
788
788
Orphaned factors are not added, with a warning if verbose.
789
789
Set `overwriteDest` to overwrite existing variables and factors in the destination DFG.
790
790
NOTE: copyGraphMetadata not supported yet.
791
+ Related:
792
+ - [`deepcopyGraph`](@ref)
793
+ - [`deepcopyGraph!`](@ref)
794
+ - [`buildSubgraph`](@ref)
795
+ - [`getNeighborhood`](@ref)
796
+ - [`mergeGraph!`](@ref)
791
797
Dev Note:
792
798
- Adapted from and replaces internal _copyIntoGraph!
793
799
"""
877
883
"""
878
884
$(SIGNATURES)
879
885
Build a list of all unique neighbors inside 'distance'
886
+ Related:
887
+ - [`copyGraph!`](@ref)
888
+ - [`buildSubgraph`](@ref)
889
+ - [`deepcopyGraph`](@ref)
890
+ - [`mergeGraph!`](@ref)
880
891
"""
881
892
function getNeighborhood (dfg:: AbstractDFG , label:: Symbol , distance:: Int ):: Vector{Symbol}
882
893
neighborList = Set {Symbol} ([label])
@@ -896,15 +907,7 @@ function getNeighborhood(dfg::AbstractDFG, label::Symbol, distance::Int)::Vector
896
907
return collect (neighborList)
897
908
end
898
909
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}
908
911
# find neighbors at distance to add
909
912
neighbors = Symbol[]
910
913
if distance > 0
@@ -917,11 +920,63 @@ function buildSubgraph(::Type{G}, dfg::AbstractDFG, variableFactorLabels::Vector
917
920
918
921
solvable != 0 && filter! (nlbl -> (getSolvable (dfg, nlbl) >= solvable), allvarfacs)
919
922
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
+
920
949
# Copy the section of graph we want
921
950
destDFG = deepcopyGraph (G, dfg, allvarfacs; kwargs... )
922
951
return destDFG
923
952
end
924
953
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
925
980
926
981
# #==============================================================================
927
982
# # Variable Data: VND and PPE
0 commit comments