Skip to content

Commit 5e9ecbf

Browse files
committed
add isPathFactorsHomogeneous, better path
1 parent 4d2238f commit 5e9ecbf

File tree

3 files changed

+31
-26
lines changed

3 files changed

+31
-26
lines changed

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: 16 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -374,41 +374,31 @@ using IncrementalInference
374374
fg = generateCanonicalFG_Kaess()
375375
376376
@show path = findShortestPathDijkstra(fg, :x1, :x3)
377-
@show isVariable.(path)
378-
@show isFactor.(path)
377+
@show isVariable.(fg, path)
378+
@show isFactor.(fg, path)
379379
```
380380
381381
DevNotes
382382
- # TODO expand to other AbstractDFG entities.
383383
384384
Related
385385
386-
[findFactorsBetweenNaive](@ref), `LightGraphs.dijkstra_shortest_paths`
386+
[`findFactorsBetweenNaive`](@ref), `LightGraphs.dijkstra_shortest_paths`
387387
"""
388388
function findShortestPathDijkstra( dfg::LightDFG,
389389
from::Symbol,
390390
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])
409-
end
410-
end
391+
#
392+
# LightDFG internally uses Integers
393+
frI = dfg.g.labels[from]
394+
toI = dfg.g.labels[to]
395+
396+
# 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)
400+
401+
# return the list of symbols
402+
return dijkpath
403+
end
411404

412-
# return the list of symbols
413-
return dijkpath
414-
end

src/services/AbstractDFG.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,6 +1085,20 @@ 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+
Related
1093+
1094+
[`LightDFG.findShortestPathDijkstra`](@ref)
1095+
"""
1096+
function isPathFactorsHomogeneous(dfg::AbstractDFG, from::Symbol, to::Symbol)
1097+
pth = intersect(findShortestPathDijkstra(dfg, from, to), lsf(dfg))
1098+
types = getFactorType.(dfg, pth) .|> typeof .|> x->(x).name
1099+
utyp = unique(types)
1100+
(length(utyp) == 1), utyp
1101+
end
10881102

10891103

10901104
##==============================================================================

0 commit comments

Comments
 (0)