diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1a9e4601..7f1e8f04 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1348,6 +1348,39 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.optim_weights_present = true; } +Statement * +OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + var_weights_t new_var_weights; + covar_weights_t new_covar_weights; + try + { + for (var_weights_t::const_iterator it = var_weights.begin(); + it != var_weights.end(); it++) + { + new_symbol_table->getID(it->first); + new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + + for (covar_weights_t::const_iterator it = covar_weights.begin(); + it != covar_weights.end(); it++) + { + new_symbol_table->getID(it->first.first); + new_symbol_table->getID(it->first.second); + new_covar_weights[make_pair(it->first.first, it->first.second)] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + } + catch (...) + { + cerr << "ERROR: A variable in the optim_weights statement was not found in the symbol table" << endl + << " This likely means that you have declared a varexo that is not used in the model" << endl; + exit(EXIT_FAILURE); + } + return new OptimWeightsStatement(new_var_weights, new_covar_weights, *new_symbol_table); +} + void OptimWeightsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 3736d0de..01f3cd2e 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -366,6 +366,7 @@ public: const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; /*! \todo Make model_tree a member instead of a pointer */