Skip to content

Commit 50ab7ac

Browse files
authored
Merge pull request #635 from JuliaRobotics/feat/20Q3/skeletonfromcloud
SkeletonDFG constructor from CGDFG and use it to patch connectivity bug
2 parents f353069 + 749db8a commit 50ab7ac

File tree

2 files changed

+46
-24
lines changed

2 files changed

+46
-24
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -418,24 +418,25 @@ function listFactors(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=not
418418
end
419419

420420
function isConnected(dfg::CloudGraphsDFG)::Bool
421-
# If the total number of nodes == total number of distinct connected nodes, then it is fully connected
422-
# Total nodes
423-
varIds = listVariables(dfg)
424-
factIds = listFactors(dfg)
425-
length(varIds) + length(factIds) == 0 && return false
426-
427-
# Total distinct connected nodes - thank you Neo4j for 0..* awesomeness!!
428-
# TODO: Deprecated matching technique and it's technically an expensive call - optimize.
429-
query = """
430-
match (n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(varIds[1]))-[FACTORGRAPH*]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))
431-
WHERE (n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR) and not (node:SESSION or n:SESSION) and not (n:PPE) and not (node:PPE)
432-
WITH collect(n)+collect(node) as nodelist
433-
unwind nodelist as nodes
434-
return count(distinct nodes)"""
435-
@debug "[Query] $query"
436-
result = _queryNeo4j(dfg.neo4jInstance, query)
437-
# Neo4j.jl data structure sometimes feels brittle... like below
438-
return result.results[1]["data"][1]["row"][1] == length(varIds) + length(factIds)
421+
# # If the total number of nodes == total number of distinct connected nodes, then it is fully connected
422+
# # Total nodes
423+
# varIds = listVariables(dfg)
424+
# factIds = listFactors(dfg)
425+
# length(varIds) + length(factIds) == 0 && return false
426+
427+
# # Total distinct connected nodes - thank you Neo4j for 0..* awesomeness!!
428+
# # TODO: Deprecated matching technique and it's technically an expensive call - optimize.
429+
# query = """
430+
# match (n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(varIds[1]))-[FACTORGRAPH*]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))
431+
# WHERE (n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR) and not (node:SESSION or n:SESSION) and not (n:PPE) and not (node:PPE)
432+
# WITH collect(n)+collect(node) as nodelist
433+
# unwind nodelist as nodes
434+
# return count(distinct nodes)"""
435+
# @debug "[Query] $query"
436+
# result = _queryNeo4j(dfg.neo4jInstance, query)
437+
# # Neo4j.jl data structure sometimes feels brittle... like below
438+
# return result.results[1]["data"][1]["row"][1] == length(varIds) + length(factIds)
439+
return isConnected(SkeletonDFG(dfg))
439440
end
440441

441442
function getNeighbors(dfg::CloudGraphsDFG, node::T; solvable::Int=0)::Vector{Symbol} where T <: DFGNode
@@ -943,3 +944,28 @@ function emptyTags!(dfg::CloudGraphsDFG, sym::Symbol)
943944
return getTags(getNode(dfg, sym))
944945

945946
end
947+
948+
949+
##==============================================================================
950+
## Skeleton DFG Constructor
951+
##==============================================================================
952+
# TODO tags
953+
function _getSkeletonFactors(dfg::CloudGraphsDFG)
954+
neo4jInstance = dfg.neo4jInstance
955+
query = "match (node:$(join(_getLabelsForType(dfg, DFGFactor),':'))) return distinct(node.label),node._variableOrderSymbols"
956+
result = _queryNeo4j(neo4jInstance, query)
957+
facs = map(node -> SkeletonDFGFactor(Symbol(node["row"][1]),Symbol.(node["row"][2])), result.results[1]["data"])
958+
return facs
959+
end
960+
# TODO tags
961+
function _getSkeletonVariables(dfg::CloudGraphsDFG)
962+
return SkeletonDFGVariable.(ls(dfg))
963+
end
964+
965+
export SkeletonDFG
966+
function SkeletonDFG(cfg::CloudGraphsDFG)
967+
sfg = LightDFG{NoSolverParams, SkeletonDFGVariable, SkeletonDFGFactor}()
968+
addVariable!.(sfg, _getSkeletonVariables(cfg))
969+
addFactor!.(sfg, _getSkeletonFactors(cfg))
970+
return sfg
971+
end

test/interfaceTests.jl

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,8 @@ end
170170
end
171171

172172
@testset "Connectivity Test" begin
173-
if testDFGAPI != CloudGraphsDFG
174-
rand(5)
175-
ConnectivityTest(testDFGAPI)
176-
else
177-
@warn "CloudGraphsDFG is currently failing with the connectivity test."
178-
end
173+
rand(5)
174+
ConnectivityTest(testDFGAPI)
179175
end
180176

181177

0 commit comments

Comments
 (0)