Skip to content

Commit b4f26ac

Browse files
authored
Update cloud biadjacency (#282)
1 parent dc7504d commit b4f26ac

File tree

2 files changed

+5
-37
lines changed

2 files changed

+5
-37
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -429,37 +429,12 @@ function getSubgraph(dfg::CloudGraphsDFG,
429429
return addToDFG
430430
end
431431

432-
function getIncidenceMatrix(dfg::CloudGraphsDFG; solvable::Int=0)::Matrix{Union{Nothing, Symbol}}
433-
varLabels = sort(listVariables(dfg, solvable=solvable))
434-
factLabels = sort(listFactors(dfg, solvable=solvable))
435-
vDict = Dict(varLabels .=> [1:length(varLabels)...].+1)
436-
fDict = Dict(factLabels .=> [1:length(factLabels)...].+1)
432+
#NOTE removed, exists in abstract as getAdjacencyMatrixSymbols and likeley to be removed entirely
433+
# function getAdjacencyMatrix(dfg::CloudGraphsDFG; solvable::Int=0)::Matrix{Union{Nothing, Symbol}}
437434

438-
adjMat = Matrix{Union{Nothing, Symbol}}(nothing, length(factLabels)+1, length(varLabels)+1)
439-
# Set row/col headings
440-
adjMat[2:end, 1] = factLabels
441-
adjMat[1, 2:end] = varLabels
442435

443-
# Now ask for all relationships for this session graph
444-
loadtx = transaction(dfg.neo4jInstance.connection)
445-
query = "START n=node(*) MATCH (n:VARIABLE:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId))-[r:FACTORGRAPH]-(m:FACTOR:$(dfg.userId):$(dfg.robotId):$(dfg.sessionId)) where n.solvable >= $solvable and m.solvable >= $solvable RETURN n.label as variable, m.label as factor;"
446-
nodes = loadtx(query; submit=true)
447-
# Have to finish the transaction
448-
commit(loadtx)
449-
if length(nodes.errors) > 0
450-
error(string(nodes.errors))
451-
end
452-
# Add in the relationships
453-
varRel = Symbol.(map(node -> node["row"][1], nodes.results[1]["data"]))
454-
factRel = Symbol.(map(node -> node["row"][2], nodes.results[1]["data"]))
455-
for i = 1:length(varRel)
456-
adjMat[fDict[factRel[i]], vDict[varRel[i]]] = factRel[i]
457-
end
458-
459-
return adjMat
460-
end
461436

462-
function getIncidenceMatrixSparse(dfg::CloudGraphsDFG; solvable::Int=0)::Tuple{SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
437+
function getBiadjacencyMatrix(dfg::CloudGraphsDFG; solvable::Int=0)::NamedTuple{(:B, :varLabels, :facLabels),Tuple{SparseMatrixCSC,Vector{Symbol}, Vector{Symbol}}}
463438
varLabels = listVariables(dfg, solvable=solvable)
464439
factLabels = listFactors(dfg, solvable=solvable)
465440
vDict = Dict(varLabels .=> [1:length(varLabels)...])
@@ -484,5 +459,5 @@ function getIncidenceMatrixSparse(dfg::CloudGraphsDFG; solvable::Int=0)::Tuple{S
484459
adjMat[fDict[factRel[i]], vDict[varRel[i]]] = 1
485460
end
486461

487-
return adjMat, varLabels, factLabels
462+
return (B=adjMat, varLabels=varLabels, facLabels=factLabels)
488463
end

src/LightDFG/services/LightDFG.jl

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -317,9 +317,7 @@ function getSubgraph(dfg::LightDFG{P,V,F}, variableFactorLabels::Vector{Symbol},
317317
end
318318

319319

320-
#TODO This is just way too strange to call a function getIncidenceMatrix that calls adjacency_matrix internally,
321-
# So I'm going with Biadjacency Matrix https://en.wikipedia.org/wiki/Adjacency_matrix#Of_a_bipartite_graph
322-
# TODO biadjacencyMatrix
320+
# Biadjacency Matrix https://en.wikipedia.org/wiki/Adjacency_matrix#Of_a_bipartite_graph
323321
function getBiadjacencyMatrix(dfg::LightDFG; solvable::Int=0)::NamedTuple{(:B, :varLabels, :facLabels),Tuple{LightGraphs.SparseMatrixCSC,Vector{Symbol}, Vector{Symbol}}}
324322
varLabels = listVariables(dfg, solvable=solvable)
325323
factLabels = listFactors(dfg, solvable=solvable)
@@ -332,11 +330,6 @@ function getBiadjacencyMatrix(dfg::LightDFG; solvable::Int=0)::NamedTuple{(:B, :
332330
return (B=adjvf, varLabels=varLabels, facLabels=factLabels)
333331
end
334332

335-
# this would be an incidence matrix
336-
function getIncidenceMatrix(dfg::LightDFG)
337-
return incidence_matrix(dfg.g)
338-
end
339-
340333
"""
341334
$(SIGNATURES)
342335
Gets an empty and unique LightDFG derived from an existing DFG.

0 commit comments

Comments
 (0)