1
- export buildSubgraphFromLabels!
1
+ export buildSubgraphFromLabels!, buildSubgraphFromLabels!_SPECIAL
2
+ export buildSubgraphFromLabels
2
3
3
4
4
5
"""
@@ -18,91 +19,99 @@ Related
18
19
getVariableIds, _copyIntoGraph!
19
20
"""
20
21
function buildSubgraphFromLabels! (dfg:: G ,
21
- syms:: Vector{Symbol} ,
22
- destType:: Type{<:AbstractDFG} = GraphsDFG;
23
- solvable:: Int = 0 ):: G where G <: AbstractDFG
22
+ syms:: Vector{Symbol} ;
23
+ subfg:: AbstractDFG = (G <: InMemoryDFGTypes ? G : GraphsDFG)(params= getSolverParams (dfg)),
24
+ solvable:: Int = 0 ,
25
+ allowedFactors:: Union{Nothing, Vector{Symbol}} = nothing ):: G where G <: AbstractDFG
24
26
#
25
- # Same type
26
- LocalGraphType = G <: InMemoryDFGTypes ? G : destType{typeof (getSolverParms (dfg))}
27
- # data structure for cliq sub graph
28
- cliqSubFg = LocalGraphType (params= getSolverParams (dfg))
29
27
30
28
# add a little too many variables (since we need the factors)
31
29
for sym in syms
32
30
if solvable <= getSolvable (dfg, sym)
33
- getSubgraphAroundNode (dfg, getVariable (dfg, sym), 2 , false , cliqSubFg , solvable= solvable)
31
+ getSubgraphAroundNode (dfg, getVariable (dfg, sym), 2 , false , subfg , solvable= solvable)
34
32
end
35
33
end
36
34
37
35
# remove excessive variables that were copied by neighbors distance 2
38
- currVars = getVariableIds (cliqSubFg )
36
+ currVars = getVariableIds (subfg )
39
37
toDelVars = setdiff (currVars, syms)
40
38
for dv in toDelVars
41
39
# delete any neighboring factors first
42
- for fc in lsf (cliqSubFg , dv)
43
- deleteFactor! (cliqSubFg , fc)
40
+ for fc in lsf (subfg , dv)
41
+ deleteFactor! (subfg , fc)
44
42
end
45
43
46
44
# and the variable itself
47
- deleteVariable! (cliqSubFg , dv)
45
+ deleteVariable! (subfg , dv)
48
46
end
49
47
50
- return cliqSubFg
48
+ return subfg
49
+ end
50
+
51
+ function buildSubgraphFromLabels (dfg:: G ,
52
+ syms:: Vector{Symbol} ;
53
+ subfg:: AbstractDFG = (G <: InMemoryDFGTypes ? G : GraphsDFG)(params= getSolverParams (dfg)),
54
+ solvable:: Int = 0 ,
55
+ allowedFactors:: Union{Nothing, Vector{Symbol}} = nothing ):: G where G <: AbstractDFG
56
+ #
57
+ @warn " Deprecated buildSubgraphFromLabels, use buildSubgraphFromLabels! instead."
58
+ buildSubgraphFromLabels (dfg, syms, subfg= subfg, solvable= solvable, allowedFactors= allowedFactors )
51
59
end
52
60
53
61
54
62
"""
55
63
$SIGNATURES
56
64
57
- IIF clique specific version of building subgraphs.
58
-
59
- Notes
60
- - Special snowflake that adds only factors related to `frontals`.
65
+ IIF clique specific version of building subgraphs. This is was an unfortunate rewrite of the existing `buildSubgraphFromLabels!` function above. Currently halfway consolidated. Tests required to ensure these two functions can be reduced to and will perform the same in both.
61
66
62
67
DevNotes
63
68
- DF: Could we somehow better consolidate the functionality of this method into `buildSubgraphFromLabels!` above, which in turn should be consolidated as SamC suggests.
64
69
- Since this function has happened more than once, it seems the name `buildSubgraphFromLabels!` might stick around, even if it just becomes a wrapper.
65
70
66
71
Related
67
72
68
- _copyIntoGraph!
73
+ buildSubgraphFromLabels!, _copyIntoGraph!, getVariableIds
69
74
"""
70
- function buildSubgraphFromLabels! (dfg:: AbstractDFG ,
71
- cliqSubFg:: AbstractDFG ,
72
- frontals:: Vector{Symbol} ,
73
- separators:: Vector{Symbol} ;
74
- solvable:: Int = 0 )
75
+ function buildSubgraphFromLabels!_SPECIAL (dfg:: G ,
76
+ # frontals::Vector{Symbol},
77
+ syms:: Vector{Symbol} ;
78
+ subfg:: AbstractDFG = (G <: InMemoryDFGTypes ? G : GraphsDFG)(params= getSolverParams (dfg)),
79
+ solvable:: Int = 0 ,
80
+ allowedFactors:: Union{Nothing, Vector{Symbol}} = nothing ):: G where G <: AbstractDFG
75
81
#
76
- for sym in separators
77
- (solvable <= getSolvable (dfg, sym)) && DFG. addVariable! (cliqSubFg , deepcopy (DFG. getVariable (dfg, sym)))
78
- end
82
+ # for sym in separators
83
+ # (solvable <= getSolvable(dfg, sym)) && DFG.addVariable!(subfg , deepcopy(DFG.getVariable(dfg, sym)))
84
+ # end
79
85
80
86
addfac = Symbol[]
81
- for sym in frontals
87
+ for sym in syms # frontals
82
88
if solvable <= getSolvable (dfg, sym)
83
- DFG. addVariable! (cliqSubFg , deepcopy (DFG. getVariable (dfg, sym)))
84
- append! (addfac, getNeighbors (dfg,sym))
89
+ DFG. addVariable! (subfg , deepcopy (DFG. getVariable (dfg, sym)))
90
+ append! (addfac, getNeighbors (dfg, sym, solvable = solvable ))
85
91
end
86
92
end
87
93
88
- allvars = ls (cliqSubFg)
89
- for sym in addfac
94
+ # allowable factors as intersect between connected an user list
95
+ usefac = allowedFactors == nothing ? addfac : intersect (allowedFactors, addfac)
96
+
97
+ allvars = ls (subfg)
98
+ for sym in usefac
90
99
fac = DFG. getFactor (dfg, sym)
91
100
vos = fac. _variableOrderSymbols
92
101
# 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))
102
+ if ! exists (subfg ,fac) && ( vos ⊆ allvars) && ( solvable <= getSolvable (dfg, sym) )
103
+ DFG. addFactor! (subfg , fac. _variableOrderSymbols, deepcopy (fac))
95
104
end
96
105
end
97
106
98
107
# remove orphans
99
- for fct in DFG. getFactors (cliqSubFg )
108
+ for fct in DFG. getFactors (subfg )
100
109
# delete any neighboring factors first
101
- if length (getNeighbors (cliqSubFg , fct)) != length (fct. _variableOrderSymbols)
102
- DFG. deleteFactor! (cliqSubFg , fc)
110
+ if length (getNeighbors (subfg , fct)) != length (fct. _variableOrderSymbols)
111
+ DFG. deleteFactor! (subfg , fc)
103
112
@error " deleteFactor! this should not happen"
104
113
end
105
114
end
106
115
107
- return cliqSubFg
116
+ return subfg
108
117
end
0 commit comments