Skip to content

Commit 0d5c545

Browse files
authored
Merge pull request #393 from JuliaRobotics/maint/20Q2/varfacCRUD
FIX CGDFG addFactor! errors but adds factor
2 parents 17dbcca + 0a6a0ce commit 0d5c545

File tree

5 files changed

+65
-31
lines changed

5 files changed

+65
-31
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,15 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariable
181181
return variable
182182
end
183183

184-
function addFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)
185-
addFactor!(dfg, factor._variableOrderSymbols, factor)
186-
end
187184

188-
function addFactor!(dfg::CloudGraphsDFG, variables::Vector{<:DFGVariable}, factor::DFGFactor)::DFGFactor
185+
function addFactor!(dfg::CloudGraphsDFG, factor::DFGFactor)::DFGFactor
189186
if exists(dfg, factor)
190187
error("Factor '$(factor.label)' already exists in the factor graph")
191188
end
192189

193-
# Update the variable ordering
194-
factor._variableOrderSymbols = map(v->v.label, variables)
190+
variableIds = factor._variableOrderSymbols
191+
variables = map(vId -> getVariable(dfg, vId), variableIds)
192+
195193

196194
# Construct the properties to save
197195
props = packFactor(dfg, factor)
@@ -212,11 +210,6 @@ function addFactor!(dfg::CloudGraphsDFG, variables::Vector{<:DFGVariable}, facto
212210
return factor
213211
end
214212

215-
function addFactor!(dfg::CloudGraphsDFG, variableIds::Vector{Symbol}, factor::DFGFactor)::DFGFactor
216-
variables = map(vId -> getVariable(dfg, vId), variableIds)
217-
return addFactor!(dfg, variables, factor)
218-
end
219-
220213
function getVariable(dfg::CloudGraphsDFG, label::Union{Symbol, String})::DFGVariable
221214
if typeof(label) == String
222215
label = Symbol(label)

test/consolInterfaceDev.jl

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,22 @@ using DistributedFactorGraphs
55
using Pkg
66
using Dates
77

8+
using IncrementalInference
9+
10+
include("testBlocks.jl")
11+
12+
##
13+
testDFGAPI = CloudGraphsDFG
14+
815
# TODO maybe move to cloud graphs permanantly as standard easy to use functions
916
function DFG.CloudGraphsDFG(; params=NoSolverParams())
1017
cgfg = CloudGraphsDFG{typeof(params)}("localhost", 7474, "neo4j", "test",
1118
"testUser", "testRobot", "testSession",
1219
"description",
1320
nothing,
1421
nothing,
15-
(dfg,f)->f,
16-
(dfg,f)->f,
22+
IncrementalInference.decodePackedType,#(dfg,f)->f,
23+
IncrementalInference.rebuildFactorMetadata!,#(dfg,f)->f,
1724
solverParams=params)
1825
createDfgSessionIfNotExist(cgfg)
1926
return cgfg
@@ -42,8 +49,8 @@ function DFG.CloudGraphsDFG(description::String,
4249
description,
4350
nothing,
4451
nothing,
45-
(dfg,f)->f,
46-
(dfg,f)->f,
52+
IncrementalInference.decodePackedType,#(dfg,f)->f,
53+
IncrementalInference.rebuildFactorMetadata!,#(dfg,f)->f,
4754
solverParams=solverParams)
4855

4956
createDfgSessionIfNotExist(cdfg)
@@ -75,12 +82,39 @@ end
7582
end
7683

7784
# DFGVariable structure construction and accessors
78-
@testset "DFG Variable" begin
79-
global var1, var2, var3, v1_tags
80-
var1, var2, var3, v1_tags = DFGVariableSCA()
81-
end
85+
# @testset "DFG Variable" begin
86+
# global var1, var2, var3, v1_tags
87+
# var1, var2, var3, v1_tags = DFGVariableSCA()
88+
# end
89+
newfg = initfg()
90+
var1 = addVariable!(newfg, :a, ContinuousScalar, labels=[:POSE])
91+
var2 = addVariable!(newfg, :b, ContinuousScalar, labels=[:LANDMARK])
92+
var3 = addVariable!(newfg, :c, ContinuousScalar)
93+
v1_tags = Set([:VARIABLE, :POSE])
94+
8295

8396
# DFGFactor structure construction and accessors
84-
@testset "DFG Factor" begin
85-
global fac0, fac1, fac2 = DFGFactorSCA()
97+
# @testset "DFG Factor" begin
98+
# global fac0, fac1, fac2 = DFGFactorSCA()
99+
# end
100+
101+
fac0 = addFactor!(newfg, [:a], Prior(Normal()))
102+
fac1 = addFactor!(newfg, [:a, :b], LinearConditional(Normal()))
103+
fac2 = addFactor!(newfg, [:b, :c], LinearConditional(Normal()))
104+
105+
@testset "Variables and Factors CRUD and SET" begin
106+
VariablesandFactorsCRUD_SET!(fg1, var1, var2, var3, fac0, fac1, fac2)
86107
end
108+
109+
# @testset "tags" begin
110+
# tagsTestBlock!(fg1, var1, v1_tags)
111+
# end
112+
#
113+
#
114+
# fg = fg1
115+
# v1 = var1
116+
# v2 = var2
117+
# v3 = var3
118+
# f0 = fac0
119+
# f1 = fac1
120+
# f2 = fac2

test/runtests.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,6 @@ for api in apis
3939
end
4040
end
4141

42-
if get(ENV, "IIF_TEST", "") == "true"
43-
@testset "Testing Driver: CloudGraphsDFG" begin
44-
@info "Testing Driver: CloudGraphsDFG"
45-
global testDFGAPI = CloudGraphsDFG
46-
include("consolInterfaceDev.jl")
47-
end
48-
end
4942

5043
# Test special cases
5144
@testset "Plotting Tests" begin
@@ -82,6 +75,12 @@ if get(ENV, "IIF_TEST", "") == "true"
8275

8376
using IncrementalInference
8477

78+
@testset "Consolidation WIP Testing Driver: CloudGraphsDFG" begin
79+
@info "Testing Driver: CloudGraphsDFG"
80+
global testDFGAPI = CloudGraphsDFG
81+
include("consolInterfaceDev.jl")
82+
end
83+
8584
apis = [
8685
GraphsDFG{SolverParams}(),
8786
LightDFG{SolverParams}(),

test/testBlocks.jl

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ function DFGFactorSCA()
296296
# create f0 here for a later timestamp
297297
f0 = DFGFactor(:af1, [:a], gfnd_prior, tags = Set([:PRIOR]))
298298

299+
#fill in undefined fields
300+
f2.solverData.certainhypo = Int[]
301+
f2.solverData.fncargvID = Symbol[]
302+
f2.solverData.frommodule = :DistributedFactorGraphs
303+
f2.solverData.multihypo = Float64[]
304+
f2.solverData.edgeIDs = Int64[]
305+
299306
return (f0=f0, f1=f1, f2=f2)
300307
end
301308

@@ -339,14 +346,14 @@ function VariablesandFactorsCRUD_SET!(fg, v1, v2, v3, f0, f1, f2)
339346
@test getFactor(fg, :bcf1) |> getTimestamp == newtimestamp
340347
end
341348
#deletions
342-
@test getVariable(fg, :c) === deleteVariable!(fg, v3)
349+
@test getVariable(fg, :c) == deleteVariable!(fg, v3)
343350
@test_throws ErrorException deleteVariable!(fg, v3)
344351
@test issetequal(ls(fg),[:a,:b])
345-
@test getFactor(fg, :bcf1) === deleteFactor!(fg, f2)
352+
353+
@test getFactor(fg, :bcf1) == deleteFactor!(fg, f2)
346354
@test_throws ErrorException deleteFactor!(fg, f2)
347355
@test lsf(fg) == [:abf1]
348356

349-
350357
@test getVariable(fg, :a) == v1
351358
@test getVariable(fg, :a, :default) == v1
352359

test/testFurther.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ using IncrementalInference
33

44
dfg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
55
"testUser", "testRobot", "testSession",
6+
"description of test session",
67
nothing,
78
nothing,
89
IncrementalInference.decodePackedType,

0 commit comments

Comments
 (0)