@@ -69,7 +69,7 @@ isVariable(dfg::CloudGraphsDFG, sym::Symbol)::Bool =
69
69
isFactor (dfg:: CloudGraphsDFG , sym:: Symbol ):: Bool =
70
70
_getNodeCount (dfg. neo4jInstance, [" FACTOR" , dfg. userId, dfg. robotId, dfg. sessionId, String (sym)]) == 1
71
71
72
- function addVariable! (dfg:: CloudGraphsDFG , variable:: DFGVariable ):: Bool
72
+ function addVariable! (dfg:: CloudGraphsDFG , variable:: DFGVariable ):: DFGVariable
73
73
if exists (dfg, variable)
74
74
error (" Variable '$(variable. label) ' already exists in the factor graph" )
75
75
end
@@ -89,10 +89,14 @@ function addVariable!(dfg::CloudGraphsDFG, variable::DFGVariable)::Bool
89
89
# Track insertion
90
90
push! (dfg. addHistory, variable. label)
91
91
92
- return true
92
+ return variable
93
+ end
94
+
95
+ function addFactor! (dfg:: CloudGraphsDFG , factor:: DFGFactor )
96
+ addFactor! (dfg, factor. _variableOrderSymbols, factor)
93
97
end
94
98
95
- function addFactor! (dfg:: CloudGraphsDFG , variables:: Vector{DFGVariable} , factor:: DFGFactor ):: Bool
99
+ function addFactor! (dfg:: CloudGraphsDFG , variables:: Vector{<: DFGVariable} , factor:: DFGFactor ):: DFGFactor
96
100
if exists (dfg, factor)
97
101
error (" Factor '$(factor. label) ' already exists in the factor graph" )
98
102
end
@@ -120,10 +124,10 @@ function addFactor!(dfg::CloudGraphsDFG, variables::Vector{DFGVariable}, factor:
120
124
# Track insertion only for variables
121
125
# push!(dfg.addHistory, factor.label
122
126
123
- return true
127
+ return factor
124
128
end
125
129
126
- function addFactor! (dfg:: CloudGraphsDFG , variableIds:: Vector{Symbol} , factor:: DFGFactor ):: Bool
130
+ function addFactor! (dfg:: CloudGraphsDFG , variableIds:: Vector{Symbol} , factor:: DFGFactor ):: DFGFactor
127
131
variables = map (vId -> getVariable (dfg, vId), variableIds)
128
132
return addFactor! (dfg, variables, factor)
129
133
end
187
191
188
192
function updateVariable! (dfg:: CloudGraphsDFG , variable:: DFGVariable ):: DFGVariable
189
193
if ! exists (dfg, variable)
190
- error (" Variable label '$(variable. label) ' does not exist in the factor graph" )
194
+ @warn " Variable label '$(variable. label) ' does not exist in the factor graph, adding"
195
+ return addVariable! (dfg, variable)
191
196
end
192
197
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, variable. label)
193
198
# Update the node ID
217
222
218
223
function updateFactor! (dfg:: CloudGraphsDFG , factor:: DFGFactor ):: DFGFactor
219
224
if ! exists (dfg, factor)
220
- error (" Factor label '$(factor. label) ' does not exist in the factor graph" )
225
+ @warn " Factor label '$(factor. label) ' does not exist in the factor graph, adding"
226
+ return addFactor! (dfg, factor)
221
227
end
222
228
nodeId = _tryGetNeoNodeIdFromNodeLabel (dfg. neo4jInstance, dfg. userId, dfg. robotId, dfg. sessionId, factor. label)
223
229
# Update the _internalId
316
322
deleteFactor! (dfg:: CloudGraphsDFG , factor:: DFGFactor ):: DFGFactor = deleteFactor! (dfg, factor. label)
317
323
318
324
function getVariables (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable:: Int = 0 ):: Vector{DFGVariable}
319
- variableIds = getVariableIds (dfg, regexFilter, tags= tags, solvable= solvable)
325
+ variableIds = listVariables (dfg, regexFilter, tags= tags, solvable= solvable)
320
326
# TODO : Optimize to use tags in query here!
321
327
variables = map (vId-> getVariable (dfg, vId), variableIds)
322
328
if length (tags) > 0
@@ -326,7 +332,7 @@ function getVariables(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=no
326
332
return variables
327
333
end
328
334
329
- function getVariableIds (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable:: Int = 0 ):: Vector{Symbol}
335
+ function listVariables (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; tags:: Vector{Symbol} = Symbol[], solvable:: Int = 0 ):: Vector{Symbol}
330
336
# Optimized for DB call
331
337
tagsFilter = length (tags) > 0 ? " and " * join (" node:" .* String .(tags), " or " ) : " "
332
338
if regexFilter == nothing
@@ -337,11 +343,11 @@ function getVariableIds(dfg::CloudGraphsDFG, regexFilter::Union{Nothing, Regex}=
337
343
end
338
344
339
345
function getFactors (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable:: Int = 0 ):: Vector{DFGFactor}
340
- factorIds = getFactorIds (dfg, regexFilter, solvable= solvable)
346
+ factorIds = listFactors (dfg, regexFilter, solvable= solvable)
341
347
return map (vId-> getFactor (dfg, vId), factorIds)
342
348
end
343
349
344
- function getFactorIds (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable:: Int = 0 ):: Vector{Symbol}
350
+ function listFactors (dfg:: CloudGraphsDFG , regexFilter:: Union{Nothing, Regex} = nothing ; solvable:: Int = 0 ):: Vector{Symbol}
345
351
# Optimized for DB call
346
352
if regexFilter == nothing
347
353
return _getLabelsFromCyphonQuery (dfg. neo4jInstance, " (node:$(dfg. userId) :$(dfg. robotId) :$(dfg. sessionId) :FACTOR) where node.solvable >= $solvable " )
353
359
function isFullyConnected (dfg:: CloudGraphsDFG ):: Bool
354
360
# If the total number of nodes == total number of distinct connected nodes, then it is fully connected
355
361
# Total nodes
356
- varIds = getVariableIds (dfg)
357
- factIds = getFactorIds (dfg)
362
+ varIds = listVariables (dfg)
363
+ factIds = listFactors (dfg)
358
364
length (varIds) + length (factIds) == 0 && return false
359
365
360
366
# Total connected nodes - thank you Neo4j for 0..* awesomeness!!
@@ -424,8 +430,8 @@ function getSubgraph(dfg::CloudGraphsDFG,
424
430
end
425
431
426
432
function getIncidenceMatrix (dfg:: CloudGraphsDFG ; solvable:: Int = 0 ):: Matrix{Union{Nothing, Symbol}}
427
- varLabels = sort (getVariableIds (dfg, solvable= solvable))
428
- factLabels = sort (getFactorIds (dfg, solvable= solvable))
433
+ varLabels = sort (listVariables (dfg, solvable= solvable))
434
+ factLabels = sort (listFactors (dfg, solvable= solvable))
429
435
vDict = Dict (varLabels .=> [1 : length (varLabels)... ]. + 1 )
430
436
fDict = Dict (factLabels .=> [1 : length (factLabels)... ]. + 1 )
431
437
@@ -454,8 +460,8 @@ function getIncidenceMatrix(dfg::CloudGraphsDFG; solvable::Int=0)::Matrix{Union{
454
460
end
455
461
456
462
function getIncidenceMatrixSparse (dfg:: CloudGraphsDFG ; solvable:: Int = 0 ):: Tuple{SparseMatrixCSC, Vector{Symbol}, Vector{Symbol}}
457
- varLabels = getVariableIds (dfg, solvable= solvable)
458
- factLabels = getFactorIds (dfg, solvable= solvable)
463
+ varLabels = listVariables (dfg, solvable= solvable)
464
+ factLabels = listFactors (dfg, solvable= solvable)
459
465
vDict = Dict (varLabels .=> [1 : length (varLabels)... ])
460
466
fDict = Dict (factLabels .=> [1 : length (factLabels)... ])
461
467
0 commit comments