@@ -538,26 +538,15 @@ getSolverDataDict(v::VariableCompute) = v.solverDataDict
538538
539539Retrieve solver data structure stored in a variable.
540540"""
541- function getVariableState (v:: VariableCompute , key:: Symbol = :default )
542- # TODO this does not fit in with some of the other error behaviour. but its used so added @error
543- vnd = if haskey (getSolverDataDict (v), key)
544- return getSolverDataDict (v)[key]
541+ function getVariableState (v:: VariableCompute , label:: Symbol )
542+ vnd = if haskey (getSolverDataDict (v), label)
543+ return getSolverDataDict (v)[label]
545544 else
546- throw (LabelNotFoundError (" State" , key ))
545+ throw (LabelNotFoundError (" State" , label ))
547546 end
548547 return vnd
549548end
550549
551- # TODO Repeated functionality? same as update
552- """
553- $SIGNATURES
554- Set solver data structure stored in a variable.
555- """
556- function setSolverData! (v:: VariableCompute , data:: VariableState , key:: Symbol = :default )
557- @assert key == data. solveKey " VariableState.solveKey=:$(data. solveKey) does not match requested :$(key) "
558- return v. solverDataDict[key] = data
559- end
560-
561550# #------------------------------------------------------------------------------
562551# # Variable Metadata
563552# #------------------------------------------------------------------------------
@@ -684,47 +673,38 @@ Get variable solverdata for a given solve key.
684673"""
685674function getVariableState (
686675 dfg:: AbstractDFG ,
687- variablekey :: Symbol ,
688- solvekey :: Symbol = :default ,
676+ variableLabel :: Symbol ,
677+ label :: Symbol ,
689678)
690- v = getVariable (dfg, variablekey )
691- ! haskey (v. solverDataDict, solvekey ) && throw (LabelNotFoundError (" State" , solvekey ))
692- return v. solverDataDict[solvekey ]
679+ v = getVariable (dfg, variableLabel )
680+ ! haskey (v. solverDataDict, label ) && throw (LabelNotFoundError (" State" , label ))
681+ return v. solverDataDict[label ]
693682end
694683
695- function getVariableStates (dfg:: AbstractDFG , variablekey :: Symbol )
696- v = getVariable (dfg, variablekey )
684+ function getVariableStates (dfg:: AbstractDFG , variableLabel :: Symbol )
685+ v = getVariable (dfg, variableLabel )
697686 return collect (values (v. solverDataDict))
698687end
699688
700689"""
701690 $(SIGNATURES)
702691Add variable solver data, errors if it already exists.
703692"""
704- function addVariableState! (dfg:: AbstractDFG , variablekey:: Symbol , vnd :: VariableState )
693+ function addVariableState! (dfg:: AbstractDFG , variablekey:: Symbol , state :: VariableState )
705694 var = getVariable (dfg, variablekey)
706- if haskey (var. solverDataDict, vnd . solveKey)
707- throw (LabelExistsError (" VariableState" , vnd . solveKey))
695+ if haskey (var. solverDataDict, state . solveKey)
696+ throw (LabelExistsError (" VariableState" , state . solveKey))
708697 end
709- var. solverDataDict[vnd . solveKey] = vnd
710- return vnd
698+ var. solverDataDict[state . solveKey] = state
699+ return state
711700end
712701
713- """
714- $(SIGNATURES)
715- Add a new solver data entry from a deepcopy of the source variable solver data.
716- NOTE: Copies the solver data.
717- """
718- function addVariableState! (
719- dfg:: AbstractDFG ,
720- sourceVariable:: VariableCompute ,
721- solveKey:: Symbol = :default ,
722- )
723- return addVariableState! (
724- dfg,
725- sourceVariable. label,
726- deepcopy (getVariableState (sourceVariable, solveKey)),
727- )
702+ function addVariableState! (v, state:: VariableState )
703+ if haskey (v. solverDataDict, state. solveKey)
704+ throw (LabelExistsError (" VariableState" , state. solveKey))
705+ end
706+ v. solverDataDict[state. solveKey] = state
707+ return state
728708end
729709
730710"""
@@ -747,6 +727,17 @@ function mergeVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::Variabl
747727 return 1
748728end
749729
730+ function mergeVariableState! (v:: VariableCompute , vnd:: VariableState )
731+
732+ if ! haskey (v. solverDataDict, vnd. solveKey)
733+ addVariableState! (v, vnd)
734+ else
735+ v. solverDataDict[vnd. solveKey] = vnd
736+ end
737+
738+ return 1
739+ end
740+
750741function copytoVariableState! (
751742 dfg:: AbstractDFG ,
752743 variableLabel:: Symbol ,
@@ -797,12 +788,12 @@ end
797788
798789"""
799790 $(SIGNATURES)
800- Delete variable solver data, returns the deleted element .
791+ Delete variable solver data, returns the number of deleted elements .
801792"""
802793function deleteVariableState! (
803794 dfg:: AbstractDFG ,
804795 variablekey:: Symbol ,
805- solveKey:: Symbol = :default ,
796+ solveKey:: Symbol ,
806797)
807798 var = getVariable (dfg, variablekey)
808799
@@ -815,12 +806,12 @@ end
815806
816807"""
817808 $(SIGNATURES)
818- Delete variable solver data, returns the deleted element .
809+ Delete variable solver data, returns the number of deleted elements .
819810"""
820811function deleteVariableState! (
821812 dfg:: AbstractDFG ,
822813 sourceVariable:: VariableCompute ,
823- solveKey:: Symbol = :default ,
814+ solveKey:: Symbol ,
824815)
825816 return deleteVariableState! (dfg, sourceVariable. label, solveKey)
826817end
@@ -838,28 +829,6 @@ function listVariableStates(dfg::AbstractDFG, variablekey::Symbol)
838829 return collect (keys (v. solverDataDict))
839830end
840831
841- """
842- $(SIGNATURES)
843- Merges and updates solver and estimate data for a variable (variable can be from another graph).
844- If the same key is present in another collection, the value for that key will be the value it has in the last collection listed (updated).
845- Note: Makes a copy of the estimates and solver data so that there is no coupling between graphs.
846- """
847- function mergeVariableSolverData! (
848- destVariable:: VariableCompute ,
849- sourceVariable:: VariableCompute ,
850- )
851- # We don't know which graph this came from, must be copied!
852- merge! (destVariable. solverDataDict, deepcopy (sourceVariable. solverDataDict))
853- return destVariable
854- end
855-
856- function mergeVariableSolverData! (dfg:: AbstractDFG , sourceVariable:: VariableCompute )
857- return mergeVariableSolverData! (
858- getVariable (dfg, getLabel (sourceVariable)),
859- sourceVariable,
860- )
861- end
862-
863832# #==============================================================================
864833# # Point Parametric Estimates
865834# #==============================================================================
0 commit comments