Skip to content

Commit a32e854

Browse files
committed
Graphs.jl initial implementation
1 parent fadff97 commit a32e854

File tree

10 files changed

+462
-205
lines changed

10 files changed

+462
-205
lines changed

REQUIRE

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
julia 0.6
2-
Graphs 0.9.0
1+
julia 1.0
32
DocStringExtensions 0.4.1
3+
LightGraphs 1.2.0
4+
MetaGraphs 0.6.1
5+
Requires 0.5.2
6+
DataFrames

src/DistributedFactorGraphs.jl

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,29 +17,31 @@ module DistributedFactorGraphs
1717

1818
using Base
1919
using DocStringExtensions
20+
using Requires
2021

2122
# Entities
2223
include("entities/AbstractTypes.jl")
23-
include("entities/DFGFactor.jl")
24-
include("entities/DFGVariable.jl")
25-
include("entities/DFGAPI.jl")
26-
include("entities/DistributedFactorGraph.jl")
27-
include("services/DistributedFactorGraph.jl")
24+
# include("entities/DFGFactor.jl")
25+
# include("entities/DFGVariable.jl")
26+
# include("entities/DFGAPI.jl")
27+
# include("entities/DistributedFactorGraph.jl")
28+
# include("services/DistributedFactorGraph.jl")
2829

29-
export DFGAPI
30-
export DistributedFactorGraph
30+
export AbstractDFG
31+
# export DistributedFactorGraph
3132

3233
export DFGNode
33-
export DFGFactor, GenericFunctionNodeData, FunctionNodeData, PackedFunctionNodeData
34-
export DFGVariable, ContinuousScalar, ContinuousMultivariate, VariableNodeData, PackedVariableNodeData
34+
export DFGFactor#, GenericFunctionNodeData, FunctionNodeData, PackedFunctionNodeData
35+
export DFGVariable#, ContinuousScalar, ContinuousMultivariate, VariableNodeData, PackedVariableNodeData
3536

3637
# Exports for actual graph operations - we need a complete list here
37-
export addV!, addF!, getV, getF, deleteV!, deleteF!, neightbors, ls, subgraph, adjacencyMatrix
38+
export addVariable, addFactor
39+
# export addV!, addF!, getV, getF, deleteV!, deleteF!, neighbors, ls, subgraph, adjacencyMatrix
3840

3941
# Basis of variable and factor - moved from IncrementalInference
40-
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable
42+
# export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable
4143

4244
# Include the Graphs.jl API.
43-
include("services/GraphsjlAPI.jl")
45+
include("services/GraphsDFG.jl")
4446

4547
end

src/entities/AbstractTypes.jl

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,21 @@ abstract type FunctorInferenceType <: Function end
55
abstract type InferenceVariable end
66

77
abstract type DFGNode end
8+
9+
abstract type AbstractDFG
10+
end
11+
12+
mutable struct DFGVariable <: DFGNode
13+
label::Symbol
14+
#TODO: Populate
15+
_internalId::Int64
16+
DFGVariable(label::Symbol) = new(label, 0)
17+
DFGVariable(label::Symbol, _internalId::Int64) = new(label, _internalId)
18+
end
19+
mutable struct DFGFactor <: DFGNode
20+
label::Symbol
21+
#TODO: Populate
22+
_internalId::Int64
23+
DFGFactor(label::Symbol) = new(label, 0)
24+
DFGFactor(label::Symbol, _internalId::Int64) = new(label, _internalId)
25+
end

src/entities/DFGAPI.jl

Lines changed: 0 additions & 40 deletions
This file was deleted.

src/entities/DFGFactor.jl

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ mutable struct DFGFactor <: DFGNode
2020
label::String
2121
edgeIds::Vector{Int64}
2222
nodeData::GenericFunctionNodeData
23-
DFGFactor(label, factorFunction::R) where {R <: Union{FunctorInferenceType, InferenceType}} = new(-1, label, Vector{Int64}(), )
23+
DFGFactor(label::String, factorFunction::R) where {R <: Union{FunctorInferenceType, InferenceType}} = new(-1, label, Vector{Int64}(), factorFunction)
24+
DFGFactor(label::String, edgeIds::Vector{Int64}, factorFunction::R) where {R <: Union{FunctorInferenceType, InferenceType}} = new(-1, label, edgeIds, factorFunction)
2425
end
2526

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

src/services/DistributedFactorGraph.jl

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,36 @@ function _validate(dfg::DistributedFactorGraph)::Void
1414
end
1515
end
1616

