Skip to content

Commit bbe8f12

Browse files
authored
Merge pull request #720 from JuliaRobotics/master
v0.11.2-rc1
2 parents ca3ee9f + b260468 commit bbe8f12

File tree

7 files changed

+121
-52
lines changed

7 files changed

+121
-52
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.11.1"
3+
version = "0.11.2"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,8 @@ function listVariables(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=n
397397
if regexFilter == nothing
398398
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(join(_getLabelsForType(dfg, DFGVariable),':'))) where node.solvable >= $solvable $tagsFilter")
399399
else
400-
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(join(_getLabelsForType(dfg, DFGVariable),':'))) where node.label =~ '$(regexFilter.pattern)' and node.solvable >= $solvable $tagsFilter")
400+
# Not happy about this but need to double escape the strings.
401+
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(join(_getLabelsForType(dfg, DFGVariable),':'))) where node.label =~ '$(replace(regexFilter.pattern, "\\" => "\\\\"))' and node.solvable >= $solvable $tagsFilter")
401402
end
402403
end
403404

@@ -413,7 +414,7 @@ function listFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=not
413414
if regexFilter == nothing
414415
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(join(_getLabelsForType(dfg, DFGFactor),':'))) where node.solvable >= $solvable")
415416
else
416-
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(join(_getLabelsForType(dfg, DFGFactor),':'))) where node.label =~ '$(regexFilter.pattern)' and node.solvable >= $solvable $tagsFilter")
417+
return _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(node:$(join(_getLabelsForType(dfg, DFGFactor),':'))) where node.label =~ '$(replace(regexFilter.pattern, "\\" => "\\\\"))' and node.solvable >= $solvable $tagsFilter")
417418
end
418419
end
419420

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export toDot, toDotFile
238238

239239
# shortest path
240240
export findShortestPathDijkstra
241+
export isPathFactorsHomogeneous
241242

242243
# Comparisons
243244
export

src/LightDFG/services/LightDFG.jl

Lines changed: 71 additions & 27 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
@@ -374,41 +377,82 @@ using IncrementalInference
374377
fg = generateCanonicalFG_Kaess()
375378
376379
@show path = findShortestPathDijkstra(fg, :x1, :x3)
377-
@show isVariable.(path)
378-
@show isFactor.(path)
380+
@show isVariable.(fg, path)
381+
@show isFactor.(fg, path)
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
386-
[findFactorsBetweenNaive](@ref), `LightGraphs.dijkstra_shortest_paths`
390+
[`findFactorsBetweenNaive`](@ref), `LightGraphs.dijkstra_shortest_paths`
387391
"""
388392
function findShortestPathDijkstra( dfg::LightDFG,
389393
from::Symbol,
390-
to::Symbol )
391-
#
392-
# LightDFG internally uses Integers
393-
frI = dfg.g.labels[from]
394-
toI = dfg.g.labels[to]
395-
396-
path = LightGraphs.dijkstra_shortest_paths(dfg.g.graph, [toI;])
397-
# path = LightGraphs.enumerate_paths(path_state, toI)
398-
399-
# assemble into the list
400-
dijkpath = Symbol[]
401-
# test for connectivity
402-
if path.dists[frI] < Inf
403-
cursor = frI
404-
push!(dijkpath, dfg.g.labels[cursor])
405-
# walk the path
406-
while cursor != toI
407-
cursor = path.parents[cursor]
408-
push!(dijkpath, dfg.g.labels[cursor])
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+
initialized::Union{Nothing,Bool}=nothing )
403+
#
404+
# helper function to filter on vector of types
405+
function _filterTypeList(thelist::Vector{Symbol}, typeList, listfnc=x->ls(dfg, x) )
406+
thelist_ = Symbol[]
407+
for type_ in typeList
408+
union!(thelist_, listfnc(type_))
409+
end
410+
@show thelist_
411+
intersect( thelist, thelist_ )
409412
end
410-
end
411413

412-
# return the list of symbols
413-
return dijkpath
414-
end
414+
#
415+
duplicate = regexVariables !== nothing ||
416+
regexFactors !== nothing ||
417+
0 < length(tagsVariables) ||
418+
0 < length(tagsFactors) ||
419+
typeVariables !== nothing ||
420+
typeFactors !== nothing ||
421+
initialized !== nothing ||
422+
solvable != 0
423+
#
424+
dfg_ = if duplicate
425+
# use copy if filter is being applied
426+
varList = ls(dfg, regexVariables, tags=tagsVariables, solvable=solvable)
427+
fctList = lsf(dfg, regexFactors, tags=tagsFactors, solvable=solvable)
428+
varList = typeVariables !== nothing ? _filterTypeList(varList, typeVariables) : varList
429+
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
436+
deepcopyGraph(typeof(dfg), dfg, varList, fctList)
437+
else
438+
# no filter can be used directly
439+
dfg
440+
end
441+
442+
# 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
447+
frI = dfg_.g.labels[from]
448+
toI = dfg_.g.labels[to]
449+
450+
# get shortest path from graph provider
451+
path_state = LightGraphs.dijkstra_shortest_paths( dfg_.g.graph, [frI;] )
452+
path = LightGraphs.enumerate_paths( path_state, toI )
453+
dijkpath = map( x->dfg_.g.labels[x], path )
454+
455+
# return the list of symbols
456+
return dijkpath
457+
end
458+

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: 27 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 == ""
@@ -1085,7 +1085,28 @@ function findFactorsBetweenNaive( dfg::AbstractDFG,
10851085
return fctlist
10861086
end
10871087

1088+
"""
1089+
$SIGNATURES
1090+
Return (::Bool,::Vector{TypeName}) of types between two nodes in the factor graph
1091+
1092+
DevNotes
1093+
- Only works on LigthDFG at the moment.
1094+
1095+
Related
10881096
1097+
[`LightDFG.findShortestPathDijkstra`](@ref)
1098+
"""
1099+
function isPathFactorsHomogeneous(dfg::AbstractDFG, from::Symbol, to::Symbol)
1100+
# FIXME, must consider all paths, not just shortest...
1101+
pth = intersect(findShortestPathDijkstra(dfg, from, to), lsf(dfg))
1102+
types = getFactorType.(dfg, pth) .|> typeof .|> x->(x).name
1103+
utyp = unique(types)
1104+
(length(utyp) == 1), utyp
1105+
end
1106+
1107+
function existsPathOfFactorsType(dfg::AbstractDFG, from::Symbol, to::Symbol, ftype::FunctorInferenceType)
1108+
error("WIP")
1109+
end
10891110

10901111
##==============================================================================
10911112
## Subgraphs and Neighborhoods

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)