Skip to content

Commit fadff97

Browse files
committed
Moving to 0.7 because I need to change IIF and RoME
1 parent 9db6bed commit fadff97

File tree

9 files changed

+349
-22
lines changed

9 files changed

+349
-22
lines changed

src/DistributedFactorGraphs.jl

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
1+
### TODO: Discussions
2+
# * What is sofftype, and do we want to make it extensible now?
3+
# * Using longs (not GUIDS) for ID's - that work with everyone?
4+
# * BigData and SmallData are referenced in DFGVariable but I don't
5+
# believe they should be retrieved every time. Thoughts?
6+
# * Is ContinuousScalar used anywhere? Seems like == ContinuousMultivariate(1)
7+
# * Right now InferenceVariable is declared here. Is that fair?
8+
# I.e. IncrementalInference's InferenceVariable type hierarchy starts here
9+
10+
### Discussion
11+
# * Do edgeIds need to be defined twice - both in DFGFactor and GFND?
12+
# The higher up the better.
13+
# * What is GenericWrapParam? Looks like it should have been deprecated.
14+
###
15+
###
116
module DistributedFactorGraphs
217

3-
using
4-
DocStringExtensions
18+
using Base
19+
using DocStringExtensions
520

621
# Entities
722
include("entities/AbstractTypes.jl")
823
include("entities/DFGFactor.jl")
924
include("entities/DFGVariable.jl")
1025
include("entities/DFGAPI.jl")
26+
include("entities/DistributedFactorGraph.jl")
27+
include("services/DistributedFactorGraph.jl")
1128

1229
export DFGAPI
30+
export DistributedFactorGraph
31+
1332
export DFGNode
1433
export DFGFactor, GenericFunctionNodeData, FunctionNodeData, PackedFunctionNodeData
1534
export DFGVariable, ContinuousScalar, ContinuousMultivariate, VariableNodeData, PackedVariableNodeData
1635

36+
# Exports for actual graph operations - we need a complete list here
37+
export addV!, addF!, getV, getF, deleteV!, deleteF!, neightbors, ls, subgraph, adjacencyMatrix
38+
39+
# Basis of variable and factor - moved from IncrementalInference
40+
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable
41+
42+
# Include the Graphs.jl API.
43+
include("services/GraphsjlAPI.jl")
44+
1745
end

src/entities/DFGAPI.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,27 @@
11
### Discussion
22
# * How can we implement function signatures here?
3-
# * How can we easily overload functions? E.g. addV has a few implementations
3+
# * addV has a few implementations and all can be used by the single reference (nice work Julia!)
44
# * Where do we incorporate sessions/robot/user? Can be intrinsically, or in the configuration (children)
55
# * The philosophy of dealing atomically with factors and vertices should
66
# simplify things. Creation of a factor or variable should be atomic and in
77
# transaction. This to be discussed.
88

9+
import Base: show
10+
911
# Assuming our base types are variables and factors.
1012
# May refactor this soon back to vertices and edges, depending on
1113
# how the experiment goes.
1214
type DFGAPI
1315
configuration::Any
16+
description::String
17+
validateConfig::Function
1418
# Base functions
1519
addV!::Function
1620
addF!::Function
1721
getV::Function
22+
getVs::Function
1823
getF::Function
24+
getFs::Function
1925
updateV!::Function
2026
updateF!::Function
2127
deleteV!::Function
@@ -28,3 +34,7 @@ type DFGAPI
2834
# Additional parameters for extensibility
2935
additionaProperties::Dict{String, Any}
3036
end
37+
38+
function show(io::IO, d::DFGAPI)
39+
println(io, "DFG API: $(d.description)")
40+
end

src/entities/DFGFactor.jl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
### Discussion
2-
# * Do edgeIds need to be defined twice - both in DFGFactor and GFND?
3-
# The higher up the better.
4-
# * What is GenericWrapParam? Looks like it should have been deprecated.
5-
###
6-
71
"""
82
Data stored in a factor in the factor graph.
93
"""
104
mutable struct GenericFunctionNodeData{T, S}
115
fncargvID::Array{Int,1}
126
eliminated::Bool
137
potentialused::Bool
14-
edgeIDs::Array{Int,1}
8+
edgeIDs::Vector{Int64}
159
frommodule::S #Union{Symbol, AbstractString}
1610
fnc::T
1711
GenericFunctionNodeData{T, S}() where {T, S} = new()
@@ -26,6 +20,7 @@ mutable struct DFGFactor <: DFGNode
2620
label::String
2721
edgeIds::Vector{Int64}
2822
nodeData::GenericFunctionNodeData
23+
DFGFactor(label, factorFunction::R) where {R <: Union{FunctorInferenceType, InferenceType}} = new(-1, label, Vector{Int64}(), )
2924
end
3025

