Skip to content

Commit 851fae2

Browse files
committed
Merge branch 'master' into 4Q19/poc/v0_6
2 parents 6d49afc + ed9fb94 commit 851fae2

File tree

8 files changed

+120
-70
lines changed

8 files changed

+120
-70
lines changed

src/DFGPlots/DFGPlots.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
8686
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
8787
"""
8888
function dfgplot(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
89-
ldfg = LightDFG{AbstractParams}()
89+
# TODO implement convert functions
90+
ldfg = LightDFG{NoSolverParams}()
9091
DistributedFactorGraphs._copyIntoGraph!(dfg, ldfg, union(getVariableIds(dfg), getFactorIds(dfg)), true, copyGraphMetadata=false)
9192
dfgplot(ldfg, p)
9293
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export SkeletonDFGVariable, SkeletonDFGFactor
3636
export timestamp # DEPRECATED
3737
export label, getTimestamp, setTimestamp!, tags, setTags!, data, softtype, solverData, getData, solverDataDict, setSolverData, setSolverData!, internalId, smallData, setSmallData!, bigData
3838
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
39+
export getNeighborhood, getSubgraph, getSubgraphAroundNode
3940

4041
# Define variable levels
4142
const VariableDataLevel0 = Union{DFGVariable, DFGVariableSummary, SkeletonDFGVariable}

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 35 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -258,33 +258,41 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int=0)::Vector{Sy
258258
return map(n -> n.dfgNode.label, neighbors)
259259
end
260260

261-
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}(); solvable::Int=0)::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
262-
if !haskey(dfg.labelDict, node.label)
263-
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
264-
end
265-
266-
# Build a list of all unique neighbors inside 'distance'
267-
neighborList = Dict{Symbol, Any}()
268-
push!(neighborList, node.label => dfg.g.vertices[dfg.labelDict[node.label]])
269-
curList = Dict{Symbol, Any}(node.label => dfg.g.vertices[dfg.labelDict[node.label]])
270-
for dist in 1:distance
271-
newNeighbors = Dict{Symbol, Any}()
272-
for (key, node) in curList
273-
neighbors = in_neighbors(node, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
274-
for neighbor in neighbors
275-
if !haskey(neighborList, neighbor.dfgNode.label) && (isSolvable(neighbor.dfgNode) >= solvable)
276-
push!(neighborList, neighbor.dfgNode.label => neighbor)
277-
push!(newNeighbors, neighbor.dfgNode.label => neighbor)
278-
end
279-
end
280-
end
281-
curList = newNeighbors
282-
end
283-
284-
# Copy the section of graph we want
285-
_copyIntoGraph!(dfg, addToDFG, collect(keys(neighborList)), includeOrphanFactors)
286-
return addToDFG
287-
end
261+
#NOTE Replaced by abstract function in services/AbstractDFG.jl
262+
# """
263+
# $(SIGNATURES)
264+
# Retrieve a deep subgraph copy around a given variable or factor.
265+
# Optionally provide a distance to specify the number of edges should be followed.
266+
# Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
267+
# Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
268+
# """
269+
# function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}(); solvable::Int=0)::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
270+
# if !haskey(dfg.labelDict, node.label)
271+
# error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
272+
# end
273+
#
274+
# # Build a list of all unique neighbors inside 'distance'
275+
# neighborList = Dict{Symbol, Any}()
276+
# push!(neighborList, node.label => dfg.g.vertices[dfg.labelDict[node.label]])
277+
# curList = Dict{Symbol, Any}(node.label => dfg.g.vertices[dfg.labelDict[node.label]])
278+
# for dist in 1:distance
279+
# newNeighbors = Dict{Symbol, Any}()
280+
# for (key, node) in curList
281+
# neighbors = in_neighbors(node, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
282+
# for neighbor in neighbors
283+
# if !haskey(neighborList, neighbor.dfgNode.label) && (isSolvable(neighbor.dfgNode) >= solvable)
284+
# push!(neighborList, neighbor.dfgNode.label => neighbor)
285+
# push!(newNeighbors, neighbor.dfgNode.label => neighbor)
286+
# end
287+
# end
288+
# end
289+
# curList = newNeighbors
290+
# end
291+
#
292+
# # Copy the section of graph we want
293+
# _copyIntoGraph!(dfg, addToDFG, collect(keys(neighborList)), includeOrphanFactors)
294+
# return addToDFG
295+
# end
288296

