1
- dfg = LightDFG {NoSolverParams, DFGVariableSummary, DFGFactorSummary} ()
2
1
2
+ dfg = LightDFG {NoSolverParams, VARTYPE, FACTYPE} ()
3
3
DistributedFactorGraphs. DFGVariableSummary (label:: Symbol ) = DFGVariableSummary (label, DistributedFactorGraphs. now (), Symbol[], Dict {Symbol, MeanMaxPPE} (), :NA , 0 )
4
-
5
4
DistributedFactorGraphs. DFGFactorSummary (label:: Symbol ) = DFGFactorSummary (label, Symbol[], 0 , Symbol[])
6
5
7
- v1 = DFGVariableSummary (:a )
8
- v2 = DFGVariableSummary (:b )
9
- f1 = DFGFactorSummary (:f1 )
6
+ v1 = VARTYPE (:a )
7
+ v2 = VARTYPE (:b )
8
+ f1 = FACTYPE (:f1 )
10
9
11
10
# add tags for filters
12
11
append! (v1. tags, [:VARIABLE , :POSE ])
13
12
append! (v2. tags, [:VARIABLE , :LANDMARK ])
14
13
append! (f1. tags, [:FACTOR ])
15
14
16
15
# Force softtypename
17
- v1 . softtypename = :Pose2
16
+ isa (v1, DFGVariableSummary) && (v1 . softtypename = :Pose2 )
18
17
19
18
# @testset "Creating Graphs" begin
20
19
global dfg,v1,v2,f1
21
20
addVariable! (dfg, v1)
22
21
addVariable! (dfg, v2)
23
22
addFactor! (dfg, [v1, v2], f1)
24
- @test_throws Exception addFactor! (dfg, DFGFactorSummary (" f2" ), [v1, DFGVariableSummary (" Nope" )])
23
+ @test_throws Exception addFactor! (dfg, FACTYPE (" f2" ), [v1, VARTYPE (" Nope" )])
25
24
# end
26
25
27
26
@testset " Adding Removing Nodes" begin
28
- dfg2 = LightDFG {NoSolverParams, DFGVariableSummary, DFGFactorSummary } ()
29
- v1 = DFGVariableSummary (:a )
30
- v2 = DFGVariableSummary (:b )
31
- v3 = DFGVariableSummary (:c )
32
- f1 = DFGFactorSummary (:f1 )
33
- f2 = DFGFactorSummary (:f2 )
27
+ dfg2 = LightDFG {NoSolverParams, VARTYPE, FACTYPE } ()
28
+ v1 = VARTYPE (:a )
29
+ v2 = VARTYPE (:b )
30
+ v3 = VARTYPE (:c )
31
+ f1 = FACTYPE (:f1 )
32
+ f2 = FACTYPE (:f2 )
34
33
# @testset "Creating Graphs" begin
35
34
@test addVariable! (dfg2, v1)
36
35
@test addVariable! (dfg2, v2)
79
78
# Gets
80
79
@testset " Gets, Sets, and Accessors" begin
81
80
global dfg,v1,v2,f1
81
+
82
+
82
83
@test getVariable (dfg, v1. label) == v1
83
84
@test getFactor (dfg, f1. label) == f1
84
85
@test_throws Exception getVariable (dfg, :nope )
88
89
89
90
# Sets
90
91
v1Prime = deepcopy (v1)
91
- @test updateVariable! (dfg, v1Prime) ! = v1
92
+ @test updateVariable! (dfg, v1Prime) = = v1
92
93
f1Prime = deepcopy (f1)
93
- @test updateFactor! (dfg, f1Prime) ! = f1
94
+ @test updateFactor! (dfg, f1Prime) = = f1
94
95
95
96
# Accessors
96
97
@test label (v1) == v1. label
97
98
@test tags (v1) == v1. tags
98
- @test timestamp (v1) == v1. timestamp
99
- @test estimates (v1) == v1. estimateDict
100
- @test estimate (v1, :notfound ) == nothing
101
- @test softtype (v1) == :Pose2
99
+
100
+ if VARTYPE == DFGVariableSummary
101
+ @test timestamp (v1) == v1. timestamp
102
+ @test estimates (v1) == v1. estimateDict
103
+ @test estimate (v1, :notfound ) == nothing
104
+ @test softtype (v1) == :Pose2
105
+ @test internalId (v1) == v1. _internalId
106
+ end
102
107
# @test solverData(v1) === v1.solverDataDict[:default]
103
108
# @test getData(v1) === v1.solverDataDict[:default]
104
109
# @test solverData(v1, :default) === v1.solverDataDict[:default]
105
110
# @test solverDataDict(v1) == v1.solverDataDict
106
- @test internalId (v1) == v1. _internalId
107
111
108
112
@test label (f1) == f1. label
109
113
@test tags (f1) == f1. tags
@@ -112,44 +116,46 @@ end
112
116
# @test data(f1) == f1.data
113
117
# @test getData(f1) == f1.data
114
118
# Internal function
115
- @test internalId (f1) == f1. _internalId
119
+ if FACTYPE == DFGFactorSummary
120
+ @test internalId (f1) == f1. _internalId
121
+ end
116
122
117
- @test getSolverParams (dfg) != nothing
118
- @test setSolverParams (dfg, getSolverParams (dfg)) == getSolverParams (dfg)
119
123
end
120
124
121
125
@testset " Updating Nodes" begin
122
- global dfg
123
- # get the variable
124
- var = getVariable (dfg, :a )
125
- # make a copy and simulate external changes
126
- newvar = deepcopy (var)
127
- estimates (newvar)[:default ] = MeanMaxPPE (:default , [100.0 ], [50.0 ])
128
- # update
129
- mergeUpdateVariableSolverData! (dfg, newvar)
130
- # For now spot check
131
- # @test solverDataDict(newvar) == solverDataDict(var)
132
- @test estimates (newvar) == estimates (var)
126
+ if VARTYPE == DFGVariableSummary
127
+ global dfg
128
+ # get the variable
129
+ var = getVariable (dfg, :a )
130
+ # make a copy and simulate external changes
131
+ newvar = deepcopy (var)
132
+ estimates (newvar)[:default ] = MeanMaxPPE (:default , [100.0 ], [50.0 ])
133
+ # update
134
+ mergeUpdateVariableSolverData! (dfg, newvar)
135
+ # For now spot check
136
+ # @test solverDataDict(newvar) == solverDataDict(var)
137
+ @test estimates (newvar) == estimates (var)
133
138
134
- # Delete :default and replace to see if new ones can be added
135
- delete! (estimates (newvar), :default )
136
- estimates (newvar)[:second ] = MeanMaxPPE (:second , [10.0 ], [5.0 ])
139
+ # Delete :default and replace to see if new ones can be added
140
+ delete! (estimates (newvar), :default )
141
+ estimates (newvar)[:second ] = MeanMaxPPE (:second , [10.0 ], [5.0 ])
137
142
138
- # Persist to the original variable.
139
- mergeUpdateVariableSolverData! (dfg, newvar)
140
- # At this point newvar will have only :second, and var should have both (it is the reference)
141
- @test symdiff (collect (keys (estimates (var))), [:default , :second ]) == Symbol[]
142
- @test symdiff (collect (keys (estimates (newvar))), [:second ]) == Symbol[]
143
- # Get the source too.
144
- @test symdiff (collect (keys (estimates (getVariable (dfg, :a )))), [:default , :second ]) == Symbol[]
143
+ # Persist to the original variable.
144
+ mergeUpdateVariableSolverData! (dfg, newvar)
145
+ # At this point newvar will have only :second, and var should have both (it is the reference)
146
+ @test symdiff (collect (keys (estimates (var))), [:default , :second ]) == Symbol[]
147
+ @test symdiff (collect (keys (estimates (newvar))), [:second ]) == Symbol[]
148
+ # Get the source too.
149
+ @test symdiff (collect (keys (estimates (getVariable (dfg, :a )))), [:default , :second ]) == Symbol[]
150
+ end
145
151
end
146
152
147
153
# Connectivity test
148
154
@testset " Connectivity Test" begin
149
155
global dfg,v1,v2,f1
150
156
@test isFullyConnected (dfg) == true
151
157
@test hasOrphans (dfg) == false
152
- addVariable! (dfg, DFGVariableSummary (:orphan ))
158
+ addVariable! (dfg, VARTYPE (:orphan ))
153
159
@test isFullyConnected (dfg) == false
154
160
@test hasOrphans (dfg) == true
155
161
end
@@ -191,13 +197,13 @@ end
191
197
192
198
# Now make a complex graph for connectivity tests
193
199
numNodes = 10
194
- dfg = LightDFG {NoSolverParams, DFGVariableSummary, DFGFactorSummary } ()
195
- verts = map (n -> DFGVariableSummary (Symbol (" x$n " )), 1 : numNodes)
200
+ dfg = LightDFG {NoSolverParams, VARTYPE, FACTYPE } ()
201
+ verts = map (n -> VARTYPE (Symbol (" x$n " )), 1 : numNodes)
196
202
# change ready and backendset for x7,x8 for improved tests on x7x8f1
197
203
# verts[7].ready = 1
198
204
# verts[8].backendset = 1
199
205
map (v -> addVariable! (dfg, v), verts)
200
- map (n -> addFactor! (dfg, [verts[n], verts[n+ 1 ]], DFGFactorSummary (Symbol (" x$(n) x$(n+ 1 ) f1" ))), 1 : (numNodes- 1 ))
206
+ map (n -> addFactor! (dfg, [verts[n], verts[n+ 1 ]], FACTYPE (Symbol (" x$(n) x$(n+ 1 ) f1" ))), 1 : (numNodes- 1 ))
201
207
202
208
@testset " Getting Neighbors" begin
203
209
global dfg,verts
@@ -211,20 +217,6 @@ map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactorSummary(Symbol("x$(n)x
211
217
@test getNeighbors (dfg, getFactor (dfg, :x1x2f1 )) == ls (dfg, getFactor (dfg, :x1x2f1 ))
212
218
@test getNeighbors (dfg, :x1x2f1 ) == ls (dfg, :x1x2f1 )
213
219
214
- # ready and backendset
215
- # @test getNeighbors(dfg, :x5, ready=1) == Symbol[]
216
- # @test getNeighbors(dfg, :x5, ready=0) == [:x4x5f1,:x5x6f1]
217
- # @test getNeighbors(dfg, :x5, backendset=1) == Symbol[]
218
- # @test getNeighbors(dfg, :x5, backendset=0) == [:x4x5f1,:x5x6f1]
219
- # @test getNeighbors(dfg, :x7x8f1, ready=0) == [:x8]
220
- # @test getNeighbors(dfg, :x7x8f1, backendset=0) == [:x7]
221
- # @test getNeighbors(dfg, :x7x8f1, ready=1) == [:x7]
222
- # @test getNeighbors(dfg, :x7x8f1, backendset=1) == [:x8]
223
- # @test getNeighbors(dfg, verts[1], ready=0) == [:x1x2f1]
224
- # @test getNeighbors(dfg, verts[1], ready=1) == Symbol[]
225
- # @test getNeighbors(dfg, verts[1], backendset=0) == [:x1x2f1]
226
- # @test getNeighbors(dfg, verts[1], backendset=1) == Symbol[]
227
-
228
220
end
229
221
230
222
@testset " Getting Subgraphs" begin
@@ -256,41 +248,27 @@ end
256
248
end
257
249
258
250
@testset " Summaries and Summary Graphs" begin
259
- factorFields = fieldnames (DFGFactorSummary)
260
- variableFields = fieldnames (DFGVariableSummary)
251
+ if VARTYPE == DFGVariableSummary
252
+ factorFields = fieldnames (FACTYPE)
253
+ variableFields = fieldnames (VARTYPE)
261
254
262
- summary = getSummary (dfg)
263
- @test symdiff (collect (keys (summary. variables)), ls (dfg)) == Symbol[]
264
- @test symdiff (collect (keys (summary. factors)), lsf (dfg)) == Symbol[]
255
+ summary = getSummary (dfg)
256
+ @test symdiff (collect (keys (summary. variables)), ls (dfg)) == Symbol[]
257
+ @test symdiff (collect (keys (summary. factors)), lsf (dfg)) == Symbol[]
265
258
266
- summaryGraph = getSummaryGraph (dfg)
267
- @test symdiff (ls (summaryGraph), ls (dfg)) == Symbol[]
268
- @test symdiff (lsf (summaryGraph), lsf (dfg)) == Symbol[]
269
- # Check all fields are equal for all variables
270
- for v in ls (summaryGraph)
271
- for field in variableFields
272
- @test getfield (getVariable (dfg, v), field) == getfield (getVariable (summaryGraph, v), field)
259
+ summaryGraph = getSummaryGraph (dfg)
260
+ @test symdiff (ls (summaryGraph), ls (dfg)) == Symbol[]
261
+ @test symdiff (lsf (summaryGraph), lsf (dfg)) == Symbol[]
262
+ # Check all fields are equal for all variables
263
+ for v in ls (summaryGraph)
264
+ for field in variableFields
265
+ @test getfield (getVariable (dfg, v), field) == getfield (getVariable (summaryGraph, v), field)
266
+ end
273
267
end
274
- end
275
- for f in lsf (summaryGraph)
276
- for field in factorFields
277
- @test getfield ( getFactor (dfg, f), field) == getfield ( getFactor (summaryGraph, f), field)
268
+ for f in lsf (summaryGraph)
269
+ for field in factorFields
270
+ @test getfield ( getFactor (dfg, f), field) == getfield ( getFactor (summaryGraph, f), field)
271
+ end
278
272
end
279
273
end
280
274
end
281
-
282
- # @testset "Producing Dot Files" begin
283
- # # create a simpler graph for dot testing
284
- # dotdfg = LightDFG{NoSolverParams, DFGVariableSummary, DFGFactorSummary}()
285
- # v1 = DFGVariableSummary(:a)
286
- # v2 = DFGVariableSummary(:b)
287
- # f1 = DFGFactorSummary(:f1)
288
- # addVariable!(dotdfg, v1)
289
- # addVariable!(dotdfg, v2)
290
- # addFactor!(dotdfg, [v1, v2], f1)
291
- #
292
- # @test toDot(dotdfg) == "graph graphname {\n2 [\"label\"=\"b\",\"shape\"=\"box\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n2 -- 3\n3 [\"label\"=\"f1\",\"shape\"=\"ellipse\",\"fillcolor\"=\"blue\",\"color\"=\"blue\"]\n1 [\"label\"=\"a\",\"shape\"=\"box\",\"fillcolor\"=\"red\",\"color\"=\"red\"]\n1 -- 3\n}\n"
293
- # @test toDotFile(dotdfg, "something.dot") == nothing
294
- # Base.rm("something.dot")
295
- #
296
- # end
0 commit comments