@@ -540,14 +540,18 @@ end
540
540
# ## Updated functions from AbstractDFG
541
541
# ## These functions write back as you add the data.
542
542
543
- function addVariableSolverData! (dfg:: CloudGraphsDFG , variablekey:: Symbol , vnd:: VariableNodeData , solvekey:: Symbol = :default ):: VariableNodeData
543
+ function addVariableSolverData! (dfg:: CloudGraphsDFG ,
544
+ variablekey:: Symbol ,
545
+ vnd:: VariableNodeData ,
546
+ solvekey:: Symbol = :default ):: VariableNodeData
544
547
# TODO : Switch out to their own nodes, don't get the whole variable
545
548
var = getVariable (dfg, variablekey)
546
549
if haskey (var. solverDataDict, solvekey)
547
550
error (" VariableNodeData '$(solvekey) ' already exists" )
548
551
end
549
552
var. solverDataDict[solvekey] = vnd
550
- # TODO : Cleanup
553
+
554
+ # TODO : Cleanup and consolidate as one function.
551
555
solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
552
556
_setNodeProperty (
553
557
dfg. neo4jInstance,
@@ -557,28 +561,58 @@ function addVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, vnd::V
557
561
return vnd
558
562
end
559
563
560
- function updateVariableSolverData! (dfg:: CloudGraphsDFG , variablekey:: Symbol , vnd:: VariableNodeData , solvekey:: Symbol = :default ):: VariableNodeData
564
+ function updateVariableSolverData! (dfg:: CloudGraphsDFG ,
565
+ variablekey:: Symbol ,
566
+ vnd:: VariableNodeData ,
567
+ solvekey:: Symbol = :default ,
568
+ useCopy:: Bool = true ,
569
+ fields:: Vector{Symbol} = Symbol[]):: VariableNodeData
561
570
# TODO : Switch out to their own nodes, don't get the whole variable
562
571
var = getVariable (dfg, variablekey)
563
572
if ! haskey (var. solverDataDict, solvekey)
564
573
@warn " VariableNodeData '$(solvekey) ' does not exist, adding"
565
574
end
566
- var. solverDataDict[solvekey] = vnd
567
- # TODO : Cleanup
575
+
576
+ # Unnecessary for cloud, but (probably) being (too) conservative (just because).
577
+ usevnd = useCopy ? deepcopy (vnd) : vnd
578
+ # should just one, or many pointers be updated?
579
+ if haskey (var. solverDataDict, solvekey) && isa (var. solverDataDict[solvekey], VariableNodeData) && length (fields) != 0
580
+ # change multiple pointers inside the VND var.solverDataDict[solvekey]
581
+ for field in fields
582
+ destField = getfield (var. solverDataDict[solvekey], field)
583
+ srcField = getfield (usevnd, field)
584
+ if isa (destField, Array) && size (destField) == size (srcField)
585
+ # use broadcast (in-place operation)
586
+ destField .= srcField
587
+ else
588
+ # change pointer of destination VND object member
589
+ setfield! (var. solverDataDict[solvekey], field, srcField)
590
+ end
591
+ end
592
+ else
593
+ # change a single pointer in var.solverDataDict
594
+ var. solverDataDict[solvekey] = usevnd
595
+ end
596
+
597
+ # TODO : Cleanup and consolidate
568
598
solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
569
599
_setNodeProperty (
570
600
dfg. neo4jInstance,
571
601
_getLabelsForInst (dfg, var),
572
602
" solverDataDict" ,
573
603
solverDataDict)
574
- return vnd
604
+ return var . solverDataDict[solvekey]
575
605
end
576
606
577
- function updateVariableSolverData! (dfg:: CloudGraphsDFG , sourceVariables:: Vector{<:DFGVariable} , solvekey:: Symbol = :default )
607
+ function updateVariableSolverData! (dfg:: CloudGraphsDFG ,
608
+ sourceVariables:: Vector{<:DFGVariable} ,
609
+ solvekey:: Symbol = :default ,
610
+ useCopy:: Bool = true ,
611
+ fields:: Vector{Symbol} = Symbol[] )
578
612
# TODO : Switch out to their own nodes, don't get the whole variable
579
613
# TODO : Do in bulk for speed.
580
614
for var in sourceVariables
581
- updateVariableSolverData! (dfg, var. label, getSolverData (var, solvekey), solvekey)
615
+ updateVariableSolverData! (dfg, var. label, getSolverData (var, solvekey), solvekey, useCopy, fields )
582
616
end
583
617
end
584
618
@@ -590,7 +624,7 @@ function deleteVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, sol
590
624
error (" VariableNodeData '$(solvekey) ' does not exist" )
591
625
end
592
626
vnd = pop! (var. solverDataDict, solvekey)
593
- # TODO : Cleanup
627
+ # TODO : Cleanup and consolidate... yadda yadda just do it already :)
594
628
solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
595
629
_setNodeProperty (
596
630
dfg. neo4jInstance,
@@ -600,6 +634,22 @@ function deleteVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, sol
600
634
return vnd
601
635
end
602
636
637
+ function mergeVariableSolverData! (dfg:: AbstractDFG , sourceVariable:: DFGVariable )
638
+ # TODO : Switch out to their own nodes, don't get the whole variable
639
+ var = getVariable (dfg, sourceVariable. label)
640
+
641
+ merge! (var. solverDataDict, deepcopy (sourceVariable. solverDataDict))
642
+
643
+ # TODO : Cleanup and consolidate
644
+ solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
645
+ _setNodeProperty (
646
+ dfg. neo4jInstance,
647
+ _getLabelsForInst (dfg, var),
648
+ " solverDataDict" ,
649
+ solverDataDict)
650
+ return var
651
+ end
652
+
603
653
function getSolvable (dfg:: CloudGraphsDFG , sym:: Symbol )
604
654
prop = _getNodeProperty (
605
655
dfg. neo4jInstance,
0 commit comments