289297
"""
290298
$(SIGNATURES)

src/LightDFG/entities/LightDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function LightDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
3636
userData::Dict{Symbol, String} = Dict{Symbol, String}(),
3737
robotData::Dict{Symbol, String} = Dict{Symbol, String}(),
3838
sessionData::Dict{Symbol, String} = Dict{Symbol, String}(),
39-
params::T=NoSolverParams()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
39+
params::T=T()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
4040

4141
LightDFG{T,V,F}(g, description, userId, robotId, sessionId, userData, robotData, sessionData, Symbol[], params)
4242
end

src/attic/SymbolDFG/services/SymbolDFG.jl

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -360,44 +360,44 @@ function _copyIntoGraph!(sourceDFG::SymbolDFG, destDFG::SymbolDFG, labels::Vecto
360360
return nothing
361361
end
362362

363-
364-
"""
365-
$(SIGNATURES)
366-
Retrieve a deep subgraph copy around a given variable or factor.
367-
Optionally provide a distance to specify the number of edges should be followed.
368-
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
369-
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
370-
"""
371-
function getSubgraphAroundNode(dfg::SymbolDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::SymbolDFG=SymbolDFG{AbstractParams}(); solvable::Int=0)::SymbolDFG
372-
if !exists(dfg,node.label)
373-
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
374-
end
375-
376-
nodelabel = node.label
377-
# Build a list of all unique neighbors inside 'distance'
378-
neighborList = Symbol[nodelabel]
379-
380-
curList = Symbol[nodelabel]
381-
382-
for dist in 1:distance
383-
newNeighbors = Symbol[]
384-
for cl in curList
385-
neighbors = outneighbors(dfg.g, cl)
386-
for neighbor in neighbors
387-
if !(neighbor in neighborList) && _isSolvable(dfg, neighbor, solvable)
388-
push!(neighborList, neighbor)
389-
push!(newNeighbors, neighbor)
390-
end
391-
end
392-
end
393-
curList = newNeighbors
394-
end
395-
396-
397-
# _copyIntoGraph!(dfg, addToDFG, map(n->get_prop(dfg.g, n, :label), ns), includeOrphanFactors)
398-
_copyIntoGraph!(dfg, addToDFG, neighborList, includeOrphanFactors)
399-
return addToDFG
400-
end
363+
# moved to abstract
364+
# """
365+
# $(SIGNATURES)
366+
# Retrieve a deep subgraph copy around a given variable or factor.
367+
# Optionally provide a distance to specify the number of edges should be followed.
368+
# Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
369+
# Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
370+
# """
371+
# function getSubgraphAroundNode(dfg::SymbolDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::SymbolDFG=SymbolDFG{AbstractParams}(); solvable::Int=0)::SymbolDFG
372+
# if !exists(dfg,node.label)
373+
# error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
374+
# end
375+
#
376+
# nodelabel = node.label
377+
# # Build a list of all unique neighbors inside 'distance'
378+
# neighborList = Symbol[nodelabel]
379+
#
380+
# curList = Symbol[nodelabel]
381+
#
382+
# for dist in 1:distance
383+
# newNeighbors = Symbol[]
384+
# for cl in curList
385+
# neighbors = outneighbors(dfg.g, cl)
386+
# for neighbor in neighbors
387+
# if !(neighbor in neighborList) && _isSolvable(dfg, neighbor, solvable)
388+
# push!(neighborList, neighbor)
389+
# push!(newNeighbors, neighbor)
390+
# end
391+
# end
392+
# end
393+
# curList = newNeighbors
394+
# end
395+
#
396+
#
397+
# # _copyIntoGraph!(dfg, addToDFG, map(n->get_prop(dfg.g, n, :label), ns), includeOrphanFactors)
398+
# _copyIntoGraph!(dfg, addToDFG, neighborList, includeOrphanFactors)
399+
# return addToDFG
400+
# end
401401

