Skip to content

Commit 1b182cd

Browse files
committed
maybe better abstractparams
1 parent 423dde4 commit 1b182cd

File tree

2 files changed

+19
-24
lines changed

2 files changed

+19
-24
lines changed

src/services/GraphsDFG.jl

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ end
2727
vertex_index(v::GraphsNode) = v.index
2828

2929
# Exports
30-
export GraphsDFG, InMemoryParams
30+
export GraphsDFG, NoSolverParams, AbstractParams
3131
export exists
3232
export getLabelDict, getDescription, setDescription, getInnerGraph, getAddHistory, getSolverParams, setSolverParams
3333

@@ -45,37 +45,32 @@ export getSubgraph
4545
export isFullyConnected, hasOrphans
4646
export toDot, toDotFile
4747

48-
abstract type SolverParams end
48+
abstract type AbstractParams end
4949

50-
mutable struct InMemoryParams <: SolverParams
51-
qfl::Int
52-
isfixedlag::Bool
50+
mutable struct NoSolverParams <: AbstractParams
5351
end
5452

55-
mutable struct GraphsDFG{T<:SolverParams} <: AbstractDFG
53+
mutable struct GraphsDFG{T<:AbstractParams} <: AbstractDFG
5654
g::FGType
5755
description::String
5856
nodeCounter::Int64
5957
labelDict::Dict{Symbol, Int64}
6058
addHistory::Vector{Symbol} #TODO: Discuss more - is this an audit trail?
6159
solverParams::T # Solver parameters
60+
GraphsDFG{T}(g::FGType=Graphs.incdict(GraphsNode,is_directed=false),
61+
d::String="Graphs.jl implementation",
62+
n::Int64=0,
63+
l::Dict{Symbol, Int64}=Dict{Symbol, Int64}(),
64+
a::Vector{Symbol}=Symbol[],
65+
s::T=NoSolverParams()) where T <: AbstractParams = new{T}(g, d, n, l, a, s)
6266
end
6367

64-
function GraphsDFG(g::FGType,
65-
d::String,
66-
n::Int64,
67-
l::Dict{Symbol, Int64},
68-
a::Vector{Symbol},
69-
s::T=InMemoryParams(999999999, false)) where T <: SolverParams
70-
#
71-
GraphsDFG{T}(g, d, n, l, a, s)
72-
end
7368

74-
"""
75-
$(SIGNATURES)
76-
Create a new in-memory Graphs.jl-based DFG factor graph.
77-
"""
78-
GraphsDFG() = GraphsDFG(Graphs.incdict(GraphsNode,is_directed=false), "Graphs.jl implementation", 0, Dict{Symbol, Int64}(), Symbol[])
69+
# """
70+
# $(SIGNATURES)
71+
# Create a new in-memory Graphs.jl-based DFG factor graph.
72+
# """
73+
# GraphsDFG() = GraphsDFG(Graphs.incdict(GraphsNode,is_directed=false), "Graphs.jl implementation", 0, Dict{Symbol, Int64}(), Symbol[], NoSolverParams())
7974

8075
# Accessors
8176
getLabelDict(dfg::GraphsDFG) = dfg.labelDict
@@ -84,7 +79,7 @@ setDescription(dfg::GraphsDFG, description::String) = dfg.description = descript
8479
getInnerGraph(dfg::GraphsDFG) = dfg.g
8580
getAddHistory(dfg::GraphsDFG) = dfg.addHistory
8681
getSolverParams(dfg::GraphsDFG) = dfg.solverParams
87-
setSolverParams(dfg::GraphsDFG, solverParams::Any) = dfg.solverParams = solverParams
82+
setSolverParams(dfg::GraphsDFG, solverParams) = dfg.solverParams = solverParams
8883

8984
"""
9085
$(SIGNATURES)
@@ -445,7 +440,7 @@ Optionally provide a distance to specify the number of edges should be followed.
445440
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
446441
Note: By default orphaned factors (where the subgraph does not contain all the related variables) are not returned. Set includeOrphanFactors to return the orphans irrespective of whether the subgraph contains all the variables.
447442
"""
448-
function getSubgraphAroundNode(dfg::GraphsDFG, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG())::GraphsDFG where T <: DFGNode
443+
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}())::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
449444
if !haskey(dfg.labelDict, node.label)
450445
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
451446
end

test/interfaceTests.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
dfg = testDFGAPI()
1+
dfg = testDFGAPI{NoSolverParams}()
22
v1 = DFGVariable(:a)
33
v2 = DFGVariable(:b)
44
f1 = DFGFactor{Int, :Symbol}(:f1)
@@ -96,7 +96,7 @@ end
9696

9797
# Now make a complex graph for connectivity tests
9898
numNodes = 10
99-
dfg = testDFGAPI()
99+
dfg = testDFGAPI{NoSolverParams}()
100100
verts = map(n -> DFGVariable(Symbol("x$n")), 1:numNodes)
101101
map(v -> addVariable!(dfg, v), verts)
102102
map(n -> addFactor!(dfg, [verts[n], verts[n+1]], DFGFactor{Int, :Symbol}(Symbol("x$(n)x$(n+1)f1"))), 1:(numNodes-1))

0 commit comments

Comments
 (0)