Skip to content

Commit 433b2fc

Browse files
committed
Merged master
2 parents e76f3d8 + 47f1527 commit 433b2fc

File tree

11 files changed

+185
-138
lines changed

11 files changed

+185
-138
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -577,12 +577,12 @@ Optionally provide a distance to specify the number of edges should be followed.
577577
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
578578
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.
579579
"""
580-
function getSubgraphAroundNode(dfg::CloudGraphsDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg))::AbstractDFG
580+
function getSubgraphAroundNode(dfg::CloudGraphsDFG, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg); solvable::Int=0)::AbstractDFG
581581
distance < 1 && error("getSubgraphAroundNode() only works for distance > 0")
582582

583583
# Thank you Neo4j for 0..* awesomeness!!
584584
neighborList = _getLabelsFromCyphonQuery(dfg.neo4jInstance,
585-
"(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))-[FACTORGRAPH*0..$distance]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId)) WHERE (n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR) and not (node:SESSION)")
585+
"(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))-[FACTORGRAPH*0..$distance]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId)) WHERE (n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR) and not (node:SESSION) and (node.solvable >= $solvable)")
586586

587587
# Copy the section of graph we want
588588
_copyIntoGraph!(dfg, addToDFG, neighborList, includeOrphanFactors)

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ export AbstractParams, NoSolverParams
2323
export DFGNode, DFGVariable, DFGFactor, AbstractDFGVariable, AbstractDFGFactor
2424
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
2525
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
26+
export getMaxPPE, getMeanPPE, getSuggestedPPE
2627
export label, timestamp, tags, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
2728
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
2829

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -238,9 +238,9 @@ Optionally specify a label regular expression to retrieves a subset of the varia
238238
function getVariables(dfg::GraphsDFG,
239239
regexFilter::Union{Nothing, Regex}=nothing;
240240
tags::Vector{Symbol}=Symbol[],
241-
solvable::Int=0 )::Vector{DFGVariable}
241+
solvable::Int=0)::Vector{DFGVariable}
242242
#
243-
variables = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGVariable) && (solvable <= isSolvable(n.dfgNode)), Graphs.vertices(dfg.g)))
243+
variables = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGVariable) && (solvable != 0 ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
244244
# filter on solvable
245245

246246
# filter on regex
@@ -261,8 +261,9 @@ end
261261
List the DFGFactors in the DFG.
262262
Optionally specify a label regular expression to retrieves a subset of the factors.
263263
"""
264-
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor}
265-
factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, Graphs.vertices(dfg.g)))
264+
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{DFGFactor}
265+
factors = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGFactor) && (solvable != 0 ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
266+
266267
if regexFilter != nothing
267268
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
268269
end
@@ -281,14 +282,14 @@ end
281282
$(SIGNATURES)
282283
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
283284
"""
284-
function getNeighbors(dfg::GraphsDFG, node::T; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
285+
function getNeighbors(dfg::GraphsDFG, node::T; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
285286
if !haskey(dfg.labelDict, node.label)
286287
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
287288
end
288289
vert = dfg.g.vertices[dfg.labelDict[node.label]]
289290
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
290291
# Additional filtering
291-
neighbors = ready != nothing ? filter(v -> isSolvable(v.dfgNode) >= ready, neighbors) : neighbors
292+
neighbors = solvable != 0 ? filter(v -> solvable <= isSolvable(v.dfgNode), neighbors) : neighbors
292293
neighbors = backendset != nothing ? filter(v -> isSolveInProgress(v.dfgNode) == backendset, neighbors) : neighbors
293294
# Variable sorting (order is important)
294295
if node isa DFGFactor
@@ -302,14 +303,14 @@ end
302303
$(SIGNATURES)
303304
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
304305
"""
305-
function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
306+
function getNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
306307
if !haskey(dfg.labelDict, label)
307308
error("Variable/factor with label '$(label)' does not exist in the factor graph")
308309
end
309310
vert = dfg.g.vertices[dfg.labelDict[label]]
310311
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
311312
# Additional filtering
312-
neighbors = ready != nothing ? filter(v -> isSolvable(v.dfgNode) >= ready, neighbors) : neighbors
313+
neighbors = solvable != 0 ? filter(v -> isSolvable(v.dfgNode) >= solvable, neighbors) : neighbors
313314
neighbors = backendset != nothing ? filter(v -> isSolveInProgress(v.dfgNode) == backendset, neighbors) : neighbors
314315
# Variable sorting when using a factor (function order is important)
315316
if vert.dfgNode isa DFGFactor
@@ -328,7 +329,7 @@ Optionally provide a distance to specify the number of edges should be followed.
328329
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
329330
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.
330331
"""
331-
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}())::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
332+
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}(); solvable::Int=0)::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
332333
if !haskey(dfg.labelDict, node.label)
333334
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
334335
end
@@ -342,7 +343,7 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
342343
for (key, node) in curList
343344
neighbors = in_neighbors(node, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
344345
for neighbor in neighbors
345-
if !haskey(neighborList, neighbor.dfgNode.label)
346+
if !haskey(neighborList, neighbor.dfgNode.label) && (isSolvable(neighbor.dfgNode) >= solvable)
346347
push!(neighborList, neighbor.dfgNode.label => neighbor)
347348
push!(newNeighbors, neighbor.dfgNode.label => neighbor)
348349
end

src/LightDFG/services/LightDFG.jl

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,16 @@ end
194194
List the DFGVariables in the DFG.
195195
Optionally specify a label regular expression to retrieves a subset of the variables.
196196
"""
197-
function getVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{AbstractDFGVariable}
197+
function getVariables(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{AbstractDFGVariable}
198198

199199
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
200200
variables = collect(values(dfg.g.variables))
201201
if regexFilter != nothing
202202
variables = filter(v -> occursin(regexFilter, String(v.label)), variables)
203203
end
204+
if solvable != 0
205+
variables = filter(v -> _isSolvable(dfg, v.label, solvable), variables)
206+
end
204207
if length(tags) > 0
205208
mask = map(v -> length(intersect(v.tags, tags)) > 0, variables )
206209
return variables[mask]
@@ -223,14 +226,15 @@ Related
223226
ls
224227
"""
225228

226-
function getVariableIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{Symbol}
229+
function getVariableIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[], solvable::Int=0)::Vector{Symbol}
227230

228231
# variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, vertices(dfg.g)))
229232
if length(tags) > 0
230-
return map(v -> v.label, getVariables(dfg, regexFilter, tags=tags))
233+
return map(v -> v.label, getVariables(dfg, regexFilter, tags=tags, solvable=solvable))
231234
else
232235
variables = collect(keys(dfg.g.variables))
233236
regexFilter != nothing && (variables = filter(v -> occursin(regexFilter, String(v)), variables))
237+
solvable != 0 && (variables = filter(vId -> _isSolvable(dfg, vId, solvable), variables))
234238
return variables
235239
end
236240
end
@@ -240,12 +244,15 @@ end
240244
List the DFGFactors in the DFG.
241245
Optionally specify a label regular expression to retrieves a subset of the factors.
242246
"""
243-
function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{AbstractDFGFactor}
247+
function getFactors(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{AbstractDFGFactor}
244248
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
245249
factors = collect(values(dfg.g.factors))
246250
if regexFilter != nothing
247251
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
248252
end
253+
if solvable != 0
254+
factors = filter(f -> _isSolvable(dfg, f.label, solvable), factors)
255+
end
249256
return factors
250257
end
251258

@@ -254,12 +261,15 @@ end
254261
Get a list of the IDs of the DFGFactors in the DFG.
255262
Optionally specify a label regular expression to retrieves a subset of the factors.
256263
"""
257-
function getFactorIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{Symbol}
264+
function getFactorIds(dfg::LightDFG, regexFilter::Union{Nothing, Regex}=nothing; solvable::Int=0)::Vector{Symbol}
258265
# factors = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGFactor, vertices(dfg.g)))
259266
factors = collect(keys(dfg.g.factors))
260267
if regexFilter != nothing
261268
factors = filter(f -> occursin(regexFilter, String(f)), factors)
262269
end
270+
if solvable != 0
271+
factors = filter(fId -> _isSolvable(dfg, fId, solvable), factors)
272+
end
263273
return factors
264274
end
265275

@@ -271,7 +281,7 @@ function isFullyConnected(dfg::LightDFG)::Bool
271281
return length(LightGraphs.connected_components(dfg.g)) == 1
272282
end
273283

274-
function _isready(dfg::LightDFG, label::Symbol, ready::Int)::Bool
284+
function _isSolvable(dfg::LightDFG, label::Symbol, ready::Int)::Bool
275285

276286
haskey(dfg.g.variables, label) && (return dfg.g.variables[label].solvable >= ready)
277287
haskey(dfg.g.factors, label) && (return dfg.g.factors[label].solvable >= ready)
@@ -294,7 +304,7 @@ end
294304
$(SIGNATURES)
295305
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
296306
"""
297-
function getNeighbors(dfg::LightDFG, node::DFGNode; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
307+
function getNeighbors(dfg::LightDFG, node::DFGNode; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
298308
label = node.label
299309
if !exists(dfg, label)
300310
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
@@ -303,7 +313,7 @@ function getNeighbors(dfg::LightDFG, node::DFGNode; ready::Union{Nothing, Int}=n
303313
neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
304314
neighbors_ll = [dfg.g.labels[i] for i in neighbors_il]
305315
# Additional filtering
306-
ready != nothing && filter!(lbl -> _isready(dfg, lbl, ready), neighbors_ll)
316+
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
307317
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
308318

309319
# Variable sorting (order is important)
@@ -320,15 +330,15 @@ end
320330
$(SIGNATURES)
321331
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
322332
"""
323-
function getNeighbors(dfg::LightDFG, label::Symbol; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
333+
function getNeighbors(dfg::LightDFG, label::Symbol; solvable::Int=0, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol}
324334
if !exists(dfg, label)
325335
error("Variable/factor with label '$(label)' does not exist in the factor graph")
326336
end
327337

328338
neighbors_il = FactorGraphs.outneighbors(dfg.g, dfg.g.labels[label])
329339
neighbors_ll = [dfg.g.labels[i] for i in neighbors_il]
330340
# Additional filtering
331-
ready != nothing && filter!(lbl -> _isready(dfg, lbl, ready), neighbors_ll)
341+
solvable != 0 && filter!(lbl -> _isSolvable(dfg, lbl, solvable), neighbors_ll)
332342
backendset != nothing && filter!(lbl -> _isbackendset(dfg, lbl, backendset), neighbors_ll)
333343

334344
# Variable sorting (order is important)
@@ -385,13 +395,15 @@ Optionally provide a distance to specify the number of edges should be followed.
385395
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
386396
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.
387397
"""
388-
function getSubgraphAroundNode(dfg::LightDFG{P,V,F}, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}())::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
398+
function getSubgraphAroundNode(dfg::LightDFG{P,V,F}, node::DFGNode, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::LightDFG=LightDFG{P,V,F}(); solvable::Int=0)::LightDFG where {P <: AbstractParams, V <: AbstractDFGVariable, F <: AbstractDFGFactor}
389399
if !exists(dfg,node.label)
390400
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
391401
end
392402

393403
# Get a list of all unique neighbors inside 'distance'
394404
ns = neighborhood(dfg.g, dfg.g.labels[node.label], distance)
405+
# Always return the center node, skip that if we're filtering.
406+
solvable != 0 && (filter!(id -> _isSolvable(dfg, dfg.g.labels[id], solvable) || dfg.g.labels[id] == node.label, ns))
395407

396408
# Copy the section of graph we want
397409
_copyIntoGraph!(dfg, addToDFG, ns, includeOrphanFactors)
@@ -426,10 +438,10 @@ Get an adjacency matrix for the DFG, returned as a Matrix{Union{Nothing, Symbol}
426438
Rows are all factors, columns are all variables, and each cell contains either nothing or the symbol of the relating factor.
427439
The first row and first column are factor and variable headings respectively.
428440
"""
429-
function getAdjacencyMatrix(dfg::LightDFG)::Matrix{Union{Nothing, Symbol}}
441+
function getAdjacencyMatrix(dfg::LightDFG; solvable::Int=0)::Matrix{Union{Nothing, Symbol}}
430442
#TODO Why does it need to be sorted?
431-
varLabels = sort(collect(keys(dfg.g.variables)))#ort(map(v->v.label, getVariables(dfg)))
432-
factLabels = sort(collect(keys(dfg.g.factors)))#sort(map(f->f.label, getFactors(dfg)))
443+
varLabels = sort(getVariableIds(dfg, solvable=solvable))#ort(map(v->v.label, getVariables(dfg)))
444+
factLabels = sort(getFactorIds(dfg, solvable=solvable))#sort(map(f->f.label, getFactors(dfg)))
433445
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
434446

435447
adjMat = Matrix{Union{Nothing, Symbol}}(nothing, length(factLabels)+1, length(varLabels)+1)
@@ -443,9 +455,9 @@ function getAdjacencyMatrix(dfg::LightDFG)::Matrix{Union{Nothing, Symbol}}
443455
return adjMat
444456
end
445457

446-
function getAdjacencyMatrixSparse(dfg::LightDFG)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
447-
varLabels = collect(keys(dfg.g.variables))
448-
factLabels = collect(keys(dfg.g.factors))
458+
function getAdjacencyMatrixSparse(dfg::LightDFG; solvable::Int=0)::Tuple{LightGraphs.SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
459+
varLabels = getVariableIds(dfg, solvable=solvable)
460+
factLabels = getFactorIds(dfg, solvable=solvable)
449461
varIndex = [dfg.g.labels[s] for s in varLabels]
450462
factIndex = [dfg.g.labels[s] for s in factLabels]
451463

src/SymbolDFG/SymbolDFG.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ using SparseArrays
55
using DocStringExtensions
66

77
import ...DistributedFactorGraphs: AbstractDFG, DFGNode, AbstractParams, NoSolverParams, DFGVariable, DFGFactor
8-
# import DFG functions to exstend
8+
# import DFG functions to extend
99
import ...DistributedFactorGraphs: setSolverParams,
1010
getFactor,
1111
setDescription,

0 commit comments

Comments
 (0)