@@ -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# #------------------------------------------------------------------------------
@@ -682,49 +671,36 @@ end
682671 $(SIGNATURES)
683672Get variable solverdata for a given solve key.
684673"""
685- function getVariableState (
686- dfg:: AbstractDFG ,
687- variablekey:: Symbol ,
688- solvekey:: Symbol = :default ,
689- )
690- v = getVariable (dfg, variablekey)
691- ! haskey (v. solverDataDict, solvekey) && throw (LabelNotFoundError (" State" , solvekey))
692- return v. solverDataDict[solvekey]
674+ function getVariableState (dfg:: AbstractDFG , variableLabel:: Symbol , label:: Symbol )
675+ v = getVariable (dfg, variableLabel)
676+ ! haskey (v. solverDataDict, label) && throw (LabelNotFoundError (" State" , label))
677+ return v. solverDataDict[label]
693678end
694679
695- function getVariableStates (dfg:: AbstractDFG , variablekey :: Symbol )
696- v = getVariable (dfg, variablekey )
680+ function getVariableStates (dfg:: AbstractDFG , variableLabel :: Symbol )
681+ v = getVariable (dfg, variableLabel )
697682 return collect (values (v. solverDataDict))
698683end
699684
700685"""
701686 $(SIGNATURES)
702687Add variable solver data, errors if it already exists.
703688"""
704- function addVariableState! (dfg:: AbstractDFG , variablekey:: Symbol , vnd :: VariableState )
689+ function addVariableState! (dfg:: AbstractDFG , variablekey:: Symbol , state :: VariableState )
705690 var = getVariable (dfg, variablekey)
706- if haskey (var. solverDataDict, vnd . solveKey)
707- throw (LabelExistsError (" VariableState" , vnd . solveKey))
691+ if haskey (var. solverDataDict, state . solveKey)
692+ throw (LabelExistsError (" VariableState" , state . solveKey))
708693 end
709- var. solverDataDict[vnd . solveKey] = vnd
710- return vnd
694+ var. solverDataDict[state . solveKey] = state
695+ return state
711696end
712697
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- )
698+ function addVariableState! (v, state:: VariableState )
699+ if haskey (v. solverDataDict, state. solveKey)
700+ throw (LabelExistsError (" VariableState" , state. solveKey))
701+ end
702+ v. solverDataDict[state. solveKey] = state
703+ return state
728704end
729705
730706"""
@@ -747,6 +723,16 @@ function mergeVariableState!(dfg::AbstractDFG, variablekey::Symbol, vnd::Variabl
747723 return 1
748724end
749725
726+ function mergeVariableState! (v:: VariableCompute , vnd:: VariableState )
727+ if ! haskey (v. solverDataDict, vnd. solveKey)
728+ addVariableState! (v, vnd)
729+ else
730+ v. solverDataDict[vnd. solveKey] = vnd
731+ end
732+
733+ return 1
734+ end
735+
750736function copytoVariableState! (
751737 dfg:: AbstractDFG ,
752738 variableLabel:: Symbol ,
797783
798784"""
799785 $(SIGNATURES)
800- Delete variable solver data, returns the deleted element .
786+ Delete variable solver data, returns the number of deleted elements .
801787"""
802- function deleteVariableState! (
803- dfg:: AbstractDFG ,
804- variablekey:: Symbol ,
805- solveKey:: Symbol = :default ,
806- )
788+ function deleteVariableState! (dfg:: AbstractDFG , variablekey:: Symbol , solveKey:: Symbol )
807789 var = getVariable (dfg, variablekey)
808790
809791 if ! haskey (var. solverDataDict, solveKey)
@@ -815,12 +797,12 @@ end
815797
816798"""
817799 $(SIGNATURES)
818- Delete variable solver data, returns the deleted element .
800+ Delete variable solver data, returns the number of deleted elements .
819801"""
820802function deleteVariableState! (
821803 dfg:: AbstractDFG ,
822804 sourceVariable:: VariableCompute ,
823- solveKey:: Symbol = :default ,
805+ solveKey:: Symbol ,
824806)
825807 return deleteVariableState! (dfg, sourceVariable. label, solveKey)
826808end
@@ -838,28 +820,6 @@ function listVariableStates(dfg::AbstractDFG, variablekey::Symbol)
838820 return collect (keys (v. solverDataDict))
839821end
840822
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-
863823# #==============================================================================
864824# # Point Parametric Estimates
865825# #==============================================================================
0 commit comments