3126
FunctionNodeData{T <: Union{InferenceType, FunctorInferenceType}} = GenericFunctionNodeData{T, Symbol}

src/entities/DFGVariable.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
11

2-
### TODO: Discussions
3-
# * What is sofftype, and do we want to make it extensible now?
4-
# * Using longs (not GUIDS) for ID's - that work with everyone?
5-
# * BigData and SmallData are referenced in DFGVariable but I don't
6-
# believe they should be retrieved every time. Thoughts?
7-
# * Is ContinuousScalar used anywhere? Seems like == ContinuousMultivariate(1)
8-
###
9-
102
struct ContinuousScalar <: InferenceVariable
113
dims::Int
124
labels::Vector{String}
@@ -66,6 +58,7 @@ mutable struct DFGVariable <: DFGNode
6658
nodeData::VariableNodeData
6759
bigDataEntries::Vector{String} #Big data entries
6860
smallData::Dict{String, Any} # All small data.
61+
DFGVariable(label) = new(-1, label, VariableNodeData(), Vector{String}(), Dict{String, Any}())
6962
end
7063

7164
"""
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,22 @@
1+
import Base: show
12

2-
type DistributedFactorGraph
3-
# Do we need this + anything here?
3+
struct DistributedFactorGraph
4+
# A cache - TBD
5+
# something::T
6+
# An API for communication
7+
api::DFGAPI
8+
# A series of mirrors that are asynchronously updated.
9+
mirrors::Vector{DFGAPI}
10+
DistributedFactorGraph() = new(GraphsJlAPI.getAPI(), Vector{DFGAPI}())
11+
DistributedFactorGraph(api::DFGAPI) = new(api, Vector{DFGAPI}())
12+
DistributedFactorGraph(api::DFGAPI, mirrors::Vector{DFGAPI}) = new(api, mirrors)
13+
end
14+
15+
function show(io::IO, d::DistributedFactorGraph)
16+
println(io, "DFG:")
17+
println(io, " - Principal API: $(d.api)")
18+
if length(d.mirrors) > 0
19+
println(io, " - Mirrors ($(length(d.mirrors))): ")
20+
map(x -> print(io, " - $x"), d.mirrors)
21+
end
422
end
Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
2+
function _validate(dfg::DistributedFactorGraph)::Void
3+
#TODO: Erm WTH? This fails with error
4+
# if _api == nothing
5+
# error("The API is not set, please set API with setAPI() call.")
6+
# end
7+
if !dfg.api.validateConfig(dfg.api)
8+
error("The principal API indicated that it is not configured - please configure your API first.")
9+
end
10+
for mirror in dfg.mirrors
11+
if !mirror.validateConfig(mirror)
12+
error("The mirror API '$(string(typeof(mirror)))' indicated that it is not configured - please configure your API first.")
13+
end
14+
end
15+
end
16+
17+
function addV!(dfg::DistributedFactorGraph, v::DFGVariable)::DFGVariable
18+
_validate(dfg)
19+
# Principal
20+
v = dfg.api.addV!(dfg.api, v)
21+
# Mirrors #TODO Consider async call here.
22+
map(api -> api.addV!(api, v), dfg.mirrors)
23+
return v
24+
end
25+
26+
function addV!(dfg::DistributedFactorGraph, label::Symbol, softtype::T)::DFGVariable where {T <: DistributedFactorGraphs.InferenceVariable}
27+
_validate(dfg)
28+
29+
v = DFGVariable(String(label))
30+
v.nodeData.softtype = softtype
31+
v = addV!(dfg, v)
32+
return v
33+
end
34+
35+
"""
36+
Constructs x0x1f1 from [x0; x1] and check for duplicates.
37+
"""
38+
function _constructFactorName(dfg::DistributedFactorGraph, labelVariables::Vector{Symbol})::String
39+
factorName = join(map(label -> String(label), labelVariables))*"f"
40+
# Get the maximum prioir number e.g. f5 using efficient call to get all factor summaries.
41+
duplicates = getFs(dfg, "($factorName[0-9]+)")
42+
newVal = length(duplicates) > 0 ? 0 : maximum(map(f -> parse(Int, replace(f.label, factorName, "")), duplicates)) + 1
43+
return "$factorName$newVal"
44+
end
45+
46+
function addF!(dfg::DistributedFactorGraph, f::DFGFactor)::DFGFactor
47+
_validate(dfg)
48+
# Principal
49+
f = dfg.api.addF!(dfg.api, f)
50+
# Mirrors #TODO Consider async call here.
51+
map(api -> api.addF!(api, f), dfg.mirrors)
52+
return f
53+
end
54+
55+
function addF!(dfg::DistributedFactorGraph, labelVariables::Vector{Symbol}, factorFunc::R)::DFGFactor where {R <: Union{FunctorInferenceType, InferenceType}}
56+
variables = map(label -> gtV(dfg, label), labelVariables)
57+
factName = _constructFactorName(dfg, labelVariables)
58+
f = DFGFactor(-1, factName, map(v -> v.id, variables), factorFunc)
59+
return f
60+
end
61+
62+
function getV(vId::Int64)::DFGVariable
63+
return DFGVariable(vId, "x0", VariableNodeData(), Vector{String}(), Dict{String, Any}())
64+
end
65+
66+
function getV(d::DFGAPI, vLabel::String)::DFGVariable
67+
_validate(dfg)
68+
return DFGVariable(0, vLabel, VariableNodeData(), Vector{String}(), Dict{String, Any}())
69+
end
70+
71+
function getF(d::DFGAPI, fId::Int64)::DFGFactor
72+
_validate(dfg)
73+
return DFGFactor(fId, "x0f0", [], GenericFunctionNodeData{Int64, Symbol}())
74+
end
75+
76+
function getF(d::DFGAPI, fLabel::String)::DFGFactor
77+
_validate(dfg)
78+
return DFGFactor(1, fLabel, [0], GenericFunctionNodeData{Int64, Symbol}())
79+
end
80+
81+
function updateV!(d::DFGAPI, v::DFGVariable)::DFGVariable
82+
_validate(dfg)
83+
return v
84+
end
85+
86+
function updateF!(d::DFGAPI, f::DFGFactor)::DFGFactor
87+
_validate(dfg)
88+
return f
89+
end
90+
91+
function deleteV!(d::DFGAPI, vId::Int64)::DFGVariable
92+
_validate(dfg)
93+
return DFGVariable(vId, "x0", VariableNodeData(), Vector{String}(), Dict{String, Any}())
94+
end
95+
function deleteV!(d::DFGAPI, vLabel::String)::DFGVariable
96+
_validate(dfg)
97+
return DFGVariable(0, vLabel, VariableNodeData(), Vector{String}(), Dict{String, Any}())
98+
end
99+
function deleteV!(d::DFGAPI, v::DFGVariable)::DFGVariable
100+
_validate(dfg)
101+
return v
102+
end
103+
104+
function deleteF!(d::DFGAPI, fId::Int64)::DFGFactor
105+
_validate(dfg)
106+
return DFGFactor(fId, "x0f0", [0], GenericFunctionNodeData{Int64, Symbol}())
107+
end
108+
function deleteF!(d::DFGAPI, fLabel::String)::DFGFactor
109+
_validate(dfg)
110+
return DFGFactor(1, fLabel, [0], GenericFunctionNodeData{Int64, Symbol}())
111+
end
112+
function deleteF!(d::DFGAPI, f::DFGFactor)::DFGFactor
113+
_validate(dfg)
114+
return f
115+
end
116+
117+
# Are we going to return variables related to this variable? TODO: Confirm
118+
function neighbors(d::DFGAPI, v::DFGVariable)::Dict{String, DFGVariable}
119+
_validate(dfg)
120+
return Dict{String, DFGVariable}()
121+
end
122+
123+
# Returns a flat dictionary of the vertices, keyed by ID.
124+
# Assuming only variables here for now - think maybe not, should be variables+factors?
125+
function ls(d::DFGAPI)::Dict{Int64, DFGVariable}
126+
_validate(dfg)
127+
return Dict{Int64, DFGVariable}()
128+
end
129+
130+
# Returns a flat dictionary of the vertices around v, keyed by ID.
131+
# Assuming only variables here for now - think maybe not, should be variables+factors?
132+
function ls(d::DFGAPI, v::DFGVariable, variableDistance=1)::Dict{Int64, DFGVariable}
133+
_validate(dfg)
134+
return Dict{Int64, DFGVariable}()
135+
end
136+
137+
# Returns a flat dictionary of the vertices around v, keyed by ID.
138+
# Assuming only variables here for now - think maybe not, should be variables+factors?
139+
function ls(d::DFGAPI, vId::Int64, variableDistance=1)::Dict{Int64, DFGVariable}
140+
_validate(dfg)
141+
return Dict{Int64, DFGVariable}()
142+
end
143+
144+
function subGraph(d::DFGAPI, vIds::Vector{Int64})::Dict{Int64, DFGVariable}
145+
_validate(dfg)
146+
return Dict{Int64, DFGVariable}()
147+
end
148+
149+
function adjacencyMatrix(d::DFGAPI)::Matrix{DFGNode}
150+
_validate(dfg)
151+
return Matrix{DFGNode}(0,0)
152+
end

0 commit comments

Comments
 (0)