Skip to content

Commit 3deb874

Browse files
committed
Fixing isFullyConnected
1 parent 3956990 commit 3deb874

File tree

3 files changed

+36
-40
lines changed

3 files changed

+36
-40
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -632,15 +632,19 @@ function isFullyConnected(dfg::CloudGraphsDFG)::Bool
632632
# Total nodes
633633
varIds = getVariableIds(dfg)
634634
factIds = getFactorIds(dfg)
635-
totalNodes = length(varIds) + length(factIds)
636-
if length(varIds) == 0
637-
return false
638-
end
635+
length(varIds) + length(factIds) == 0 && return false
639636

640637
# Total connected nodes - thank you Neo4j for 0..* awesomeness!!
641-
connectedList = _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(varIds[1]))-[FACTORGRAPH*]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))")
642-
643-
return length(connectedList) == totalNodes
638+
query = """
639+
match (n:testUser:testRobot:sandbox:a)-[FACTORGRAPH*]-(node:testUser:testRobot:sandbox)
640+
WHERE n:VARIABLE OR n:FACTOR OR node:VARIABLE OR node:FACTOR
641+
WITH collect(n)+collect(node) as nodelist
642+
unwind nodelist as nodes
643+
return count(distinct nodes)"""
644+
@debug "[Querying] $query"
645+
result = _queryNeo4j(dfg.neo4jInstance, query)
646+
# Neo4j.jl data structure sometimes feels brittle... like below
647+
return result.results[1]["data"][1]["row"][1] == length(varIds) + length(factIds)
644648
end
645649

646650
#Alias

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,21 @@
11
alphaOnlyMatchRegex = r"^[a-zA-Z0-9_]*$"
22

3+
"""
4+
$(SIGNATURES)
5+
Returns the transaction for a given query.
6+
NOTE: Must commit(transaction) after you're done.
7+
"""
8+
function _queryNeo4j(neo4jInstance::Neo4jInstance, query::String)
9+
loadtx = transaction(neo4jInstance.connection)
10+
result = loadtx(query; submit=true)
11+
if length(result.errors) > 0
12+
error(string(result.errors))
13+
end
14+
# Have to finish the transaction
15+
commit(loadtx)
16+
return result
17+
end
18+
319
"""
420
$(SIGNATURES)
521
Returns the list of CloudGraph nodes that matches the Cyphon query.
@@ -11,16 +27,9 @@ If orderProperty is not ==, then 'order by n.{orderProperty} will be appended to
1127
So can make orderProperty = label or id.
1228
"""
1329
function _getLabelsFromCyphonQuery(neo4jInstance::Neo4jInstance, matchCondition::String, orderProperty::String="")::Vector{Symbol}
14-
# 2. Perform the transaction
15-
loadtx = transaction(neo4jInstance.connection)
1630
query = "match $matchCondition return distinct(node.label) $(orderProperty != "" ? "order by node.$orderProperty" : "")";
17-
nodes = loadtx(query; submit=true)
18-
if length(nodes.errors) > 0
19-
error(string(nodes.errors))
20-
end
21-
nodeIds = map(node -> node["row"][1], nodes.results[1]["data"])
22-
# Have to finish the transaction
23-
commit(loadtx)
31+
result = _queryNeo4j(neo4jInstance, query)
32+
nodeIds = map(node -> node["row"][1], result.results[1]["data"])
2433
return Symbol.(nodeIds)
2534
end
2635

test/sandbox.jl

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ using Neo4j
33
using DistributedFactorGraphs
44
using IncrementalInference
55
using Test
6+
using Logging
7+
# Debug logging
8+
logger = SimpleLogger(stdout, Logging.Debug)
9+
global_logger(logger)
610

711
dfg = CloudGraphsDFG{SolverParams}("localhost", 7474, "neo4j", "test",
8-
"testUser", "testRobot", "testSession",
12+
"testUser", "testRobot", "sandbox",
913
nothing,
1014
nothing,
1115
IncrementalInference.decodePackedType,
@@ -16,30 +20,9 @@ v1 = addVariable!(dfg, :a, ContinuousScalar, labels = [:POSE])
1620
v2 = addVariable!(dfg, :b, ContinuousScalar, labels = [:LANDMARK])
1721
f1 = addFactor!(dfg, [:a; :b], LinearConditional(Normal(50.0,2.0)) )
1822
v1 == deepcopy(v1)
23+
v1 == getVariable(dfg, :a)
1924

20-
function al(a, b)
21-
a.label != b.label && return false
22-
a.timestamp != b.timestamp && return false
23-
a.tags != b.tags && return false
24-
symdiff(keys(a.estimateDict), keys(b.estimateDict)) != Set(Symbol[]) && return false
25-
for k in keys(a.estimateDict)
26-
a.estimateDict[k] != b.estimateDict[k] && return false
27-
end
28-
symdiff(keys(a.solverDataDict), keys(b.solverDataDict)) != Set(Symbol[]) && return false
29-
for k in keys(a.solverDataDict)
30-
a.solverDataDict[k] != b.solverDataDict[k] && return false
31-
end
32-
return true
33-
end
34-
al(a, b)
35-
a = v1
36-
b = deepcopy(v1)
37-
38-
a.smallData != b.smallData && return false
39-
a.bigData != b.bigData && return false
40-
a.ready != b.ready && return false
41-
a.backendset != b.backendset && return false
42-
a._internalId != b._internalId && return false
25+
isFullyConnected(dfg)
4326

4427
T = typeof(dfg)
4528
if T <: CloudGraphsDFG

0 commit comments

Comments
 (0)