Skip to content

Commit 4111823

Browse files
committed
Tests working, need a decent review
1 parent 2f46e4a commit 4111823

File tree

13 files changed

+191
-259
lines changed

13 files changed

+191
-259
lines changed

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -366,83 +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
433-
end
434-
435-
function getSummary(dfg::GraphsDFG)::AbstractDFGSummary
436-
vars = map(v -> convert(DFGVariableSummary, v), getVariables(dfg))
437-
facts = map(f -> convert(DFGFactorSummary, f), getFactors(dfg))
438-
return AbstractDFGSummary(
439-
Dict(map(v->v.label, vars) .=> vars),
440-
Dict(map(f->f.label, facts) .=> facts),
441-
"userId",
442-
"robotId",
443-
"sessionId")
444-
end
445-
446-
function getSummaryGraph(dfg::GraphsDFG)
447-
error("getSummaryGraph not implemented for $(typeof(dfg))")
374+
return Graphs.to_dot(dfg.g)
448375
end

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: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,30 @@
11

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+
"""
210
mutable struct LightDFG{T <: AbstractParams, V <: DFGNode, F <:DFGNode} <: 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",
@@ -25,7 +36,14 @@ function LightDFG{T,V,F}(g::FactorGraph{Int,V,F}=FactorGraph{Int,V,F}();
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)