@@ -582,14 +582,18 @@ end
582
582
# ## Updated functions from AbstractDFG
583
583
# ## These functions write back as you add the data.
584
584
585
- function addVariableSolverData! (dfg:: CloudGraphsDFG , variablekey:: Symbol , vnd:: VariableNodeData , solvekey:: Symbol = :default ):: VariableNodeData
585
+ function addVariableSolverData! (dfg:: CloudGraphsDFG ,
586
+ variablekey:: Symbol ,
587
+ vnd:: VariableNodeData ,
588
+ solvekey:: Symbol = :default ):: VariableNodeData
586
589
# TODO : Switch out to their own nodes, don't get the whole variable
587
590
var = getVariable (dfg, variablekey)
588
591
if haskey (var. solverDataDict, solvekey)
589
592
error (" VariableNodeData '$(solvekey) ' already exists" )
590
593
end
591
594
var. solverDataDict[solvekey] = vnd
592
- # TODO : Cleanup
595
+
596
+ # TODO : Cleanup and consolidate as one function.
593
597
solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
594
598
_setNodeProperty (
595
599
dfg. neo4jInstance,
@@ -599,28 +603,58 @@ function addVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, vnd::V
599
603
return vnd
600
604
end
601
605
602
- function updateVariableSolverData! (dfg:: CloudGraphsDFG , variablekey:: Symbol , vnd:: VariableNodeData , solvekey:: Symbol = :default ):: VariableNodeData
606
+ function updateVariableSolverData! (dfg:: CloudGraphsDFG ,
607
+ variablekey:: Symbol ,
608
+ vnd:: VariableNodeData ,
609
+ solvekey:: Symbol = :default ,
610
+ useCopy:: Bool = true ,
611
+ fields:: Vector{Symbol} = Symbol[]):: VariableNodeData
603
612
# TODO : Switch out to their own nodes, don't get the whole variable
604
613
var = getVariable (dfg, variablekey)
605
614
if ! haskey (var. solverDataDict, solvekey)
606
615
@warn " VariableNodeData '$(solvekey) ' does not exist, adding"
607
616
end
608
- var. solverDataDict[solvekey] = vnd
609
- # TODO : Cleanup
617
+
618
+ # Unnecessary for cloud, but (probably) being (too) conservative (just because).
619
+ usevnd = useCopy ? deepcopy (vnd) : vnd
620
+ # should just one, or many pointers be updated?
621
+ if haskey (var. solverDataDict, solvekey) && isa (var. solverDataDict[solvekey], VariableNodeData) && length (fields) != 0
622
+ # change multiple pointers inside the VND var.solverDataDict[solvekey]
623
+ for field in fields
624
+ destField = getfield (var. solverDataDict[solvekey], field)
625
+ srcField = getfield (usevnd, field)
626
+ if isa (destField, Array) && size (destField) == size (srcField)
627
+ # use broadcast (in-place operation)
628
+ destField .= srcField
629
+ else
630
+ # change pointer of destination VND object member
631
+ setfield! (var. solverDataDict[solvekey], field, srcField)
632
+ end
633
+ end
634
+ else
635
+ # change a single pointer in var.solverDataDict
636
+ var. solverDataDict[solvekey] = usevnd
637
+ end
638
+
639
+ # TODO : Cleanup and consolidate
610
640
solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
611
641
_setNodeProperty (
612
642
dfg. neo4jInstance,
613
643
_getLabelsForInst (dfg, var),
614
644
" solverDataDict" ,
615
645
solverDataDict)
616
- return vnd
646
+ return var . solverDataDict[solvekey]
617
647
end
618
648
619
- function updateVariableSolverData! (dfg:: CloudGraphsDFG , sourceVariables:: Vector{<:DFGVariable} , solvekey:: Symbol = :default )
649
+ function updateVariableSolverData! (dfg:: CloudGraphsDFG ,
650
+ sourceVariables:: Vector{<:DFGVariable} ,
651
+ solvekey:: Symbol = :default ,
652
+ useCopy:: Bool = true ,
653
+ fields:: Vector{Symbol} = Symbol[] )
620
654
# TODO : Switch out to their own nodes, don't get the whole variable
621
655
# TODO : Do in bulk for speed.
622
656
for var in sourceVariables
623
- updateVariableSolverData! (dfg, var. label, getSolverData (var, solvekey), solvekey)
657
+ updateVariableSolverData! (dfg, var. label, getSolverData (var, solvekey), solvekey, useCopy, fields )
624
658
end
625
659
end
626
660
@@ -632,7 +666,7 @@ function deleteVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, sol
632
666
error (" VariableNodeData '$(solvekey) ' does not exist" )
633
667
end
634
668
vnd = pop! (var. solverDataDict, solvekey)
635
- # TODO : Cleanup
669
+ # TODO : Cleanup and consolidate... yadda yadda just do it already :)
636
670
solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
637
671
_setNodeProperty (
638
672
dfg. neo4jInstance,
@@ -642,6 +676,22 @@ function deleteVariableSolverData!(dfg::CloudGraphsDFG, variablekey::Symbol, sol
642
676
return vnd
643
677
end
644
678
679
+ function mergeVariableSolverData! (dfg:: CloudGraphsDFG , sourceVariable:: DFGVariable )
680
+ # TODO : Switch out to their own nodes, don't get the whole variable
681
+ var = getVariable (dfg, sourceVariable. label)
682
+
683
+ merge! (var. solverDataDict, deepcopy (sourceVariable. solverDataDict))
684
+
685
+ # TODO : Cleanup and consolidate
686
+ solverDataDict = JSON2. write (Dict (keys (var. solverDataDict) .=> map (vnd -> packVariableNodeData (dfg, vnd), values (var. solverDataDict))))
687
+ _setNodeProperty (
688
+ dfg. neo4jInstance,
689
+ _getLabelsForInst (dfg, var),
690
+ " solverDataDict" ,
691
+ solverDataDict)
692
+ return var
693
+ end
694
+
645
695
function getSolvable (dfg:: CloudGraphsDFG , sym:: Symbol )
646
696
prop = _getNodeProperty (
647
697
dfg. neo4jInstance,
0 commit comments