Skip to content

Commit c2a3a2a

Browse files
authored
Merge pull request #268 from JuliaRobotics/feat/1Q20/solvedcount
add solveCount to DFGVariable
2 parents ed9fb94 + 0d72016 commit c2a3a2a

File tree

4 files changed

+66
-12
lines changed

4 files changed

+66
-12
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariab
2323
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
2424
export getMaxPPE, getMeanPPE, getSuggestedPPE, getVariablePPE, getPPE, getVariablePPEs, getPPEs #, getEstimates
2525
export timestamp # DEPRECATED
26+
export getSolved, isSolved, setSolved!
2627
export label, getTimestamp, setTimestamp!, tags, setTags!, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, setSolverData!, internalId, smallData, setSmallData!, bigData
2728
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
2829
export addBigDataEntry!, getBigDataEntry, updateBigDataEntry!, deleteBigDataEntry!, getBigDataEntries, getBigDataKeys

src/entities/DFGVariable.jl

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,9 @@ mutable struct VariableNodeData{T<:InferenceVariable}
2222
ismargin::Bool
2323
dontmargin::Bool
2424
solveInProgress::Int
25+
solvedCount::Int
2526
VariableNodeData{T}() where {T <:InferenceVariable} =
26-
new{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0)
27+
new{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], T(), false, 0.0, false, false, 0, 0)
2728
VariableNodeData{T}(val::Array{Float64,2},
2829
bw::Array{Float64,2},
2930
BayesNetOutVertIDs::Array{Symbol,1},
@@ -36,11 +37,12 @@ mutable struct VariableNodeData{T<:InferenceVariable}
3637
inferdim::Float64,
3738
ismargin::Bool,
3839
dontmargin::Bool,
39-
solveInProgress::Int=0) where T <: InferenceVariable =
40+
solveInProgress::Int=0,
41+
solvedCount::Int=0 ) where T <: InferenceVariable =
4042
new{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,
4143
eliminated,BayesNetVertID,separator,
4244
softtype::T,initialized,inferdim,ismargin,
43-
dontmargin, solveInProgress)
45+
dontmargin, solveInProgress, solvedCount)
4446
end
4547

4648
VariableNodeData(val::Array{Float64,2},
@@ -55,20 +57,21 @@ VariableNodeData(val::Array{Float64,2},
5557
inferdim::Float64,
5658
ismargin::Bool,
5759
dontmargin::Bool,
58-
solveInProgress::Int=0) where T <: InferenceVariable =
60+
solveInProgress::Int=0,
61+
solvedCount::Int=0) where T <: InferenceVariable =
5962
VariableNodeData{T}(val,bw,BayesNetOutVertIDs,dimIDs,dims,
6063
eliminated,BayesNetVertID,separator,
6164
softtype::T,initialized,inferdim,ismargin,
62-
dontmargin, solveInProgress)
65+
dontmargin, solveInProgress, solvedCount)
6366
#
6467
VariableNodeData(softtype::T) where T <: InferenceVariable =
65-
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0)
68+
VariableNodeData{T}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], softtype, false, 0.0, false, false, 0, 0)
6669

6770
function VariableNodeData()
6871
st = stacktrace()
6972
@warn "VariableNodeData() is deprecated please use VariableNodeData{T}() or VariableNodeData(softtype::T) where T <: InferenceVariable. Enable DEBUG logging for stack trace."
7073
@debug st
71-
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false, 0)
74+
VariableNodeData{InferenceVariable}(zeros(1,1), zeros(1,1), Symbol[], Int[], 0, false, :NOTHING, Symbol[], SingletonInferenceVariable(), false, 0.0, false, false, 0, 0)
7275
end
7376

7477

@@ -93,6 +96,7 @@ mutable struct PackedVariableNodeData
9396
ismargin::Bool
9497
dontmargin::Bool
9598
solveInProgress::Int
99+
solvedCount::Int
96100
PackedVariableNodeData() = new()
97101
PackedVariableNodeData(x1::Vector{Float64},
98102
x2::Int,
@@ -109,7 +113,8 @@ mutable struct PackedVariableNodeData
109113
x13::Float64,
110114
x14::Bool,
111115
x15::Bool,
112-
x16::Int) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16)
116+
x16::Int,
117+
solvedCount::Int) = new(x1,x2,x3,x4,x5,x6,x7,x8,x9,x10,x11,x12,x13,x14,x15,x16,solvedCount)
113118
end
114119

