Skip to content

Commit b7f496f

Browse files
committed
isFullyConnected and hasOrphans
1 parent 64a6c07 commit b7f496f

File tree

2 files changed

+37
-41
lines changed

2 files changed

+37
-41
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -619,21 +619,33 @@ function getFactorIds(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=no
619619
end
620620
end
621621

622-
# """
623-
# $(SIGNATURES)
624-
# Checks if the graph is fully connected, returns true if so.
625-
# """
626-
# function isFullyConnected(dfg::CloudGraphsDFG)::Bool
627-
# return length(connected_components(dfg.g)) == 1
628-
# end
629-
#
630-
# #Alias
631-
# """
632-
# $(SIGNATURES)
633-
# Checks if the graph is not fully connected, returns true if it is not contiguous.
634-
# """
635-
# hasOrphans(dfg::CloudGraphsDFG)::Bool = !isFullyConnected(dfg)
636-
#
622+
"""
623+
$(SIGNATURES)
624+
Checks if the graph is fully connected, returns true if so.
625+
"""
626+
function isFullyConnected(dfg::CloudGraphsDFG)::Bool
627+
# If the total number of nodes == total number of distinct connected nodes, then it is fully connected
628+
# Total nodes
629+
varIds = getVariableIds(dfg)
630+
factIds = getFactorIds(dfg)
631+
totalNodes = length(varIds) + length(factIds)
632+
if length(varIds) == 0
633+
return false
634+
end
635+
636+
# Total connected nodes - thank you Neo4j for 0..* awesomeness!!
637+
connectedList = _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(varIds[1]))-[FACTORGRAPH*]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))")
638+
639+
return length(connectedList) == totalNodes
640+
end
641+
642+
#Alias
643+
"""
644+
$(SIGNATURES)
645+
Checks if the graph is not fully connected, returns true if it is not contiguous.
646+
"""
647+
hasOrphans(dfg::CloudGraphsDFG)::Bool = !isFullyConnected(dfg)
648+
637649
"""
638650
$(SIGNATURES)
639651
Retrieve a list of labels of the immediate neighbors around a given variable or factor.
@@ -745,7 +757,7 @@ function getSubgraphAroundNode(dfg::CloudGraphsDFG, node::T, distance::Int64=1,
745757
end
746758

747759
# Thank you Neo4j for 0..* awesomeness!!
748-
neighborList = _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))-[FACTORGRAPH*0..$distance]-(node)")
760+
neighborList = _getLabelsFromCyphonQuery(dfg.neo4jInstance, "(n:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId):$(node.label))-[FACTORGRAPH*0..$distance]-(node:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))")
749761

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

test/sandbox.jl

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -190,31 +190,15 @@ global cgDFG = CloudGraphsDFG("localhost", 7474, "neo4j", "test",
190190
@test adjMat == expected
191191
end
192192

193+
@testset "isFullyConnected, hasOrphans tests" begin
194+
@test isFullyConnected(cgDFG) == true
195+
@test hasOrphans(cgDFG) == false
196+
197+
# Now let's add an orphan
198+
lOrphan = addVariable!(cgDFG, :lOrphan, Pose2)
199+
@test isFullyConnected(cgDFG) == false
200+
@test hasOrphans(cgDFG) == true
201+
end
193202

194203
# Show it
195204
DFG.toDotFile(dfg, "/tmp/testRmMarg.dot")
196-
197-
198-
# ##### Testing
199-
newFactor = DFGFactor{CommonConvWrapper{typeof(prior)}, Symbol}(Symbol("x0f0"))
200-
# # newFactor.tags = union([:abc], [:FACTOR]) # TODO: And session info
201-
# # addNewFncVertInGraph!(fgl, newvert, currid, namestring, ready)
202-
ccw = IncrementalInference.prepgenericconvolution([x1], prior, multihypo=nothing, threadmodel=SingleThreaded)
203-
data_ccw = FunctionNodeData{CommonConvWrapper{typeof(prior)}}(Int[], false, false, Int[], Symbol(:test), ccw)
204-
newData = IncrementalInference.setDefaultFactorNode!(cgDFG, newFactor, [x1], deepcopy(prior), multihypo=nothing, threadmodel=SingleThreaded)
205-
# packedType = encodePackedType(newData)
206-
# #Testing
207-
fnctype = newData.fnc.usrfnc!
208-
fnc = getfield(IncrementalInference.getmodule(fnctype), Symbol("Packed$(IncrementalInference.getname(fnctype))"))
209-
packed = convert(PackedFunctionNodeData{fnc}, newData)
210-
using JSON2
211-
j = JSON2.write(packed)
212-
retPacked = JSON2.read(j, GenericFunctionNodeData{PackedPriorPose2,String})
213-
# retUnpacked = convert(GenericFunctionNodeData{IncrementalInference.getname(fnctype)}, retPacked)
214-
retUnpacked = convert(PriorPose2, retPacked.fnc)
215-
# # TODO: Need to remove this...
216-
# for vert in Xi
217-
# push!(newData.fncargvID, vert.label) # vert._internalId # YUCK :/ -- Yup, this is a problem
218-
# end
219-
#
220-
#

0 commit comments

Comments
 (0)