Skip to content

Commit 9afd7a3

Browse files
authored
Merge pull request #120 from JuliaRobotics/feature/summaryfunction
Summary functions
2 parents 6a4278a + f38ffd7 commit 9afd7a3

25 files changed

+686
-364
lines changed

Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
1313
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1414
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1515
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
16-
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1716
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1817
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1918
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
@@ -29,6 +28,8 @@ julia = "0.7, 1"
2928

3029
[extras]
3130
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
31+
GraphPlot = "a2cc645c-3eea-5389-862e-a155d0052231"
32+
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
3233

3334
[targets]
34-
test = ["Test"]
35+
test = ["Test", "GraphPlot", "Neo4j"]

docs/src/func_ref.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,12 @@ getSubgraphAroundNode
5858
getSubgraph
5959
```
6060

61+
### Summaries
62+
```@docs
63+
getSummary
64+
getSummaryGraph
65+
```
66+
6167
### Visualization and Plotting
6268
```@docs
6369
toDot

src/DistributedFactorGraphs.jl

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,18 @@ using LinearAlgebra
1111
using SparseArrays
1212

1313
# Entities
14-
include("entities/AbstractTypes.jl")
14+
include("entities/AbstractDFG.jl")
1515
include("entities/DFGFactor.jl")
1616
include("entities/DFGVariable.jl")
17+
include("entities/AbstractDFGSummary.jl")
1718

1819
export AbstractDFG
1920
export AbstractParams, NoSolverParams
20-
export DFGNode
21-
22-
export DFGFactor
21+
export DFGNode, DFGVariable, DFGFactor
2322
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
24-
2523
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
26-
27-
export DFGVariable
28-
export label, timestamp, tags, estimates, estimate, solverData, getData, solverDataDict, internalId, smallData, bigData
29-
export setSolverData
30-
export label, data, id
24+
export label, timestamp, tags, estimates, estimate, data, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
25+
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
3126

3227
# Services/AbstractDFG Exports
3328
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
@@ -45,9 +40,13 @@ export getAdjacencyMatrixSparse
4540
# File import and export
4641
export saveDFG, loadDFG
4742

43+
# Summary functions
44+
export getSummary, getSummaryGraph
45+
4846
# Common includes
4947
include("services/AbstractDFG.jl")
5048
include("services/DFGVariable.jl")
49+
include("services/DFGFactor.jl")
5150

5251
# Include the Graphs.jl API.
5352
include("GraphsDFG/GraphsDFG.jl")

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 1 addition & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -366,68 +366,10 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
366366
return addToDFG
367367
end
368368

