Skip to content

Commit 3795259

Browse files
committed
Adding missing function to GraphsJl driver
1 parent 94a7aa5 commit 3795259

File tree

2 files changed

+56
-27
lines changed

2 files changed

+56
-27
lines changed

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,15 @@ function addFactor!(dfg::GraphsDFG, variables::Vector{DFGVariable}, factor::DFGF
8989
return true
9090
end
9191

92+
"""
93+
$(SIGNATURES)
94+
Add a DFGFactor to a DFG.
95+
"""
96+
function addFactor!(dfg::GraphsDFG, variableIds::Vector{Symbol}, factor::DFGFactor)::Bool
97+
variables = map(vId -> getVariable(dfg, vId), variableIds)
98+
return addFactor!(dfg, variables, factor)
99+
end
100+
92101
"""
93102
$(SIGNATURES)
94103
Get a DFGVariable from a DFG using its underlying integer ID.

test/HexagonalCloud.jl

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,74 @@
1-
# add more julia processes
2-
using Distributed
3-
nprocs() < 4 ? addprocs(5-nprocs()) : nothing
4-
5-
# tell Julia that you want to use these modules/namespaces
1+
using Revise
62
using Neo4j # So that DFG initializes the database driver.
73
using RoME
84
using DistributedFactorGraphs
9-
## Inter-operating visualization packages for Caesar/RoME/IncrementalInference exist
10-
# using RoMEPlotting
11-
5+
using Test
126

137
# start with an empty factor graph object
148
# fg = initfg()
15-
global cgDFG = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
9+
cloudFg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
1610
"testUser", "testRobot", "testSession",
1711
nothing,
1812
nothing,
1913
IncrementalInference.decodePackedType,
20-
solverParams=SolverParams(0, nothing, nothing, false, 0, false))
21-
fg = cgDFG
22-
clearSession!!(fg)
23-
# fg = initfg()
14+
IncrementalInference.rebuildFactorMetadata!,
15+
solverParams=SolverParams())
16+
clearSession!!(cloudFg)
17+
# cloudFg = initfg()
2418

2519
# Add the first pose :x0
26-
addVariable!(fg, :x0, Pose2)
20+
x0 = addVariable!(cloudFg, :x0, Pose2)
21+
IncrementalInference.compareVariable(x0, getVariable(cloudFg, :x0))
2722

2823
# Add at a fixed location PriorPose2 to pin :x0 to a starting location (10,10, pi/4)
29-
prior = addFactor!(fg, [:x0], PriorPose2( MvNormal([10; 10; pi/6.0], Matrix(Diagonal([0.1;0.1;0.05].^2))) ) )
30-
31-
# Drive around in a hexagon
24+
prior = addFactor!(cloudFg, [:x0], PriorPose2( MvNormal([10; 10; 1.0/8.0], Matrix(Diagonal([0.1;0.1;0.05].^2))) ) )
25+
# retPrior = getFactor(cloudFg, :x0f1)
26+
# Do the check
27+
# IncrementalInference.compareFactor(prior, retPrior)
28+
# Testing
29+
30+
# retPrior.data.fnc.cpt = prior.data.fnc.cpt
31+
# # This one
32+
# prior.data.fnc.cpt[1].factormetadata
33+
# deserialized: Any[Pose2(3, String[], (:Euclid, :Euclid, :Circular))]
34+
# vs.
35+
# original: Pose2[Pose2(3, String[], (:Euclid, :Euclid, :Circular))]
36+
37+
# Drive around in a hexagon in the cloud
3238
for i in 0:5
3339
psym = Symbol("x$i")
3440
nsym = Symbol("x$(i+1)")
35-
addVariable!(fg, nsym, Pose2)
41+
addVariable!(cloudFg, nsym, Pose2)
3642
pp = Pose2Pose2(MvNormal([10.0;0;pi/3], Matrix(Diagonal([0.1;0.1;0.1].^2))))
37-
addFactor!(fg, [psym;nsym], pp )
43+
addFactor!(cloudFg, [psym;nsym], pp )
3844
end
3945

40-
retPrior = getFactor(fg, :x0f1)
41-
IncrementalInference.compareFactor(prior, retPrior)
46+
# Right, let's copy it into local memory for solving...
47+
localFg = GraphsDFG{SolverParams}(params=SolverParams())
48+
DistributedFactorGraphs._copyIntoGraph!(cloudFg, localFg, union(getVariableIds(fg), getFactorIds(fg)), true)
49+
# Some checks
50+
@test getVariableIds(localFg) == getVariableIds(cloudFg)
51+
@test getFactorIds(localFg) == getFactorIds(cloudFg)
52+
@test isFullyConnected(localFg)
53+
# Show it
54+
toDotFile(localFg, "/tmp/localfg.dot")
55+
56+
# Alrighty! At this point, we should be able to solve locally...
57+
# perform inference, and remember first runs are slower owing to Julia's just-in-time compiling
58+
batchSolve!(localFg, drawpdf=true, show=true)
59+
# Erm, whut? Error = mcmcIterationIDs -- unaccounted variables
4260

43-
# for factId in getFactorIds(fg)
44-
# @show getFactor(fg, factId)
45-
# end
61+
#### WIP and general debugging
4662

47-
# perform inference, and remember first runs are slower owing to Julia's just-in-time compiling
48-
batchSolve!(fg, drawpdf=true, show=true)
63+
# Testing with GenericMarginal
64+
# This will not work because GenericMarginal *shouldn't* really be persisted.
65+
# That would mean we're decomposing the cloud graph...
66+
# genmarg = GenericMarginal()
67+
# Xi = [getVariable(fg, :x0)]
68+
# addFactor!(fg, Xi, genmarg, autoinit=false)
4969

5070
# For Juno/Jupyter style use
51-
pl = drawPoses(fg, meanmax=:mean)
71+
pl = drawPoses(localFg, meanmax=:mean)
5272
plotPose(fg, :x6)
5373
# For scripting use-cases you can export the image
5474
Gadfly.draw(Gadfly.PDF("/tmp/test1.pdf", 20cm, 10cm),pl) # or PNG(...)

0 commit comments

Comments
 (0)