Skip to content

Commit a2c5f83

Browse files
authored
Merge pull request #219 from JuliaRobotics/master
Release 0.5.1
2 parents 44c403b + 8a4ed78 commit a2c5f83

27 files changed

+408
-800
lines changed

Project.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "DistributedFactorGraphs"
22
uuid = "b5cc3c7e-6572-11e9-2517-99fb8daf2f04"
3-
version = "0.5.0"
3+
version = "0.5.1"
44

55
[deps]
66
Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f"
@@ -13,7 +13,6 @@ Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
1313
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
1414
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
1515
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
16-
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
1716
Neo4j = "d2adbeaf-5838-5367-8a2f-e46d570981db"
1817
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
1918
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
@@ -27,7 +26,6 @@ GraphPlot = "0.3.1, 0.4"
2726
Graphs = "0.10.2, 0.11, 1"
2827
JSON2 = "0.3.1"
2928
LightGraphs = "1.2, 1.3"
30-
MetaGraphs = "^0.6.3"
3129
Neo4j = "2"
3230
Reexport = "0.2, 0.3, 0.4, 0.5, 1"
3331
Requires = "0.5, 0.6, 0.7, 0.8, 0.9, 0.10, 1"

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 41 additions & 216 deletions
Large diffs are not rendered by default.

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ So can make orderProperty = label or id.
4242
"""
4343
function _getLabelsFromCyphonQuery(neo4jInstance::Neo4jInstance, matchCondition::String, orderProperty::String="")::Vector{Symbol}
4444
query = "match $matchCondition return distinct(node.label) $(orderProperty != "" ? "order by node.$orderProperty" : "")";
45+
@debug "[Query] $query"
4546
result = _queryNeo4j(neo4jInstance, query)
4647
nodeIds = map(node -> node["row"][1], result.results[1]["data"])
4748
return Symbol.(nodeIds)

src/DFGPlots/DFGPlots.jl

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ module DFGPlots
22

33
using Colors
44
using LightGraphs
5-
using MetaGraphs
65
using GraphPlot
76
using DocStringExtensions
87
import GraphPlot: gplot
@@ -84,39 +83,6 @@ using Compose
8483
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
8584
```
8685
87-
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
88-
"""
89-
function dfgplot(dfg::DistributedFactorGraphs.MetaGraphsDFG, p::DFGPlotProps = DFGPlotProps())
90-
@info "Deprecated, please use GraphsDFG or LightDFG."
91-
nodesize = [has_prop(dfg.g,i,:factor) ? p.nodesize.fac : p.nodesize.var for i=vertices(dfg.g)]
92-
if p.drawlabels
93-
nodelabel = [has_prop(dfg.g,i,:factor) ? "" : string(get_prop(dfg.g,i,:label)) for i=vertices(dfg.g)]
94-
else
95-
nodelabel = nothing
96-
end
97-
nodefillc = [has_prop(dfg.g,i,:factor) ? p.nodefillc.fac : p.nodefillc.var for i=vertices(dfg.g)]
98-
99-
gplot(dfg.g, nodelabel=nodelabel, nodesize=nodesize, nodefillc=nodefillc, layout=p.layout)
100-
101-
end
102-
103-
"""
104-
$(SIGNATURES)
105-
Plots the structure of the factor graph. GraphPlot must be imported before DistributedFactoGraphs for these functions to be available.
106-
Returns the plot context.
107-
108-
E.g.
109-
```
110-
using GraphPlot
111-
using DistributedFactorGraphs, DistributedFactorGraphs.DFGPlots
112-
# ... Make graph...
113-
# Using GraphViz plotting
114-
dfgplot(fg)
115-
# Save to PDFG
116-
using Compose
117-
draw(PDF("/tmp/graph.pdf", 16cm, 16cm), dfgplot(fg))
118-
```
119-
12086
More information at [GraphPlot.jl](https://github.com/JuliaGraphs/GraphPlot.jl)
12187
"""
12288
function dfgplot(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
@@ -128,11 +94,6 @@ function dfgplot(dfg::AbstractDFG, p::DFGPlotProps = DFGPlotProps())
12894
dfgplot(ldfg, p)
12995
end
13096

131-
function gplot(dfg::DistributedFactorGraphs.MetaGraphsDFG; keyargs...)
132-
@info "Deprecated, please use GraphsDFG or LightDFG."
133-
gplot(dfg.g; keyargs...)
134-
end
135-
13697
function gplot(dfg::LightDFG; keyargs...)
13798
gplot(dfg.g; keyargs...)
13899
end

src/DistributedFactorGraphs.jl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export AbstractParams, NoSolverParams
2121
export DFGNode, DFGVariable, DFGFactor, AbstractDFGVariable, AbstractDFGFactor
2222
export InferenceType, PackedInferenceType, FunctorInferenceType, InferenceVariable, ConvolutionObject
2323
export FunctorSingleton, FunctorPairwise, FunctorPairwiseMinimize
24+
export getMaxPPE, getMeanPPE, getSuggestedPPE
2425
export label, timestamp, tags, estimates, estimate, data, softtype, solverData, getData, solverDataDict, setSolverData, internalId, smallData, bigData
2526
export DFGVariableSummary, DFGFactorSummary, AbstractDFGSummary
2627

@@ -32,7 +33,8 @@ export getUserData, setUserData, getRobotData, setRobotData, getSessionData, set
3233
export pushUserData!, pushRobotData!, pushSessionData!, popUserData!, popRobotData!, popSessionData!
3334

3435
# Services/AbstractDFG Exports
35-
export hasFactor, hasVariable, isInitialized, getFactorFunction, isVariable, isFactor
36+
export isInitialized, getFactorFunction, isVariable, isFactor
37+
export isSolvable, isSolveInProgress
3638
export mergeUpdateVariableSolverData!, mergeUpdateGraphSolverData!
3739

3840
# Solver (IIF) Exports
@@ -85,9 +87,6 @@ include("GraphsDFG/GraphsDFG.jl")
8587
# Include the FilesDFG API.
8688
include("FileDFG/FileDFG.jl")
8789

88-
# Include the LightGraphs.jl (MetaGraphs.jl) API.
89-
include("MetaGraphsDFG/MetaGraphsDFG.jl")
90-
9190
include("SymbolDFG/SymbolDFG.jl")
9291
using .SymbolDFGs
9392

src/GraphsDFG/services/GraphsDFG.jl

Lines changed: 20 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -235,11 +235,20 @@ end
235235
List the DFGVariables in the DFG.
236236
Optionally specify a label regular expression to retrieves a subset of the variables.
237237
"""
238-
function getVariables(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing; tags::Vector{Symbol}=Symbol[])::Vector{DFGVariable}
239-
variables = map(v -> v.dfgNode, filter(n -> n.dfgNode isa DFGVariable, Graphs.vertices(dfg.g)))
238+
function getVariables(dfg::GraphsDFG,
239+
regexFilter::Union{Nothing, Regex}=nothing;
240+
tags::Vector{Symbol}=Symbol[],
241+
solvable::Int=0)::Vector{DFGVariable}
242+
#
243+
variables = map(v -> v.dfgNode, filter(n -> (n.dfgNode isa DFGVariable) && (solvable != 0 ? solvable <= isSolvable(n.dfgNode) : true), Graphs.vertices(dfg.g)))
244+
# filter on solvable
245+
246+
# filter on regex
240247
if regexFilter != nothing
241248
variables = filter(v -> occursin(regexFilter, String(v.label)), variables)
242249
end
250+
251+
# filter on tags
243252
if length(tags) > 0
244253
mask = map(v -> length(intersect(v.tags, tags)) > 0, variables )
245254
return variables[mask]
@@ -252,8 +261,9 @@ end
252261
List the DFGFactors in the DFG.
253262
Optionally specify a label regular expression to retrieves a subset of the factors.
254263
"""
255-
function getFactors(dfg::GraphsDFG, regexFilter::Union{Nothing, Regex}=nothing)::Vector{DFGFactor}
256-
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+
257267
if regexFilter != nothing
258268
factors = filter(f -> occursin(regexFilter, String(f.label)), factors)
259269
end
@@ -272,15 +282,14 @@ end
272282
$(SIGNATURES)
273283
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
274284
"""
275-
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)::Vector{Symbol} where T <: DFGNode
276286
if !haskey(dfg.labelDict, node.label)
277287
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
278288
end
279289
vert = dfg.g.vertices[dfg.labelDict[node.label]]
280290
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
281291
# Additional filtering
282-
neighbors = ready != nothing ? filter(v -> v.dfgNode.ready == ready, neighbors) : neighbors
283-
neighbors = backendset != nothing ? filter(v -> v.dfgNode.backendset == backendset, neighbors) : neighbors
292+
neighbors = solvable != 0 ? filter(v -> solvable <= isSolvable(v.dfgNode), neighbors) : neighbors
284293
# Variable sorting (order is important)
285294
if node isa DFGFactor
286295
order = intersect(node._variableOrderSymbols, map(v->v.dfgNode.label, neighbors))
@@ -293,15 +302,14 @@ end
293302
$(SIGNATURES)
294303
Retrieve a list of labels of the immediate neighbors around a given variable or factor specified by its label.
295304
"""
296-
function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=nothing, backendset::Union{Nothing, Int}=nothing)::Vector{Symbol} where T <: DFGNode
305+
function getNeighbors(dfg::GraphsDFG, label::Symbol; solvable::Int=0)::Vector{Symbol} where T <: DFGNode
297306
if !haskey(dfg.labelDict, label)
298307
error("Variable/factor with label '$(label)' does not exist in the factor graph")
299308
end
300309
vert = dfg.g.vertices[dfg.labelDict[label]]
301310
neighbors = in_neighbors(vert, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
302311
# Additional filtering
303-
neighbors = ready != nothing ? filter(v -> v.dfgNode.ready == ready, neighbors) : neighbors
304-
neighbors = backendset != nothing ? filter(v -> v.dfgNode.backendset == backendset, neighbors) : neighbors
312+
neighbors = solvable != 0 ? filter(v -> isSolvable(v.dfgNode) >= solvable, neighbors) : neighbors
305313
# Variable sorting when using a factor (function order is important)
306314
if vert.dfgNode isa DFGFactor
307315
vert.dfgNode._variableOrderSymbols
@@ -312,49 +320,14 @@ function getNeighbors(dfg::GraphsDFG, label::Symbol; ready::Union{Nothing, Int}=
312320
return map(n -> n.dfgNode.label, neighbors)
313321
end
314322

315-
# function _copyIntoGraph!(sourceDFG::GraphsDFG, destDFG::GraphsDFG, variableFactorLabels::Vector{Symbol}, includeOrphanFactors::Bool=false)::Nothing
316-
# # Split into variables and factors
317-
# verts = map(id -> sourceDFG.g.vertices[sourceDFG.labelDict[id]], variableFactorLabels)
318-
# sourceVariables = filter(n -> n.dfgNode isa DFGVariable, verts)
319-
# sourceFactors = filter(n -> n.dfgNode isa DFGFactor, verts)
320-
#
321-
# # Now we have to add all variables first,
322-
# for variable in sourceVariables
323-
# if !haskey(destDFG.labelDict, variable.dfgNode.label)
324-
# addVariable!(destDFG, deepcopy(variable.dfgNode))
325-
# end
326-
# end
327-
# # And then all factors to the destDFG.
328-
# for factor in sourceFactors
329-
# if !haskey(destDFG.labelDict, factor.dfgNode.label)
330-
# # Get the original factor variables (we need them to create it)
331-
# neighVarIds = getNeighbors(sourceDFG, factor.dfgNode.label) #OLD: in_neighbors(factor, sourceDFG.g)
332-
# # Find the labels and associated neighVarIds in our new subgraph
333-
# factVariables = DFGVariable[]
334-
# for neighVarId in neighVarIds
335-
# if haskey(destDFG.labelDict, neighVarId)
336-
# push!(factVariables, getVariable(destDFG, neighVarId))
337-
# #otherwise ignore
338-
# end
339-
# end
340-
#
341-
# # Only if we have all of them should we add it (otherwise strange things may happen on evaluation)
342-
# if includeOrphanFactors || length(factVariables) == length(neighVarIds)
343-
# addFactor!(destDFG, factVariables, deepcopy(factor.dfgNode))
344-
# end
345-
# end
346-
# end
347-
# return nothing
348-
# end
349-
350323
"""
351324
$(SIGNATURES)
352325
Retrieve a deep subgraph copy around a given variable or factor.
353326
Optionally provide a distance to specify the number of edges should be followed.
354327
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
355328
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.
356329
"""
357-
function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, includeOrphanFactors::Bool=false, addToDFG::GraphsDFG=GraphsDFG{P}())::GraphsDFG where {P <: AbstractParams, T <: DFGNode}
330+
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}
358331
if !haskey(dfg.labelDict, node.label)
359332
error("Variable/factor with label '$(node.label)' does not exist in the factor graph")
360333
end
@@ -368,7 +341,7 @@ function getSubgraphAroundNode(dfg::GraphsDFG{P}, node::T, distance::Int64=1, in
368341
for (key, node) in curList
369342
neighbors = in_neighbors(node, dfg.g) #Don't use out_neighbors! It enforces directiveness even if we don't want it
370343
for neighbor in neighbors
371-
if !haskey(neighborList, neighbor.dfgNode.label)
344+
if !haskey(neighborList, neighbor.dfgNode.label) && (isSolvable(neighbor.dfgNode) >= solvable)
372345
push!(neighborList, neighbor.dfgNode.label => neighbor)
373346
push!(newNeighbors, neighbor.dfgNode.label => neighbor)
374347
end

0 commit comments

Comments
 (0)