17+
function getV(dfg::DistributedFactorGraph, vId::Int64)::DFGVariable
18+
return DFGVariable("x0")
19+
end
20+
21+
function getV(dfg::DistributedFactorGraph, vLabel::String)::DFGVariable
22+
_validate(dfg)
23+
return DFGVariable(vLabel)
24+
end
25+
26+
function getVs(dfg::DistributedFactorGraph, regex::String)::Vector{DFGVariable}
27+
_validate(dfg)
28+
return [DFGVariable("x0")]
29+
end
30+
31+
function getF(dfg::DistributedFactorGraph, fId::Int64)::DFGFactor
32+
_validate(dfg)
33+
return DFGFactor(fId, "x0f0", [], GenericFunctionNodeData{Int64, Symbol}())
34+
end
35+
36+
function getF(dfg::DistributedFactorGraph, fLabel::String)::DFGFactor
37+
_validate(dfg)
38+
return DFGFactor(1, fLabel, [0], GenericFunctionNodeData{Int64, Symbol}())
39+
end
40+
41+
function getFs(dfg::DistributedFactorGraph, regex::String)::Vector{DFGFactor}
42+
_validate(dfg)
43+
return [DFGFactor("x0x1f0", [0, 1], GenericFunctionNodeData{Int64, Symbol}())]
44+
end
45+
46+
1747
function addV!(dfg::DistributedFactorGraph, v::DFGVariable)::DFGVariable
1848
_validate(dfg)
1949
# Principal
@@ -52,30 +82,44 @@ function addF!(dfg::DistributedFactorGraph, f::DFGFactor)::DFGFactor
5282
return f
5383
end
5484

55-
function addF!(dfg::DistributedFactorGraph, labelVariables::Vector{Symbol}, factorFunc::R)::DFGFactor where {R <: Union{FunctorInferenceType, InferenceType}}
56-
variables = map(label -> gtV(dfg, label), labelVariables)
85+
function parseusermultihypo(multihypo::Union{Tuple,Vector{Float64}})
86+
mh = nothing
87+
if multihypo != nothing
88+
multihypo2 = Float64[multihypo...]
89+
# verts = Symbol.(multihypo[1,:])
90+
for i in 1:length(multihypo)
91+
if multihypo[i] > 0.999999
92+
multihypo2[i] = 0.0
93+
end
94+
end
95+
mh = Categorical(Float64[multihypo2...] )
96+
end
97+
return mh
98+
end
99+
100+
function addF!(
101+
dfg::DistributedFactorGraph,
102+
labelVariables::Vector{Symbol},
103+
factorFunc::R;
104+
multihypo::Union{Nothing,Tuple,Vector{Float64}}=nothing)::DFGFactor
105+
where {R <: Union{FunctorInferenceType, InferenceType}}
106+
variables = map(label -> getV(dfg, String(label)), labelVariables)
57107
factName = _constructFactorName(dfg, labelVariables)
58-
f = DFGFactor(-1, factName, map(v -> v.id, variables), factorFunc)
59-
return f
60-
end
61108

62-
function getV(vId::Int64)::DFGVariable
63-
return DFGVariable(vId, "x0", VariableNodeData(), Vector{String}(), Dict{String, Any}())
64-
end
109+
# Create the FunctionNodeData
110+
ftyp = typeof(factorFunc) # maybe this can be T
111+
# @show "setDefaultFactorNode!", usrfnc, ftyp, T
112+
mhcat = parseusermultihypo(multihypo)
113+
# gwpf = prepgenericwrapper(Xi, usrfnc, getSample, multihypo=mhcat)
114+
ccw = prepgenericconvolution(Xi, usrfnc, multihypo=mhcat, threadmodel=threadmodel)
65115

66-
function getV(d::DFGAPI, vLabel::String)::DFGVariable
67-
_validate(dfg)
68-
return DFGVariable(0, vLabel, VariableNodeData(), Vector{String}(), Dict{String, Any}())
69-
end
116+
m = Symbol(ftyp.name.module)
70117

71-
function getF(d::DFGAPI, fId::Int64)::DFGFactor
72-
_validate(dfg)
73-
return DFGFactor(fId, "x0f0", [], GenericFunctionNodeData{Int64, Symbol}())
74-
end
118+
# experimental wip
119+
data_ccw = FunctionNodeData{CommonConvWrapper{T}}(Int[], false, false, Int[], m, ccw)
75120

76-
function getF(d::DFGAPI, fLabel::String)::DFGFactor
77-
_validate(dfg)
78-
return DFGFactor(1, fLabel, [0], GenericFunctionNodeData{Int64, Symbol}())
121+
f = DFGFactor(-1, factName, map(v -> v.id, variables), data_ccw)
122+
return f
79123
end
80124

81125
function updateV!(d::DFGAPI, v::DFGVariable)::DFGVariable

0 commit comments

Comments
 (0)