Skip to content

Commit b260468

Browse files
authored
Merge pull request #719 from JuliaRobotics/feat/4Q20/shortpinit
xtra filter or shortest path, initialized
2 parents 2d361dd + 52acf45 commit b260468

File tree

2 files changed

+25
-12
lines changed

2 files changed

+25
-12
lines changed

src/LightDFG/services/LightDFG.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,8 @@ function findShortestPathDijkstra( dfg::LightDFG,
398398
tagsFactors::Vector{Symbol}=Symbol[],
399399
typeVariables::Union{Nothing, <:AbstractVector}=nothing,
400400
typeFactors::Union{Nothing, <:AbstractVector}=nothing,
401-
solvable::Int=0 )
401+
solvable::Int=0,
402+
initialized::Union{Nothing,Bool}=nothing )
402403
#
403404
# helper function to filter on vector of types
404405
function _filterTypeList(thelist::Vector{Symbol}, typeList, listfnc=x->ls(dfg, x) )
@@ -417,6 +418,7 @@ function findShortestPathDijkstra( dfg::LightDFG,
417418
0 < length(tagsFactors) ||
418419
typeVariables !== nothing ||
419420
typeFactors !== nothing ||
421+
initialized !== nothing ||
420422
solvable != 0
421423
#
422424
dfg_ = if duplicate
@@ -425,13 +427,23 @@ function findShortestPathDijkstra( dfg::LightDFG,
425427
fctList = lsf(dfg, regexFactors, tags=tagsFactors, solvable=solvable)
426428
varList = typeVariables !== nothing ? _filterTypeList(varList, typeVariables) : varList
427429
fctList = typeFactors !== nothing ? _filterTypeList(fctList, typeFactors, x->lsf(dfg, x)) : fctList
430+
varList = if initialized !== nothing
431+
initmask = isInitialized.(dfg, varList) .== initialized
432+
varList[initmask]
433+
else
434+
varList
435+
end
428436
deepcopyGraph(typeof(dfg), dfg, varList, fctList)
429437
else
430438
# no filter can be used directly
431439
dfg
432440
end
433441

434442
# LightDFG internally uses Integers
443+
if !haskey(dfg_.g.labels, from) || !haskey(dfg_.g.labels, from)
444+
# assume filters excluded either `to` or `from` and hence no shortest path
445+
return Symbol[]
446+
end
435447
frI = dfg_.g.labels[from]
436448
toI = dfg_.g.labels[to]
437449

src/services/DFGVariable.jl

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -136,23 +136,24 @@ isSolved(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol=:default) = isSolved(ge
136136
"""
137137
$SIGNATURES
138138
139-
Returns state of vertex data `.initialized` flag.
139+
Returns state of variable data `.initialized` flag.
140140
141141
Notes:
142142
- used by both factor graph variable and Bayes tree clique logic.
143143
"""
144-
function isInitialized(var::DFGVariable, key::Symbol=:default)::Bool
145-
data = getSolverData(var, key)
146-
if data == nothing
147-
#TODO we still have a mixture of 2 error behaviours
148-
return false
149-
else
150-
return data.initialized
151-
end
144+
function isInitialized(var::DFGVariable, key::Symbol=:default)
145+
data = getSolverData(var, key)
146+
if data === nothing
147+
#TODO we still have a mixture of 2 error behaviours
148+
# DF, not sure I follow the error here?
149+
return false
150+
else
151+
return data.initialized
152+
end
152153
end
153154

154-
function isInitialized(dfg::AbstractDFG, label::Symbol, key::Symbol=:default)::Bool
155-
return isInitialized(getVariable(dfg, label), key)
155+
function isInitialized(dfg::AbstractDFG, label::Symbol, key::Symbol=:default)
156+
return isInitialized(getVariable(dfg, label), key)::Bool
156157
end
157158

158159

0 commit comments

Comments
 (0)