402402

403403
"""

src/needsahome.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ function buildSubgraphFromLabels!(dfg::G,
2525
syms::Vector{Symbol};
2626
subfg::AbstractDFG=(G <: InMemoryDFGTypes ? G : GraphsDFG)(params=getSolverParams(dfg)),
2727
solvable::Int=0,
28-
allowedFactors::Union{Nothing, Vector{Symbol}}=nothing )::G where G <: AbstractDFG
28+
allowedFactors::Union{Nothing, Vector{Symbol}}=nothing )::AbstractDFG where G <: AbstractDFG
2929
#
3030

3131
# add a little too many variables (since we need the factors)

src/services/AbstractDFG.jl

Lines changed: 38 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,6 +361,30 @@ end
361361

362362
# TODO: NEED TO FIGURE OUT SIGNATURE FOR DEFAULT ARGS
363363

364+
365+
# TODO export, test and overwrite in LightGraphs and CloudGraphsDFG
366+
"""
367+
$(SIGNATURES)
368+
Build a list of all unique neighbors inside 'distance'
369+
"""
370+
function getNeighborhood(dfg::AbstractDFG, label::Symbol, distance::Int)::Vector{Symbol}
371+
neighborList = Set{Symbol}([label])
372+
curList = Set{Symbol}([label])
373+
374+
for dist in 1:distance
375+
newNeighbors = Set{Symbol}()
376+
for node in curList
377+
neighbors = getNeighbors(dfg, node)
378+
for neighbor in neighbors
379+
push!(neighborList, neighbor)
380+
push!(newNeighbors, neighbor)
381+
end
382+
end
383+
curList = newNeighbors
384+
end
385+
return collect(neighborList)
386+
end
387+
364388
"""
365389
$(SIGNATURES)
366390
Retrieve a deep subgraph copy around a given variable or factor.
@@ -369,8 +393,20 @@ Optionally provide an existing subgraph addToDFG, the extracted nodes will be co
369393
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
370394
Note: Always returns the node at the center, but filters around it if solvable is set.
371395
"""
372-
function getSubgraphAroundNode(dfg::G, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::H=_getDuplicatedEmptyDFG(dfg); solvable::Int=0)::G where {G <: AbstractDFG, H <: AbstractDFG, P <: AbstractParams, T <: DFGNode}
373-
error("getSubgraphAroundNode not implemented for $(typeof(dfg))")
396+
function getSubgraphAroundNode(dfg::AbstractDFG, node::DFGNode, distance::Int=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg); solvable::Int=0)::AbstractDFG
397+
398+
if !exists(dfg, node.label)
399+
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
400+
end
401+
402+
neighbors = getNeighborhood(dfg, node.label, distance)
403+
404+
# for some reason: always returns the node at the center with || (nlbl == node.label)
405+
solvable != 0 && filter!(nlbl -> (getSolvable(dfg, nlbl) >= solvable) || (nlbl == node.label), neighbors)
406+
407+
# Copy the section of graph we want
408+
_copyIntoGraph!(dfg, addToDFG, neighbors, includeOrphanFactors)
409+
return addToDFG
374410
end
375411

376412
"""

test/interfaceTests.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,10 @@ end
416416
# Filter - always returns the node you start at but filters around that.
417417
dfgSubgraph = getSubgraphAroundNode(dfg, getFactor(dfg, :x7x8f1), 1, true, solvable=1)
418418
@test symdiff([:x7x8f1, :x7], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
419+
# Test for distance = 2, should return orphans
420+
#:x7x8f1 is not solvable
421+
dfgSubgraph = getSubgraphAroundNode(dfg, getVariable(dfg, :x8), 2, true, solvable=1)
422+
@test symdiff([:x8, :x7], [ls(dfgSubgraph)..., lsf(dfgSubgraph)...]) == []
419423

420424
# DFG issue #95 - confirming that getSubgraphAroundNode retains order
421425
# REF: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/95

0 commit comments

Comments
 (0)