Skip to content

Commit 6846880

Browse files
committed
Accessors
1 parent 875caa5 commit 6846880

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export AbstractDFG
1515
export DFGNode
1616
export DFGFactor
1717
export DFGVariable
18+
export label, timestamp, tags, estimates, estimate, solverData, solverDataDict, id, smallData, bigData
19+
export label, data, id
1820

1921
# Include the Graphs.jl API.
2022
include("services/GraphsDFG.jl")

src/entities/DFGFactor.jl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,7 @@ mutable struct DFGFactor{T, S} <: DFGNode
2727
DFGFactor{T, S}(label::Symbol) where {T, S} = new{T, S}(label, GenericFunctionNodeData{T, S}(), 0)
2828
DFGFactor{T, S}(label::Symbol, _internalId::Int64) where {T, S} = new{T, S}(label, GenericFunctionNodeData{T, S}(), _internalId)
2929
end
30+
31+
label(f::F) where F <: DFGFactor = f.label
32+
data(f::F) where F <: DFGFactor = f.data
33+
id(f::F) where F <: DFGFactor = f._internalId

src/entities/DFGVariable.jl

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ mutable struct VariableNodeData
3636
new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13)
3737
end
3838

39+
struct VariableEstimate
40+
estimate::Vector{Float64}
41+
type::Symbol
42+
key::Symbol
43+
end
44+
3945
"""
4046
$(SIGNATURES)
4147
Fundamental structure for a DFG variable.
@@ -44,12 +50,25 @@ mutable struct DFGVariable <: DFGNode
4450
label::Symbol
4551
timestamp::DateTime
4652
tags::Vector{Symbol}
47-
estimates::Dict{Symbol, Vector{Float64}}
48-
variableData::VariableNodeData
49-
# variableDatas::VND
53+
estimateDict::Dict{Symbol, VariableEstimate}
54+
solverDataDict::Dict{Symbol, VariableNodeData}
5055
smallData::Any
5156
bigData::Any
5257
_internalId::Int64
53-
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, Vector{Float64}}(), VariableNodeData(), nothing, nothing, _internalId)
54-
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, Vector{Float64}}(), VariableNodeData(), nothing, nothing, 0)
58+
DFGVariable(label::Symbol, _internalId::Int64) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), nothing, nothing, _internalId)
59+
DFGVariable(label::Symbol) = new(label, now(), Symbol[], Dict{Symbol, VariableEstimate}(), Dict{Symbol, VariableNodeData}(:default => VariableNodeData()), nothing, nothing, 0)
5560
end
61+
62+
# Accessors
63+
label(v::DFGVariable) = v.label
64+
timestamp(v::DFGVariable) = v.timestamp
65+
tags(v::DFGVariable) = v.tags
66+
estimates(v::DFGVariable) = v.estimateDict
67+
estimate(v::DFGVariable, key::Symbol) = haskey(v.estimateDict, key) ? v.estimateDict[key] : nothing
68+
solverData(v::DFGVariable) = haskey(v.solverDataDict, :default) ? v.solverDataDict[:default] : nothing
69+
solverData(v::DFGVariable, key::Symbol) = haskey(v.solverDataDict, key) ? v.solverDataDict[key] : nothing
70+
solverDataDict(v::DFGVariable) = v.solverDataDict
71+
id(v::DFGVariable) = v._internalId
72+
# Todo: Complete this.
73+
smallData(v::DFGVariable) = v.smallData
74+
bigData(v::DFGVariable) = v.bigData

test/interfaceTests.jl

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ end
2121
end
2222

2323
# Gets
24-
@testset "Gets and Sets" begin
24+
@testset "Gets, Sets, and Accessors" begin
2525
global dfg,v1,v2,f1
2626
@test getVariable(dfg, v1.label) == v1
2727
@test getFactor(dfg, f1.label) == f1
@@ -35,6 +35,20 @@ end
3535
@test updateVariable!(dfg, v1Prime) != v1
3636
f1Prime = deepcopy(f1)
3737
@test updateFactor!(dfg, f1Prime) != f1
38+
39+
# Accessors
40+
@test label(v1) == v1.label
41+
@test timestamp(v1) == v1.timestamp
42+
@test estimates(v1) == v1.estimateDict
43+
@test estimate(v1, :notfound) == nothing
44+
@test solverData(v1) == v1.solverDataDict[:default]
45+
@test solverData(v1, :default) == v1.solverDataDict[:default]
46+
@test solverDataDict(v1) == v1.solverDataDict
47+
@test id(v1) == v1._internalId
48+
49+
@test label(f1) == f1.label
50+
@test data(f1) == f1.data
51+
@test id(f1) == f1._internalId
3852
end
3953

4054
# Deletions

0 commit comments

Comments
 (0)