Skip to content

Commit d1e9cce

Browse files
authored
Merge pull request #717 from JuliaRobotics/feat/4Q20/filtershortestpath
add filters for shortest path
2 parents 8c1078f + ee967ac commit d1e9cce

File tree

3 files changed

+68
-18
lines changed

3 files changed

+68
-18
lines changed

src/LightDFG/services/LightDFG.jl

Lines changed: 49 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -366,6 +366,9 @@ end
366366
367367
Speciallized function available to only LightDFG at this time.
368368
369+
Notes
370+
- Has option for various types of filters (increases memory usage)
371+
369372
Example
370373
```julia
371374
using IncrementalInference
@@ -379,24 +382,63 @@ fg = generateCanonicalFG_Kaess()
379382
```
380383
381384
DevNotes
382-
- # TODO expand to other AbstractDFG entities.
385+
- TODO expand to other AbstractDFG entities.
386+
- TODO use of filter resource consumption can be improved.
383387
384388
Related
385389
386390
[`findFactorsBetweenNaive`](@ref), `LightGraphs.dijkstra_shortest_paths`
387391
"""
388392
function findShortestPathDijkstra( dfg::LightDFG,
389393
from::Symbol,
390-
to::Symbol )
394+
to::Symbol;
395+
regexVariables::Union{Nothing, Regex}=nothing,
396+
regexFactors::Union{Nothing, Regex}=nothing,
397+
tagsVariables::Vector{Symbol}=Symbol[],
398+
tagsFactors::Vector{Symbol}=Symbol[],
399+
typeVariables::Union{Nothing, <:AbstractVector}=nothing,
400+
typeFactors::Union{Nothing, <:AbstractVector}=nothing,
401+
solvable::Int=0 )
402+
#
403+
# helper function to filter on vector of types
404+
function _filterTypeList(thelist::Vector{Symbol}, typeList, listfnc=x->ls(dfg, x) )
405+
thelist_ = Symbol[]
406+
for type_ in typeList
407+
union!(thelist_, listfnc(type_))
408+
end
409+
@show thelist_
410+
intersect( thelist, thelist_ )
411+
end
412+
391413
#
414+
duplicate = regexVariables !== nothing ||
415+
regexFactors !== nothing ||
416+
0 < length(tagsVariables) ||
417+
0 < length(tagsFactors) ||
418+
typeVariables !== nothing ||
419+
typeFactors !== nothing ||
420+
solvable != 0
421+
#
422+
dfg_ = if duplicate
423+
# use copy if filter is being applied
424+
varList = ls(dfg, regexVariables, tags=tagsVariables, solvable=solvable)
425+
fctList = lsf(dfg, regexFactors, tags=tagsFactors, solvable=solvable)
426+
varList = typeVariables !== nothing ? _filterTypeList(varList, typeVariables) : varList
427+
fctList = typeFactors !== nothing ? _filterTypeList(fctList, typeFactors, x->lsf(dfg, x)) : fctList
428+
deepcopyGraph(typeof(dfg), dfg, varList, fctList)
429+
else
430+
# no filter can be used directly
431+
dfg
432+
end
433+
392434
# LightDFG internally uses Integers
393-
frI = dfg.g.labels[from]
394-
toI = dfg.g.labels[to]
435+
frI = dfg_.g.labels[from]
436+
toI = dfg_.g.labels[to]
395437

396438
# get shortest path from graph provider
397-
path_state = LightGraphs.dijkstra_shortest_paths(dfg.g.graph, [frI;])
398-
path = LightGraphs.enumerate_paths(path_state, toI)
399-
dijkpath = map(x->dfg.g.labels[x], path)
439+
path_state = LightGraphs.dijkstra_shortest_paths( dfg_.g.graph, [frI;] )
440+
path = LightGraphs.enumerate_paths( path_state, toI )
441+
dijkpath = map( x->dfg_.g.labels[x], path )
400442

401443
# return the list of symbols
402444
return dijkpath

src/entities/DFGFactor.jl

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,22 @@
22
## Abstract Types
33
##==============================================================================
44

5+
# TODO consider changing this to AbstractFactor
56
abstract type FunctorInferenceType <: Function end
67
abstract type PackedInferenceType end
78

9+
abstract type AbstractPrior <: FunctorInferenceType end
10+
abstract type AbstractRelative <: FunctorInferenceType end
11+
abstract type AbstractRelativeRoots <: AbstractRelative end
12+
abstract type AbstractRelativeMinimize <: AbstractRelative end
13+
814
# NOTE DF, Convolution is IIF idea, but DFG should know about "FactorOperationalMemory"
915
# DF, IIF.CommonConvWrapper <: FactorOperationalMemory #
1016
abstract type FactorOperationalMemory <: Function end
1117
# TODO to be removed from DFG,
1218
# we can add to IIF or have IIF.CommonConvWrapper <: FactorOperationalMemory directly
1319
# abstract type ConvolutionObject <: FactorOperationalMemory end
1420

15-
abstract type AbstractPrior <: FunctorInferenceType end
16-
abstract type AbstractRelative <: FunctorInferenceType end
17-
abstract type AbstractRelativeRoots <: AbstractRelative end
18-
abstract type AbstractRelativeMinimize <: AbstractRelative end
19-
2021
##==============================================================================
2122
## GenericFunctionNodeData
2223
##==============================================================================

src/services/AbstractDFG.jl

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,12 +1027,12 @@ Related:
10271027
- [`getNeighborhood`](@ref)
10281028
- [`mergeGraph!`](@ref)
10291029
"""
1030-
function deepcopyGraph(::Type{T},
1031-
sourceDFG::AbstractDFG,
1032-
variableLabels::Vector{Symbol} = ls(sourceDFG),
1033-
factorLabels::Vector{Symbol} = lsf(sourceDFG);
1034-
sessionId::String = "",
1035-
kwargs...) where T <: AbstractDFG
1030+
function deepcopyGraph( ::Type{T},
1031+
sourceDFG::AbstractDFG,
1032+
variableLabels::Vector{Symbol} = ls(sourceDFG),
1033+
factorLabels::Vector{Symbol} = lsf(sourceDFG);
1034+
sessionId::String = "",
1035+
kwargs...) where T <: AbstractDFG
10361036

10371037
ginfo = [getDFGInfo(sourceDFG)...]
10381038
if sessionId == ""
@@ -1089,17 +1089,24 @@ end
10891089
$SIGNATURES
10901090
Return (::Bool,::Vector{TypeName}) of types between two nodes in the factor graph
10911091
1092+
DevNotes
1093+
- Only works on LigthDFG at the moment.
1094+
10921095
Related
10931096
10941097
[`LightDFG.findShortestPathDijkstra`](@ref)
10951098
"""
10961099
function isPathFactorsHomogeneous(dfg::AbstractDFG, from::Symbol, to::Symbol)
1100+
# FIXME, must consider all paths, not just shortest...
10971101
pth = intersect(findShortestPathDijkstra(dfg, from, to), lsf(dfg))
10981102
types = getFactorType.(dfg, pth) .|> typeof .|> x->(x).name
10991103
utyp = unique(types)
11001104
(length(utyp) == 1), utyp
11011105
end
11021106

1107+
function existsPathOfFactorsType(dfg::AbstractDFG, from::Symbol, to::Symbol, ftype::FunctorInferenceType)
1108+
error("WIP")
1109+
end
11031110

11041111
##==============================================================================
11051112
## Subgraphs and Neighborhoods

0 commit comments

Comments
 (0)