Skip to content

Commit 8d866f4

Browse files
committed
InMemoryDFGTypes UpdateVariableSolverData!
1 parent bff33dd commit 8d866f4

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,5 +78,6 @@ end
7878

7979
# To be moved as necessary.
8080
include("Common.jl")
81+
include("services/CommonInMemoryDFG.jl")
8182

8283
end

src/services/CommonInMemoryDFG.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
## Common funtions to all InMemoryDFGTypes
2+
3+
4+
#TODO consider moving IIF InMemoryDFGTypes here and exporting,
5+
# but what IIF supports and what DFG support is different?
6+
# define and don't export yet
7+
const InMemoryDFGTypes = Union{SymbolDFG, LightDFG, GraphsDFG, MetaGraphsDFG}
8+
#Union{SymbolDFG, LightDFG}
9+
10+
"""
11+
$(SIGNATURES)
12+
Update solver and estimate data for a variable (variable can be from another graph).
13+
"""
14+
function updateVariableSolverData!(dfg::InMemoryDFGTypes, sourceVariable::DFGVariable)::DFGVariable
15+
#TODO test graphs that pass var/factor by reference
16+
if !exists(dfg, sourceVariable)
17+
error("Source variable '$(sourceVariable.label)' doesn't exist in the graph.")
18+
end
19+
var = getVariable(dfg, sourceVariable.label)
20+
merge!(var.estimateDict, sourceVariable.estimateDict)
21+
merge!(var.solverDataDict, sourceVariable.solverDataDict)
22+
return sourceVariable
23+
end

test/interfaceTests.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,20 @@ end
9494
@test internalId(f1) == f1._internalId
9595
end
9696

97+
@testset "Updating Nodes" begin
98+
global dfg
99+
v1 = getVariable(dfg, :a)
100+
newv1 = deepcopy(v1)
101+
newv1.estimateDict[:default] = Dict{Symbol, VariableEstimate}(
102+
:max => VariableEstimate(:default, :max, [100.0]),
103+
:mean => VariableEstimate(:default, :mean, [50.0]),
104+
:ppe => VariableEstimate(:default, :ppe, [75.0]))
105+
updateVariableSolverData!(dfg, newv1)
106+
#TODO maybe implement ==; @test newv1==v1
107+
#For now spot check
108+
@test newv1.solverDataDict == v1.solverDataDict
109+
end
110+
97111
# Connectivity test
98112
@testset "Connectivity Test" begin
99113
global dfg,v1,v2,f1

0 commit comments

Comments
 (0)