115120
# AbstractPointParametricEst interface
@@ -184,7 +189,7 @@ mutable struct DFGVariableSummary <: AbstractDFGVariable
184189
timestamp::DateTime
185190
tags::Vector{Symbol}
186191
ppeDict::Dict{Symbol, <:AbstractPointParametricEst}
187-
softtypename::Symbol
192+
softtypename::Symbol # should be removed
188193
_internalId::Int64
189194
end
190195

@@ -274,8 +279,6 @@ TODO, DO NOT USE v.softtypename in DFGVariableSummary
274279
getSofttype(v::DFGVariableSummary)::Symbol = v.softtypename
275280

276281

277-
278-
279282
"""
280283
$SIGNATURES
281284
@@ -298,6 +301,47 @@ Get solver data dictionary for a variable.
298301
"""
299302
solverDataDict(v::DFGVariable) = v.solverDataDict
300303

304+
"""
305+
$SIGNATURES
306+
307+
Get the number of times a variable has been inferred -- i.e. `solvedCount`.
308+
309+
Related
310+
311+
isSolved, setSolved!
312+
"""
313+
getSolved(v::VariableNodeData) = v.solvedCount
314+
getSolved(v::VariableDataLevel2, solveKey::Symbol=:default) = solverData(v, solveKey) |> getSolved
315+
getSolved(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol=:default) = getSolved(getVariable(dfg, sym), solveKey)
316+
317+
"""
318+
$SIGNATURES
319+
320+
Boolean on whether the variable has been solved.
321+
322+
Related
323+
324+
getSolved, setSolved!
325+
"""
326+
isSolved(v::VariableNodeData) = 0 < v.solvedCount
327+
isSolved(v::VariableDataLevel2, solveKey::Symbol=:default) = solverData(v, solveKey) |> isSolved
328+
isSolved(dfg::AbstractDFG, sym::Symbol, solveKey::Symbol=:default) = isSolved(getVariable(dfg, sym), solveKey)
329+
330+
331+
"""
332+
$SIGNATURES
333+
334+
Update/set the `solveCount` value.
335+
336+
Related
337+
338+
getSolved, isSolved
339+
"""
340+
setSolved!(v::VariableNodeData, val::Int) = v.solvedCount = val
341+
setSolved!(v::VariableDataLevel2, val::Int, solveKey::Symbol=:default) = setSolved!(solverData(v, solveKey), val)
342+
setSolved!(dfg::AbstractDFG, sym::Symbol, val::Int, solveKey::Symbol=:default) = setSolved!(getVariable(dfg, sym), solveKey, val)
343+
344+
301345
"""
302346
$SIGNATURES
303347

src/services/DFGVariable.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ function pack(dfg::G, d::VariableNodeData)::PackedVariableNodeData where G <: Ab
6363
d.inferdim,
6464
d.ismargin,
6565
d.dontmargin,
66-
d.solveInProgress)
66+
d.solveInProgress,
67+
d.solvedCount)
6768
end
6869

6970
function unpack(dfg::G, d::PackedVariableNodeData)::VariableNodeData where G <: AbstractDFG

test/interfaceTests.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,14 @@ end
211211
@test !isVariable(dfg, :doesntexist)
212212
@test !isFactor(dfg, :doesntexist)
213213

214+
# test solveCount for variable
215+
# vari = getVariable(dfg, v1)
216+
@test !isSolved(v1)
217+
@test getSolved(v1) == 0
218+
setSolved!(v1, 1)
219+
@test getSolved(v1) == 1
220+
@test isSolved(v1)
221+
214222
# Session, robot, and user small data tests
215223
smallUserData = Dict{Symbol, String}(:a => "42", :b => "Hello")
216224
smallRobotData = Dict{Symbol, String}(:a => "43", :b => "Hello")

0 commit comments

Comments
 (0)