Skip to content

Commit 1371f18

Browse files
authored
Merge pull request #19 from JuliaRobotics/dev/df/dfgintegration
few updates to Symbol
2 parents aaa6fd0 + 04e0705 commit 1371f18

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
88
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
99
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1010
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
11+
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1112
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
1213

1314
[compat]

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ using DocStringExtensions
55
using Requires
66
using Dates
77
using Distributions
8+
using Reexport
89

910
# Entities
1011
include("entities/AbstractTypes.jl")

src/entities/DFGFactor.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
$(TYPEDEF)
33
"""
44
mutable struct GenericFunctionNodeData{T, S}
5-
fncargvID::Array{Int,1}
5+
fncargvID::Vector{Symbol}
66
eliminated::Bool
77
potentialused::Bool
88
edgeIDs::Array{Int,1}
@@ -27,8 +27,9 @@ mutable struct DFGFactor{T, S} <: DFGNode
2727
ready::Int
2828
backendset::Int
2929
_internalId::Int64
30-
DFGFactor{T, S}(label::Symbol) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, 0)
31-
DFGFactor{T, S}(label::Symbol, _internalId::Int64) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, _internalId)
30+
_variableOrderSymbols::Vector{Symbol}
31+
DFGFactor{T, S}(label::Symbol) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, 0, Symbol[])
32+
DFGFactor{T, S}(label::Symbol, _internalId::Int64) where {T, S} = new{T, S}(label, Symbol[], GenericFunctionNodeData{T, S}(), 0, 0, _internalId, Symbol[])
3233
end
3334

3435
# const FunctionNodeData{T} = GenericFunctionNodeData{T, Symbol}

src/entities/DFGVariable.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ mutable struct VariableNodeData
88
dimIDs::Array{Int,1} # Likely deprecate
99
dims::Int
1010
eliminated::Bool
11-
BayesNetVertID::Union{Nothing, Symbol}
11+
BayesNetVertID::Union{Nothing, Symbol} # TODO Drop union type from here
1212
separator::Array{Symbol,1}
1313
groundtruth::Union{Nothing, Dict{ Tuple{Symbol, Vector{Float64}} } } # not packed yet
1414
softtype

src/services/GraphsDFG.jl

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,4 @@
1-
module GraphsJl
2-
31
using Graphs
4-
using Requires
5-
using DocStringExtensions
6-
using DistributedFactorGraphs
72

83
"""
94
$(SIGNATURES)
@@ -118,6 +113,7 @@ function addFactor!(dfg::GraphsDFG, variables::Vector{DFGVariable}, factor::DFGF
118113
end
119114
dfg.nodeCounter += 1
120115
factor._internalId = dfg.nodeCounter
116+
factor._variableOrderSymbols = map(v->v.label, variables)
121117
fNode = GraphsNode(dfg.nodeCounter, factor)
122118
f = Graphs.add_vertex!(dfg.g, fNode)
123119
# Add index
@@ -296,6 +292,9 @@ function lsf(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector
296292
end
297293
return factors
298294
end
295+
function lsf(dfg::GraphsDFG, label::Symbol)::Vector{Symbol}
296+
return GraphsJl.getNeighbors(dfg, label)
297+
end
299298

300299
# Alias
301300
"""
@@ -340,6 +339,11 @@ function getNeighbors(dfg::GraphsDFG, node::T; ready::Union{Nothing, Int}=nothin
340339
# Additional filtering
341340
neighbors = ready != nothing ? filter(v -> v.ready == ready, neighbors) : neighbors
342341
neighbors = backendset != nothing ? filter(v -> v.backendset == backendset, neighbors) : neighbors
342+
# Variable sorting (order is important)
343+
if node isa DFGFactor
344+
order = intersect(node._variableOrderSymbols, map(v->v.dfgNode.label, neighbors))
345+
return order
346+
end
343347

344348
return map(n -> n.dfgNode.label, neighbors)
345349
end
@@ -356,6 +360,12 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=
356360
# Additional filtering
357361
neighbors = ready != nothing ? filter(v -> v.ready == ready, neighbors) : neighbors
358362
neighbors = backendset != nothing ? filter(v -> v.backendset == backendset, neighbors) : neighbors
363+
# Variable sorting when using a factor (function order is important)
364+
if vert.dfgNode isa DFGFactor
365+
vert.dfgNode._variableOrderSymbols
366+
order = intersect(vert.dfgNode._variableOrderSymbols, map(v->v.dfgNode.label, neighbors))
367+
return order
368+
end
359369

360370
return map(n -> n.dfgNode.label, neighbors)
361371
end
@@ -501,8 +511,13 @@ end
501511
$(SIGNATURES)
502512
Produces a dot file of the graph for visualization.
503513
Download XDot to see the data
514+
515+
Note
516+
- Default location "/tmp/dfg.dot" -- MIGHT BE REMOVED
517+
- Can be viewed with the `xdot` system application.
518+
- Based on graphviz.org
504519
"""
505-
function toDotFile(dfg::GraphsDFG, fileName::String)::Nothing
520+
function toDotFile(dfg::GraphsDFG, fileName::String="/tmp/dfg.dot")::Nothing
506521
open(fileName, "w") do fid
507522
write(fid,Graphs.to_dot(dfg.g))
508523
end
@@ -535,5 +550,3 @@ function __init__()
535550
end
536551
end
537552
end
538-
539-
end

test/interfaceTests.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,12 @@ map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol(
104104

105105
@testset "Getting Neighbors" begin
106106
global dfg,verts
107+
# Trivial test to validate that intersect([], []) returns order of first parameter
108+
@test intersect([:x3, :x2, :x1], [:x1, :x2]) == [:x2, :x1]
107109
# Get neighbors tests
108110
@test getNeighbors(dfg, verts[1]) == [:x1x2f1]
109111
neighbors = getNeighbors(dfg, getFactor(dfg, :x1x2f1))
110-
@test all([v in [:x1, :x2] for v in neighbors])
112+
@test neighbors == [:x1, :x2]
111113
# Testing aliases
112114
@test getNeighbors(dfg, getFactor(dfg, :x1x2f1)) == ls(dfg, getFactor(dfg, :x1x2f1))
113115
@test getNeighbors(dfg, :x1x2f1) == ls(dfg, :x1x2f1)

0 commit comments

Comments
 (0)