@@ -63,8 +63,8 @@ getDescription(dfg::CloudGraphsDFG) = dfg.description
63
63
setDescription (dfg:: CloudGraphsDFG , description:: String ) = dfg. description = description
64
64
getAddHistory (dfg:: CloudGraphsDFG ) = dfg. addHistory
65
65
getSolverParams (dfg:: CloudGraphsDFG ) = dfg. solverParams
66
- function setSolverParams (dfg:: CloudGraphsDFG , solverParams:: T ) where T <: AbstractParams
67
- dfg. solverParams = solverParams
66
+ function setSolverParams (dfg:: CloudGraphsDFG , solverParams:: T ):: T where T <: AbstractParams
67
+ return dfg. solverParams = solverParams
68
68
end
69
69
70
70
"""
@@ -255,7 +255,7 @@ function getVariable(dfg::CloudGraphsDFG, variableId::Int64)::DFGVariable
255
255
# props["label"] = Symbol(variable.label)
256
256
timestamp = DateTime (props[" timestamp" ])
257
257
tags = JSON2. read (props[" tags" ], Vector{Symbol})
258
- estimateDict = JSON2. read (props[" estimateDict" ], Dict{Symbol, VariableEstimate})
258
+ estimateDict = JSON2. read (props[" estimateDict" ], Dict{Symbol, Dict{Symbol, VariableEstimate} })
259
259
smallData = nothing
260
260
smallData = JSON2. read (props[" smallData" ], Dict{String, String})
261
261
@@ -389,6 +389,20 @@ function updateVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::DFGVariabl
389
389
return variable
390
390
end
391
391
392
+ """
393
+ $(SIGNATURES)
394
+ Update solver and estimate data for a variable (variable can be from another graph).
395
+ """
396
+ function updateVariableSolverData! (dfg:: CloudGraphsDFG , sourceVariable:: DFGVariable ):: DFGVariable
397
+ if ! exists (dfg, sourceVariable)
398
+ error (" Source variable '$(sourceVariable. label) ' doesn't exist in the graph." )
399
+ end
400
+ nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, sourceVariable. label)
401
+ Neo4j. setnodeproperty (dfg. neo4jInstance. graph, nodeId, " estimateDict" , JSON2. write (sourceVariable. estimateDict))
402
+ Neo4j. setnodeproperty (dfg. neo4jInstance. graph, nodeId, " solverDataDict" , JSON2. write (Dict (keys (sourceVariable. solverDataDict) .=> map (vnd -> pack (dfg, vnd), values (sourceVariable. solverDataDict)))))
403
+ return sourceVariable
404
+ end
405
+
392
406
"""
393
407
$(SIGNATURES)
394
408
Update a complete DFGFactor in the DFG.
@@ -704,25 +718,11 @@ Optionally provide a distance to specify the number of edges should be followed.
704
718
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
705
719
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.
706
720
"""
707
- function getSubgraphAroundNode (dfg:: CloudGraphsDFG , node:: DFGNode , distance:: Int64 = 1 , includeOrphanFactors:: Bool = false , addToDFG:: Union{Nothing, CloudGraphsDFG} = nothing ) :: CloudGraphsDFG
721
+ function getSubgraphAroundNode (dfg:: CloudGraphsDFG , node:: DFGNode , distance:: Int64 = 1 , includeOrphanFactors:: Bool = false , addToDFG:: AbstractDFG = _getDuplicatedEmptyDFG (dfg)) :: AbstractDFG
708
722
distance < 1 && error (" getSubgraphAroundNode() only works for distance > 0" )
709
723
710
724
# Making a copy session if not specified
711
- if addToDFG == nothing
712
- addToDFG = _getDuplicatedEmptyDFG (dfg)
713
- end
714
-
715
- # Thank you Neo4j for 0..* awesomeness!!
716
- neighborList = _getLabelsFromCyphonQuery (dfg. neo4jInstance, " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )-[FACTORGRAPH*0..$distance ]-(node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) )" )
717
-
718
- # Copy the section of graph we want
719
- _copyIntoGraph! (dfg, addToDFG, neighborList, includeOrphanFactors)
720
- return addToDFG
721
- end
722
-
723
- function getSubgraphAroundNode (dfg:: CloudGraphsDFG{<:AbstractParams} , node:: DFGNode , distance:: Int64 , includeOrphanFactors:: Bool , addToDFG:: MetaGraphsDFG{AbstractParams} ):: AbstractDFG
724
- distance < 1 && error (" getSubgraphAroundNode() only works for distance > 0" )
725
-
725
+ # moved to parameter addToDFG::AbstractDFG=_getDuplicatedEmptyDFG(dfg)
726
726
727
727
# Thank you Neo4j for 0..* awesomeness!!
728
728
neighborList = _getLabelsFromCyphonQuery (dfg. neo4jInstance, " (n:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :$(node. label) )-[FACTORGRAPH*0..$distance ]-(node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) )" )
@@ -739,11 +739,11 @@ Get a deep subgraph copy from the DFG given a list of variables and factors.
739
739
Optionally provide an existing subgraph addToDFG, the extracted nodes will be copied into this graph. By default a new subgraph will be created.
740
740
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.
741
741
"""
742
- function getSubgraph (dfg:: CloudGraphsDFG , variableFactorLabels:: Vector{Symbol} , includeOrphanFactors:: Bool = false , addToDFG:: Union{Nothing, CloudGraphsDFG} = nothing ):: CloudGraphsDFG
742
+ function getSubgraph (dfg:: CloudGraphsDFG ,
743
+ variableFactorLabels:: Vector{Symbol} ,
744
+ includeOrphanFactors:: Bool = false ,
745
+ addToDFG:: G = _getDuplicatedEmptyDFG (dfg) ):: G where {G <: AbstractDFG }
743
746
# Making a copy session if not specified
744
- if addToDFG == nothing
745
- addToDFG = _getDuplicatedEmptyDFG (dfg)
746
- end
747
747
748
748
_copyIntoGraph! (dfg, addToDFG, variableFactorLabels, includeOrphanFactors)
749
749
@@ -787,6 +787,33 @@ function getAdjacencyMatrix(dfg::CloudGraphsDFG)::Matrix{Union{Nothing, Symbol}}
787
787
return adjMat
788
788
end
789
789
790
+ function getAdjacencyMatrixSparse (dfg:: CloudGraphsDFG ):: Tuple{SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
791
+ varLabels = getVariableIds (dfg)
792
+ factLabels = sort (getFactorIds (dfg))
793
+ vDict = Dict (varLabels .=> [1 : length (varLabels)... ]. + 1 )
794
+ fDict = Dict (factLabels .=> [1 : length (factLabels)... ]. + 1 )
795
+
796
+ adjMat = spzeros (Int, length (factLabels)+ 1 , length (varLabels)+ 1 )
797
+
798
+ # Now ask for all relationships for this session graph
799
+ loadtx = transaction (dfg. neo4jInstance. connection)
800
+ query = " START n=node(*) MATCH (n:VARIABLE:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) )-[r:FACTORGRAPH]-(m:FACTOR:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) ) RETURN n.label as variable, m.label as factor;"
801
+ nodes = loadtx (query; submit= true )
802
+ # Have to finish the transaction
803
+ commit (loadtx)
804
+ if length (nodes. errors) > 0
805
+ error (string (nodes. errors))
806
+ end
807
+ # Add in the relationships
808
+ varRel = Symbol .(map (node -> node[" row" ][1 ], nodes. results[1 ][" data" ]))
809
+ factRel = Symbol .(map (node -> node[" row" ][2 ], nodes. results[1 ][" data" ]))
810
+ for i = 1 : length (varRel)
811
+ adjMat[fDict[factRel[i]], vDict[varRel[i]]] = 1
812
+ end
813
+
814
+ return adjMat, varLabels, factLabels
815
+ end
816
+
790
817
# """
791
818
# $(SIGNATURES)
792
819
# Produces a dot-format of the graph for visualization.
0 commit comments