369-
"""
370-
$(SIGNATURES)
371-
Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}}.
372-
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
373-
The first row and first column are factor and variable headings respectively.
374-
"""
375-
function getAdjacencyMatrix(dfg::GraphsDFG)::Matrix{Union{Nothing, Symbol}}
376-
varLabels = sort(map(v->v.label, getVariables(dfg)))
377-
factLabels = sort(map(f->f.label, getFactors(dfg)))
378-
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
379-
380-
adjMat = Matrix{Union{Nothing, Symbol}}(nothing, length(factLabels)+1, length(varLabels)+1)
381-
# Set row/col headings
382-
adjMat[2:end, 1] = factLabels
383-
adjMat[1, 2:end] = varLabels
384-
for (fIndex, factLabel) in enumerate(factLabels)
385-
factVars = getNeighbors(dfg, getFactor(dfg, factLabel))
386-
map(vLabel -> adjMat[fIndex+1,vDict[vLabel]] = factLabel, factVars)
387-
end
388-
return adjMat
389-
end
390-
391-
function getAdjacencyMatrixSparse(dfg::GraphsDFG)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
392-
varLabels = map(v->v.label, getVariables(dfg))
393-
factLabels = map(f->f.label, getFactors(dfg))
394-
395-
vDict = Dict(varLabels .=> [1:length(varLabels)...])
396-
397-
adjMat = spzeros(Int, length(factLabels), length(varLabels))
398-
399-
for (fIndex, factLabel) in enumerate(factLabels)
400-
factVars = getNeighbors(dfg, getFactor(dfg, factLabel))
401-
map(vLabel -> adjMat[fIndex,vDict[vLabel]] = 1, factVars)
402-
end
403-
return adjMat, varLabels, factLabels
404-
end
405-
406369
"""
407370
$(SIGNATURES)
408371
Produces a dot-format of the graph for visualization.
409372
"""
410373
function toDot(dfg::GraphsDFG)::String
411-
m = PipeBuffer()
412-
write(m,Graphs.to_dot(dfg.g))
413-
data = take!(m)
414-
close(m)
415-
return String(data)
416-
end
417-
418-
"""
419-
$(SIGNATURES)
420-
Produces a dot file of the graph for visualization.
421-
Download XDot to see the data
422-
423-
Note
424-
- Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
425-
- Can be viewed with the `xdot` system application.
426-
- Based on graphviz.org
427-
"""
428-
function toDotFile(dfg::GraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
429-
open(fileName, "w") do fid
430-
write(fid,Graphs.to_dot(dfg.g))
431-
end
432-
return nothing
374+
return Graphs.to_dot(dfg.g)
433375
end

src/LightDFG/FactorGraphs/FactorGraphs.jl

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,22 @@ export
3131
filter_vertices,
3232
reverse
3333

34-
import DistributedFactorGraphs: DFGNode
35-
const AbstractNodeType = DFGNode
34+
# import DistributedFactorGraphs: DFGNode
35+
# const AbstractNodeType = DFGNode
36+
import DistributedFactorGraphs: AbstractDFGVariable, AbstractDFGFactor
37+
const AbstractVariableType = AbstractDFGVariable
38+
const AbstractFactorType = AbstractDFGFactor
3639

3740
include("BiMaps.jl")
3841

39-
struct FactorGraph{T <: Integer,V <: AbstractNodeType, F <: AbstractNodeType} <: AbstractGraph{T}
42+
struct FactorGraph{T <: Integer,V <: AbstractVariableType, F <: AbstractFactorType} <: AbstractGraph{T}
4043
graph::SimpleGraph{T}
4144
labels::BiDictMap{T}
4245
variables::Dict{Symbol,V}
4346
factors::Dict{Symbol,F}
4447
end
4548

46-
function FactorGraph{T, V, F}(nv::Int=100, nf::Int=100) where {T <: Integer, V <: AbstractNodeType, F <: AbstractNodeType}
49+
function FactorGraph{T, V, F}(nv::Int=100, nf::Int=100) where {T <: Integer, V <: AbstractVariableType, F <: AbstractFactorType}
4750
fadjlist = Vector{Vector{T}}()
4851
sizehint!(fadjlist, nv + nf)
4952
g = SimpleGraph{T}(0, fadjlist)
@@ -55,10 +58,10 @@ function FactorGraph{T, V, F}(nv::Int=100, nf::Int=100) where {T <: Integer, V <
5558
return FactorGraph{T, V, F}(g, labels, variables, factors)
5659
end
5760

58-
# fg = FactorGraph{Int, AbstractNodeType, AbstractNodeType}()
61+
# fg = FactorGraph{Int, AbstractVariableType, AbstractFactorType}()
5962

60-
FactorGraph() = FactorGraph{Int, AbstractNodeType, AbstractNodeType}()
61-
FactorGraph{V,F}() where {V <: AbstractNodeType, F <: AbstractNodeType} = FactorGraph{Int, V, F}()
63+
FactorGraph() = FactorGraph{Int, AbstractVariableType, AbstractFactorType}()
64+
FactorGraph{V,F}() where {V <: AbstractVariableType, F <: AbstractFactorType} = FactorGraph{Int, V, F}()
6265

6366

6467
function show(io::IO, g::FactorGraph)

src/LightDFG/LightDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module LightDFGs
33
using LightGraphs
44
using DocStringExtensions
55

6-
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
6+
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractDFGVariable, AbstractDFGFactor, AbstractDFGSummary, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
77

8-
# import DFG functions to exstend
8+
# import DFG functions to extend
99
import ...DistributedFactorGraphs: setSolverParams,
1010
getInnerGraph,
1111
getFactor,

src/LightDFG/entities/LightDFG.jl

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,49 @@
11

2-
mutable struct LightDFG{T <: AbstractParams, V <: DFGNode, F <:DFGNode} <: AbstractDFG
2+
"""
3+
$(SIGNATURES)
4+
5+
An in-memory DistributedFactorGraph based on LightGraphs.jl with parameters:
6+
- T: Solver parameters (defaults to `NoSolverParams()`)
7+
- V: Variable type
8+
- F: Factor type
9+
"""
10+
mutable struct LightDFG{T <: AbstractParams, V <: AbstractDFGVariable, F <:AbstractDFGFactor} <: AbstractDFG
311
g::FactorGraph{Int, V, F}
412
description::String
513
userId::String
614
robotId::String
715
sessionId::String
8-
#NOTE does not exist
9-
# nodeCounter::Int64
10-
#NOTE does not exist
11-
# labelDict::Dict{Symbol, Int64}
1216
addHistory::Vector{Symbol} #TODO: Discuss more - is this an audit trail?
1317
solverParams::T # Solver parameters
1418
end
1519

16-
#TODO? do we not want props such as userId, robotId, sessionId, etc...
20+
"""
21+
$(SIGNATURES)
22+
23+
Create an in-memory LightDFG with the following parameters:
24+
- T: Solver parameters (defaults to `NoSolverParams()`)
25+
- V: Variable type
26+
- F: Factor type
27+
"""
1728
function LightDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
1829
description::String="LightGraphs.jl implementation",
1930
userId::String="User ID",
2031
robotId::String="Robot ID",
2132
sessionId::String="Session ID",
22-
params::T=NoSolverParams()) where {T <: AbstractParams, V <:DFGNode, F<:DFGNode}
33+
params::T=NoSolverParams()) where {T <: AbstractParams, V <:AbstractDFGVariable, F<:AbstractDFGFactor}
2334

2435
LightDFG{T,V,F}(g, description, userId, robotId, sessionId, Symbol[], params)
2536
end
2637

2738
# LightDFG{T}(; kwargs...) where T <: AbstractParams = LightDFG{T,DFGVariable,DFGFactor}(;kwargs...)
39+
"""
40+
$(SIGNATURES)
2841
42+
Create an in-memory LightDFG with the following parameters:
43+
- T: Solver parameters (defaults to `NoSolverParams()`)
44+
- V: Variable type
45+
- F: Factor type
46+
"""
2947
LightDFG{T}(g::FactorGraph{Int,DFGVariable,DFGFactor}=FactorGraph{Int,DFGVariable,DFGFactor}(); kwargs...) where T <: AbstractParams = LightDFG{T,DFGVariable,DFGFactor}(g; kwargs...)
3048

3149
Base.propertynames(x::LightDFG, private::Bool=false) =

0 commit comments

Comments
 (0)