From 96a5949d9edebadc0c6fac5a7066cd4927dd3eff Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 6 Mar 2015 15:58:11 +0100 Subject: [PATCH 01/74] preprocessor: remove extraneous varexo, update model and statements, #841 --- DataTree.hh | 3 +- DynamicModel.cc | 16 +++++++ DynamicModel.hh | 3 ++ ExprNode.cc | 71 ++++++++++++++++++++++++++++ ExprNode.hh | 14 +++++- ModFile.cc | 13 ++++++ NumericalInitialization.cc | 94 +++++++++++++++++++++++++++++++++++++- NumericalInitialization.hh | 10 +++- Statement.cc | 8 +++- Statement.hh | 9 +++- SymbolTable.cc | 37 ++++++++++++++- SymbolTable.hh | 4 +- 12 files changed, 272 insertions(+), 10 deletions(-) diff --git a/DataTree.hh b/DataTree.hh index d7c53645..f81f19e6 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -233,6 +233,7 @@ public: //! Returns the minimum lag (as a negative number) of the given symbol in the whole data tree (and not only in the equations !!) /*! Returns 0 if the symbol is not used */ int minLagForSymbol(int symb_id) const; + inline SymbolTable *getSymbolTable() const { return &symbol_table; }; //! Write the Header for getPowerDeriv when use_dll is used void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv diff --git a/DynamicModel.cc b/DynamicModel.cc index 645fa646..a4997e02 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3425,6 +3425,22 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } +void +DynamicModel::reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) +{ + map orig_local_variables_table = local_variables_table; + local_variables_table.clear(); + for (map::const_iterator it = orig_local_variables_table.begin(); + it != orig_local_variables_table.end(); it++) + dynamic_model.AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); + + vectoreqbak = equations; + equations.clear(); + for (size_t i = 0; i < eqbak.size(); i++) + dynamic_model.addEquation(eqbak[i]->cloneDynamicReindex(dynamic_model, orig_symbol_table), equations_lineno[i]); +} + void DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const { diff --git a/DynamicModel.hh b/DynamicModel.hh index 8efbc5d3..b13d23e1 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -235,6 +235,9 @@ public: /*! It assumes that the dynamic model given in argument has just been allocated */ void cloneDynamic(DynamicModel &dynamic_model) const; + //! reindex equations after change in symbol_table + void reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); + //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous void computeRamseyPolicyFOCs(const StaticModel &static_model); //! Replaces the model equations in dynamic_model with those in this model diff --git a/ExprNode.cc b/ExprNode.cc index d61ebb56..66cd230e 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -354,6 +354,12 @@ NumConstNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddNonNegativeConstant(datatree.num_constants.get(id)); } +expr_t +NumConstNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + return dynamic_datatree.AddNonNegativeConstant(datatree.num_constants.get(id)); +} + int NumConstNode::maxEndoLead() const { @@ -988,6 +994,12 @@ VariableNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddVariable(symb_id, lag); } +expr_t +VariableNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + return dynamic_datatree.AddVariable(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), lag); +} + int VariableNode::maxEndoLead() const { @@ -2234,6 +2246,13 @@ UnaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarUnaryOpNode(substarg, dynamic_datatree); } +expr_t +UnaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + expr_t substarg = arg->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + return buildSimilarUnaryOpNode(substarg, dynamic_datatree); +} + int UnaryOpNode::maxEndoLead() const { @@ -3452,6 +3471,14 @@ BinaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarBinaryOpNode(substarg1, substarg2, dynamic_datatree); } +expr_t +BinaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + expr_t substarg1 = arg1->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + expr_t substarg2 = arg2->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + return buildSimilarBinaryOpNode(substarg1, substarg2, dynamic_datatree); +} + int BinaryOpNode::maxEndoLead() const { @@ -4120,6 +4147,15 @@ TrinaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarTrinaryOpNode(substarg1, substarg2, substarg3, dynamic_datatree); } +expr_t +TrinaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + expr_t substarg1 = arg1->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + expr_t substarg2 = arg2->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + expr_t substarg3 = arg3->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + return buildSimilarTrinaryOpNode(substarg1, substarg2, substarg3, dynamic_datatree); +} + int TrinaryOpNode::maxEndoLead() const { @@ -4689,6 +4725,17 @@ ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments); } +expr_t +ExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); + return dynamic_datatree.AddExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), + dynamic_arguments); +} + int AbstractExternalFunctionNode::maxEndoLead() const { @@ -5182,6 +5229,18 @@ FirstDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const inputIndex); } +expr_t +FirstDerivExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); + return dynamic_datatree.AddFirstDerivExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), + dynamic_arguments, + inputIndex); +} + expr_t FirstDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { @@ -5417,6 +5476,18 @@ SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const inputIndex1, inputIndex2); } +expr_t +SecondDerivExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const +{ + vector dynamic_arguments; + for (vector::const_iterator it = arguments.begin(); + it != arguments.end(); it++) + dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); + return dynamic_datatree.AddSecondDerivExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), + dynamic_arguments, + inputIndex1, inputIndex2); +} + expr_t SecondDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { diff --git a/ExprNode.hh b/ExprNode.hh index b008333c..b6c7b9b9 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2007-2014 Dynare Team + * Copyright (C) 2007-2015 Dynare Team * * This file is part of Dynare. * @@ -407,6 +407,9 @@ public: //! Add ExprNodes to the provided datatree virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; + //! Add ExprNodes to the provided datatree, changing the symbol id from those provided in orig_symbol_table + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const = 0; + //! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor virtual expr_t removeTrendLeadLag(map trend_symbols_map) const = 0; @@ -467,6 +470,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -529,6 +533,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -606,6 +611,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -696,6 +702,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; //! Function to write out the oPowerNode in expr_t terms as opposed to writing out the function itself expr_t unpackPowerDeriv() const; @@ -766,6 +773,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -841,6 +849,7 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const = 0; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -871,6 +880,7 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; class FirstDerivExternalFunctionNode : public AbstractExternalFunctionNode @@ -905,6 +915,7 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; class SecondDerivExternalFunctionNode : public AbstractExternalFunctionNode @@ -941,6 +952,7 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; + virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; #endif diff --git a/ModFile.cc b/ModFile.cc index 847fc7e3..1d1df2a5 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -307,6 +307,19 @@ ModFile::checkPass() void ModFile::transformPass(bool nostrict) { + // Remove unused exogenous from symbol table and update dynamic_model + set unusedExo = dynamic_model.findUnusedExogenous(); + if (unusedExo.size() > 0) + { + SymbolTable orig_symbol_table = symbol_table; + symbol_table.rmExo(unusedExo); + dynamic_model.reindexEquations(dynamic_model, orig_symbol_table); + vector orig_statements = statements; + statements.clear(); + for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) + addStatement((*it)->cloneAndReindexSymbIds(dynamic_model, orig_symbol_table)); + } + // Save the original model (must be done before any model transformations by preprocessor) dynamic_model.cloneDynamic(original_model); diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 3df225fc..4937308c 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -73,6 +73,24 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const } } +Statement * +InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + cout << orig_symbol_table.getName(symb_id) << " " << symb_id << "->" << new_symbol_table->getID(orig_symbol_table.getName(symb_id)) << endl; + return new InitParamStatement(new_symbol_table->getID(orig_symbol_table.getName(symb_id)), + param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), + *new_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: encountered in InitParamStatement::cloneAndReindexSymbIds. Should not arrive here" << endl; + exit(EXIT_FAILURE); + } +} + InitOrEndValStatement::InitOrEndValStatement(const init_values_t &init_values_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : @@ -208,6 +226,27 @@ InitValStatement::writeOutputPostInit(ostream &output) const <<"end;" << endl; } +Statement * +InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + init_values_t new_init_values; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: A variable in the initval 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 InitValStatement(new_init_values, *new_symbol_table, all_values_required); +} + EndValStatement::EndValStatement(const init_values_t &init_values_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : @@ -254,6 +293,27 @@ EndValStatement::writeOutput(ostream &output, const string &basename) const writeInitValues(output); } +Statement * +EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + init_values_t new_init_values; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: A variable in the endval 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 EndValStatement(new_init_values, *new_symbol_table, all_values_required); +} + HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, const SymbolTable &symbol_table_arg) : hist_values(hist_values_arg), @@ -320,6 +380,28 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const } } +Statement * +HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + hist_values_t new_hist_values; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (hist_values_t::const_iterator it=hist_values.begin(); + it != hist_values.end(); it++) + new_hist_values[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + it->first.second)] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + cerr << "ERROR: A variable in the hist_val 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 HistValStatement(new_hist_values, *new_symbol_table); +} + InitvalFileStatement::InitvalFileStatement(const string &filename_arg) : filename(filename_arg) { @@ -393,9 +475,10 @@ SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba output << "save_params_and_steady_state('" << filename << "');" << endl; } -LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename, +LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename_arg, const SymbolTable &symbol_table_arg, WarningConsolidation &warnings) : + filename(filename_arg), symbol_table(symbol_table_arg) { cout << "Reading " << filename << "." << endl; @@ -465,3 +548,10 @@ LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) it != content.end(); it++) eval_context[it->first] = atof(it->second.c_str()); } + +Statement * +LoadParamsAndSteadyStateStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + WarningConsolidation warnings(false); + return new LoadParamsAndSteadyStateStatement(filename, *(dynamic_datatree.getSymbolTable()), warnings); +} diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index c61d41e1..913e2730 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -44,6 +44,7 @@ public: virtual void writeCOutput(ostream &output, const string &basename); //! Fill eval context with parameter value void fillEvalContext(eval_context_t &eval_context) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class InitOrEndValStatement : public Statement @@ -80,6 +81,7 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; //! Writes initializations for oo_.exo_simul and oo_.exo_det_simul void writeOutputPostInit(ostream &output) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EndValStatement : public InitOrEndValStatement @@ -91,6 +93,7 @@ public: //! Workaround for trac ticket #35 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); }; class HistValStatement : public Statement @@ -111,6 +114,7 @@ public: //! Workaround for trac ticket #157 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); }; class InitvalFileStatement : public Statement @@ -158,17 +162,19 @@ public: class LoadParamsAndSteadyStateStatement : public Statement { private: + const string filename; const SymbolTable &symbol_table; //! Content of the file /*! Maps symbol ID to numeric value (stored as string) */ map content; public: - LoadParamsAndSteadyStateStatement(const string &filename, + LoadParamsAndSteadyStateStatement(const string &filename_arg, const SymbolTable &symbol_table_arg, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; //! Fill eval context with parameters/variables values void fillEvalContext(eval_context_t &eval_context) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif diff --git a/Statement.cc b/Statement.cc index d4d522e7..2b3cd8c6 100644 --- a/Statement.cc +++ b/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Dynare Team + * Copyright (C) 2006-2015 Dynare Team * * This file is part of Dynare. * @@ -73,6 +73,12 @@ Statement::computingPass() { } +Statement * +Statement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + return this; +} + NativeStatement::NativeStatement(const string &native_statement_arg) : native_statement(native_statement_arg) { diff --git a/Statement.hh b/Statement.hh index 5bdade39..30643596 100644 --- a/Statement.hh +++ b/Statement.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Dynare Team + * Copyright (C) 2006-2015 Dynare Team * * This file is part of Dynare. * @@ -27,6 +27,8 @@ #include "SymbolList.hh" #include "WarningConsolidation.hh" +#include "SymbolTable.hh" +#include "DataTree.hh" class ModFileStructure { @@ -136,6 +138,11 @@ public: */ virtual void writeOutput(ostream &output, const string &basename) const = 0; virtual void writeCOutput(ostream &output, const string &basename); + //! clone a statement while updating all symbol ids that are contained within it. + /* Symbol id's are updated from the symbol table contained in dynamic_datatree + The original symbol table is contained in orig_symbol_table + */ + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class NativeStatement : public Statement diff --git a/SymbolTable.cc b/SymbolTable.cc index 9d43b791..490dbb31 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -21,6 +21,7 @@ #include #include #include +#include #include "SymbolTable.hh" @@ -473,6 +474,40 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenExce return symb_id; } +void +SymbolTable::rmExo(set &unused) throw (FrozenException) +{ + if (frozen) + throw FrozenException(); + + list idxs; + for (set::const_iterator it = unused.begin(); it != unused.end(); it++) + { + string name = getName(*it); + idxs.push_back(symbol_table[name]); + symbol_table.erase(name); + size--; + } + + idxs.sort(); + idxs.reverse(); + for (list::const_iterator it = idxs.begin(); it != idxs.end(); it++) + { + type_table.erase(type_table.begin() + *it); + name_table.erase(name_table.begin() + *it); + tex_name_table.erase(tex_name_table.begin() + *it); + long_name_table.erase(long_name_table.begin() + *it); + } + + symbol_table.clear(); + int i = 0; + for (vector::const_iterator it=name_table.begin(); + it != name_table.end(); it++) + symbol_table[*it] = i++; + + assert(size == symbol_table.size()); +} + int SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException) { diff --git a/SymbolTable.hh b/SymbolTable.hh index 3e4c47e1..85267fe6 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -303,6 +303,8 @@ public: bool isAuxiliaryVariable(int symb_id) const; //! Get list of endogenous variables without aux vars set getOrigEndogenous() const; + //! Remove exogenous variables contained in the set + void rmExo(set &unused) throw (FrozenException); }; inline bool From 5cc4ad033f1c8850450de0fdf733052c6c5f1d2e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 10 Mar 2015 11:24:20 +0100 Subject: [PATCH 02/74] preprocessor: remove spurious print statement --- NumericalInitialization.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 4937308c..943bbb93 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -79,7 +79,6 @@ InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { - cout << orig_symbol_table.getName(symb_id) << " " << symb_id << "->" << new_symbol_table->getID(orig_symbol_table.getName(symb_id)) << endl; return new InitParamStatement(new_symbol_table->getID(orig_symbol_table.getName(symb_id)), param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), *new_symbol_table); From 81a2a2ee0d01e277efb57c6f561dcf46f5f9f0e4 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 10 Mar 2015 14:10:10 +0100 Subject: [PATCH 03/74] =?UTF-8?q?remove=20extra=20exo=E2=80=99s=20for=20sh?= =?UTF-8?q?ocks=20statement,=20nonstationary,=20and=20trend=20vars;=20fix?= =?UTF-8?q?=20bugs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- DynamicModel.cc | 54 ++++++++++++++++++++++++++++ DynamicModel.hh | 11 +++++- ModFile.cc | 1 + Shocks.cc | 96 +++++++++++++++++++++++++++++++++++++++++++++++++ Shocks.hh | 4 ++- 5 files changed, 164 insertions(+), 2 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index a4997e02..493bbff4 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3425,6 +3425,60 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } +void +DynamicModel::reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) +{ + map orig_trend_symbols_map = trend_symbols_map; + trend_symbols_map.clear(); + for (map::const_iterator it = orig_trend_symbols_map.begin(); + it != orig_trend_symbols_map.end(); it++) + try + { + vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); + addTrendVariables(symb_id, + it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); + } + catch(...) + { + cerr << "Error: unused exo in trend symbols." << endl; + exit(EXIT_FAILURE); + } +} + +void +DynamicModel::reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) +{ + nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map; + nonstationary_symbols_map.clear(); + for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin(); + it != orig_nonstationary_symbols_map.end(); it++) + try + { + vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); + addNonstationaryVariables(symb_id, + it->second.first, + it->second.second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); + } + catch(...) + { + cerr << "Error: unused exo in nonstationary symbols." << endl; + exit(EXIT_FAILURE); + } +} + +void +DynamicModel::resetDataTree() +{ + num_const_node_map.clear(); + variable_node_map.clear(); + unary_op_node_map.clear(); + binary_op_node_map.clear(); + trinary_op_node_map.clear(); + external_function_node_map.clear(); + first_deriv_external_function_node_map.clear(); + second_deriv_external_function_node_map.clear(); +} + void DynamicModel::reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) { diff --git a/DynamicModel.hh b/DynamicModel.hh index b13d23e1..79f085de 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -238,6 +238,15 @@ public: //! reindex equations after change in symbol_table void reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); + //! reindex trend_symbol_map after change in symbol_table + void reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); + + //! reindex nonstationary_symbol_map after change in symbol_table + void reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); + + //! reset DataTree vars + void resetDataTree(); + //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous void computeRamseyPolicyFOCs(const StaticModel &static_model); //! Replaces the model equations in dynamic_model with those in this model @@ -248,7 +257,7 @@ public: //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; - + //! Returns number of dynamic only equations size_t dynamicOnlyEquationsNbr() const; diff --git a/ModFile.cc b/ModFile.cc index 1d1df2a5..f21f8f62 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -313,6 +313,7 @@ ModFile::transformPass(bool nostrict) { SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); + dynamic_model.resetDataTree(); dynamic_model.reindexEquations(dynamic_model, orig_symbol_table); vector orig_statements = statements; statements.clear(); diff --git a/Shocks.cc b/Shocks.cc index d0aecd96..46632b3d 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -67,6 +67,31 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const output << "M_.exo_det_length = " << exo_det_length << ";\n"; } +AbstractShocksStatement::det_shocks_t +AbstractShocksStatement::reindexDetShocksSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + det_shocks_t new_det_shocks; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + for (det_shocks_t::const_iterator it=det_shocks.begin(); it!=det_shocks.end(); it++) + try + { + vector det_shock_vec; + for (int i=0; isecond.size(); i++) + { + DetShockElement dse; + dse.period1 = it->second[1].period1; + dse.period2 = it->second[1].period2; + dse.value = it->second[i].value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + det_shock_vec.push_back(dse); + } + new_det_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = det_shock_vec; + } + catch (...) + { + } + return new_det_shocks; +} + ShocksStatement::ShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const var_and_std_shocks_t &var_shocks_arg, @@ -332,6 +357,69 @@ ShocksStatement::has_calibrated_measurement_errors() const return false; } +Statement * +ShocksStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + var_and_std_shocks_t new_var_shocks, new_std_shocks; + covar_and_corr_shocks_t new_covar_shocks, new_corr_shocks; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + + for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); + it != var_shocks.end(); it++) + try + { + new_var_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); + it != std_shocks.end(); it++) + try + { + new_std_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); + it != covar_shocks.end(); it++) + try + { + new_covar_shocks[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + new_symbol_table->getID(orig_symbol_table.getName(it->first.second)))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); + it != corr_shocks.end(); it++) + try + { + new_corr_shocks[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + new_symbol_table->getID(orig_symbol_table.getName(it->first.second)))] = + it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (...) + { + } + + return new ShocksStatement(overwrite, + reindexDetShocksSymbIds(dynamic_datatree, orig_symbol_table), + new_var_shocks, + new_std_shocks, + new_covar_shocks, + new_corr_shocks, + *(dynamic_datatree.getSymbolTable())); +} + + MShocksStatement::MShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg) : @@ -352,6 +440,14 @@ MShocksStatement::writeOutput(ostream &output, const string &basename) const writeDetShocks(output); } +Statement * +MShocksStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + return new MShocksStatement(overwrite, + reindexDetShocksSymbIds(dynamic_datatree, orig_symbol_table), + *(dynamic_datatree.getSymbolTable())); +} + ConditionalForecastPathsStatement::ConditionalForecastPathsStatement(const AbstractShocksStatement::det_shocks_t &paths_arg) : paths(paths_arg), path_length(-1) diff --git a/Shocks.hh b/Shocks.hh index 6ab43a64..2072e02f 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -50,7 +50,7 @@ protected: const det_shocks_t det_shocks; const SymbolTable &symbol_table; void writeDetShocks(ostream &output) const; - + det_shocks_t reindexDetShocksSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); AbstractShocksStatement(bool mshocks_arg, bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); @@ -79,6 +79,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class MShocksStatement : public AbstractShocksStatement @@ -88,6 +89,7 @@ public: const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ConditionalForecastPathsStatement : public Statement From 52e3bc993c917231833a52fd0ad8d4e2f41f79ca Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 12:23:36 +0200 Subject: [PATCH 04/74] fix copyright dates --- Shocks.cc | 2 +- Shocks.hh | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Shocks.cc b/Shocks.cc index 46632b3d..0ea7fd53 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * diff --git a/Shocks.hh b/Shocks.hh index 2072e02f..7ea320db 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * From e2c0f5698f5851135715b409021418d3a8b5c559 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 12:45:31 +0200 Subject: [PATCH 05/74] preprocessor: fix bug in shocks statement for removal of exos --- Shocks.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Shocks.cc b/Shocks.cc index 0ea7fd53..1c70cee0 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -79,8 +79,8 @@ AbstractShocksStatement::reindexDetShocksSymbIds(DataTree &dynamic_datatree, Sym for (int i=0; isecond.size(); i++) { DetShockElement dse; - dse.period1 = it->second[1].period1; - dse.period2 = it->second[1].period2; + dse.period1 = it->second[i].period1; + dse.period2 = it->second[i].period2; dse.value = it->second[i].value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); det_shock_vec.push_back(dse); } From 8a92da9c5adafce49b5a076b74e690db3dcf2364 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 16:59:47 +0200 Subject: [PATCH 06/74] preprocessor: take care of extra exos in stoch_simul --- ComputingTasks.cc | 36 ++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 37 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 2d7b1ffc..18d54db9 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -165,6 +165,42 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } +Statement * +StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the stoch_simul 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 StochSimulStatement(new_symbol_list, new_options_list); +} + void StochSimulStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d19f3e4c..d84ef1af 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -97,6 +97,7 @@ public: const OptionsList &options_list_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); }; class ForecastStatement : public Statement From 71f76cdaa6688ff1595e2f8d6c2bc21e428c164f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 17:41:41 +0200 Subject: [PATCH 07/74] preprocessor: take care of extra exos in forecast statement --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 18d54db9..7fc5d59e 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -223,6 +223,29 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, { } +Statement * +ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the forecast 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 ForecastStatement(new_symbol_list, options_list); +} + void ForecastStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d84ef1af..bc7dbcb1 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -109,6 +109,7 @@ public: ForecastStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RamseyModelStatement : public Statement From e82958222e22bc03719684fa0bae7454bd648865 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 31 Mar 2015 17:50:16 +0200 Subject: [PATCH 08/74] preprocessor: take care of extra exos in ramsey_model statement --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7fc5d59e..a17099ea 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -293,6 +293,29 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol mod_file_struct.k_order_solver = true; } +Statement * +RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the ramsey_model 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 RamseyModelStatement(new_symbol_list, options_list); +} + void RamseyModelStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index bc7dbcb1..b5da1f9d 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -122,6 +122,7 @@ public: const OptionsList &options_list_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); }; class RamseyPolicyStatement : public Statement From 33420148dd1525fa54d249e7dc8f7768284a985f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 14:19:51 +0200 Subject: [PATCH 09/74] preprocessor: take care of extra exos in ramsey_policy --- ComputingTasks.cc | 36 ++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 37 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index a17099ea..9fdd0430 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -377,6 +377,42 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.k_order_solver = true; } +Statement * +RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the ramsey_policy 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 RamseyPolicyStatement(new_symbol_list, new_options_list); +} + void RamseyPolicyStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index b5da1f9d..02e83750 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -135,6 +135,7 @@ public: const OptionsList &options_list_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); }; class DiscretionaryPolicyStatement : public Statement From 5163f2887118dcd15ac779b317bed88e0d94a75d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 14:26:07 +0200 Subject: [PATCH 10/74] preprocessor: take care of extra exos in discretionary_policy --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9fdd0430..b7b40e51 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -473,6 +473,29 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni mod_file_struct.k_order_solver = true; } +Statement * +DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the discretionary_policy 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 DiscretionaryPolicyStatement(new_symbol_list, options_list); +} + void DiscretionaryPolicyStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 02e83750..fbb94dff 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -148,6 +148,7 @@ public: const OptionsList &options_list_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); }; class RplotStatement : public Statement From 18624e0f8ffaaaa2fa97f6dcb2608f83e9dca3c7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 14:36:56 +0200 Subject: [PATCH 11/74] preprocessor: take care of extra exos in estimation --- ComputingTasks.cc | 36 ++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 37 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index b7b40e51..b90b65db 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -602,6 +602,42 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } +Statement * +EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimation 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 EstimationStatement(new_symbol_list, new_options_list); +} + void EstimationStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index fbb94dff..0dacf107 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -198,6 +198,7 @@ public: const OptionsList &options_list_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); }; class DynareSensitivityStatement : public Statement From c5b58ee1d93330af21aadcf8706d06ed17641873 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 15:06:04 +0200 Subject: [PATCH 12/74] preprocessor: take care of extra exos in dynare_sensitivity --- ComputingTasks.cc | 35 +++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 36 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index b90b65db..373b73fa 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -673,6 +673,41 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct, Warning mod_file_struct.identification_present = true; } +Statement * +DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + { + new_symbol_table->getID(*it2); + new_options_symbol_list.addSymbol(*it2); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the dynare_sensitivity 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 DynareSensitivityStatement(new_options_list); +} + void DynareSensitivityStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 0dacf107..786cf947 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -209,6 +209,7 @@ public: DynareSensitivityStatement(const OptionsList &options_list_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); }; class ObservationTrendsStatement : public Statement From e4b10c4ec6e1f6893b8336e057671c09c4fa1f6e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 1 Apr 2015 15:48:07 +0200 Subject: [PATCH 13/74] preprocessor: take care of extra exos in rplot --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1b14ebc6..7882a61f 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -735,6 +735,29 @@ RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : { } +Statement * +RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the rplot 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 RplotStatement(new_symbol_list); +} + void RplotStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index e1c659c1..a3dc37ca 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -158,6 +158,7 @@ private: public: RplotStatement(const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class UnitRootVarsStatement : public Statement From 27a69b8cec49525cd491e096cae2bcf46f9ba295 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 2 Apr 2015 17:42:01 +0200 Subject: [PATCH 14/74] take care of extra exos in estimated_params --- ComputingTasks.cc | 26 ++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7882a61f..b060df70 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -874,6 +874,32 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo mod_file_struct.estimated_parameters.insert(symbol_table.getID(it->name)); } +Statement * +EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + vector new_estim_params_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (!it->name2.empty()) + { + new_symbol_table->getID(it->name); + new_symbol_table->getID(it->name2); + } + else + new_symbol_table->getID(it->name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimated_params 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 EstimatedParamsStatement(estim_params_list, *new_symbol_table); +} + void EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index a3dc37ca..690315c7 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -318,6 +318,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); }; class EstimatedParamsInitStatement : public Statement From 5a60f2d9d7f1baf3807e95e63ecf9095c30fa07d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 2 Apr 2015 17:57:12 +0200 Subject: [PATCH 15/74] take care of extra exos in estimated_params_init --- ComputingTasks.cc | 26 ++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index b060df70..c617fbf4 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -975,6 +975,32 @@ EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, Warni mod_file_struct.estim_params_use_calib = true; } +Statement * +EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + vector new_estim_params_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (!it->name2.empty()) + { + new_symbol_table->getID(it->name); + new_symbol_table->getID(it->name2); + } + else + new_symbol_table->getID(it->name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimated_params_init 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 EstimatedParamsInitStatement(estim_params_list, *new_symbol_table, use_calibration); +} + void EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 690315c7..d1b08beb 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -333,6 +333,7 @@ public: const bool use_calibration_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); }; class EstimatedParamsBoundsStatement : public Statement From fd5b9279da0b583a6649ba09826230c4936893e0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 2 Apr 2015 18:03:16 +0200 Subject: [PATCH 16/74] take care of extra exos in estimated_params_bounds --- ComputingTasks.cc | 26 ++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 27 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index c617fbf4..4b7b7c7e 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1067,6 +1067,32 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector new_estim_params_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + if (!it->name2.empty()) + { + new_symbol_table->getID(it->name); + new_symbol_table->getID(it->name2); + } + else + new_symbol_table->getID(it->name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the estimated_params_bounds 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 EstimatedParamsBoundsStatement(estim_params_list, *new_symbol_table); +} + void EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index d1b08beb..968fd5d9 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -345,6 +345,7 @@ public: EstimatedParamsBoundsStatement(const vector &estim_params_list_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptimWeightsStatement : public Statement From e7218bd26a2fe05c44cb444e0df1a4ba1d90853c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:20:11 +0200 Subject: [PATCH 17/74] preprocessor: take care of extra exos in observation_trends --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 4b7b7c7e..9acdc06a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1181,6 +1181,29 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t { } +Statement * +ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + map new_trend_elements; + try + { + for (map::const_iterator it = trend_elements.begin(); + it != trend_elements.end(); it++) + { + new_symbol_table->getID(it->first); + new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + } + catch (...) + { + cerr << "ERROR: A variable in the observation_trends 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 ObservationTrendsStatement(new_trend_elements, *new_symbol_table); +} + void ObservationTrendsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 968fd5d9..3a4df94b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -222,6 +222,7 @@ public: ObservationTrendsStatement(const trend_elements_t &trend_elements_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OsrParamsStatement : public Statement From f852c834c2c32b986c3a405ff2de73fe3034ebba Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:21:54 +0200 Subject: [PATCH 18/74] preprocessor: update warning message for missing varexos --- ModFile.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ModFile.cc b/ModFile.cc index f21f8f62..570ad72a 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -300,7 +300,7 @@ ModFile::checkPass() if (++it != unusedExo.end()) warnings << ", "; } - warnings << ") are declared but not used in the model. This may lead to crashes or unexpected behaviour." << endl; + warnings << ") are declared but not used in the model. We have removed them and will attempt to continue..." << endl; } } From 6a634ba1043e15b3d76dc03992d8406712762563 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:30:55 +0200 Subject: [PATCH 19/74] preprocessor: take care of extra exos in osr_params --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9acdc06a..1274858b 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1237,6 +1237,29 @@ OsrParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid mod_file_struct.osr_params_present = true; } +Statement * +OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the osr_params 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 OsrParamsStatement(new_symbol_list); +} + void OsrParamsStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 3a4df94b..88d51c2c 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -233,6 +233,7 @@ public: OsrParamsStatement(const SymbolList &symbol_list_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); }; class OsrStatement : public Statement From 9dda8c40585b528f7e9664e9fcede9d7bf104f0f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:46:44 +0200 Subject: [PATCH 20/74] preprocessor: take care of extra exos in osr --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1274858b..1a9e4601 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1295,6 +1295,29 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation mod_file_struct.k_order_solver = true; } +Statement * +OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the osr 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 OsrStatement(new_symbol_list, options_list); +} + void OsrStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 88d51c2c..3736d0de 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -246,6 +246,7 @@ public: const OptionsList &options_list_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); }; class DynaTypeStatement : public Statement From de1af956047da881d79cceb48d35d1666785d6de Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 16:58:13 +0200 Subject: [PATCH 21/74] preprocessor: take care of extra exos in optim_weights --- ComputingTasks.cc | 33 +++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 34 insertions(+) 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 */ From 0c6f84bdcf8248a025abc7cb5958978333e5ea88 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 17:11:28 +0200 Subject: [PATCH 22/74] preprocessor: take care of extra exos in dynasave --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7f1e8f04..d32157f3 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1424,6 +1424,29 @@ DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg, { } +Statement * +DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the dynasave 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 DynaSaveStatement(new_symbol_list, filename); +} + void DynaSaveStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 01f3cd2e..dc9a873b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -269,6 +269,7 @@ public: DynaSaveStatement(const SymbolList &symbol_list_arg, const string &filename_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ModelComparisonStatement : public Statement From 47d0516d4fb76767b61711d940c2249e23687677 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Fri, 3 Apr 2015 17:15:01 +0200 Subject: [PATCH 23/74] preprocessor: take care of extra exos in dynatype --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index d32157f3..1d86564e 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1462,6 +1462,29 @@ DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg, { } +Statement * +DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the dynatype 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 DynaTypeStatement(new_symbol_list, filename); +} + void DynaTypeStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index dc9a873b..4eedddb4 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -258,6 +258,7 @@ public: DynaTypeStatement(const SymbolList &symbol_list_arg, const string &filename_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynaSaveStatement : public Statement From ef640070c27305584eef65fdbc5de7168f706e82 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 7 Apr 2015 15:11:39 +0200 Subject: [PATCH 24/74] preprocessor: move reindexing functions from DynamicModel to ModelTree --- DynamicModel.cc | 57 ------------------------------------------- DynamicModel.hh | 9 ------- ModFile.cc | 2 +- ModelTree.cc | 64 +++++++++++++++++++++++++++++++++++++++++++++++++ ModelTree.hh | 9 ++++++- 5 files changed, 73 insertions(+), 68 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index f27b1ca3..e881b302 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3429,47 +3429,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } -void -DynamicModel::reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) -{ - map orig_trend_symbols_map = trend_symbols_map; - trend_symbols_map.clear(); - for (map::const_iterator it = orig_trend_symbols_map.begin(); - it != orig_trend_symbols_map.end(); it++) - try - { - vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); - addTrendVariables(symb_id, - it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); - } - catch(...) - { - cerr << "Error: unused exo in trend symbols." << endl; - exit(EXIT_FAILURE); - } -} - -void -DynamicModel::reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) -{ - nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map; - nonstationary_symbols_map.clear(); - for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin(); - it != orig_nonstationary_symbols_map.end(); it++) - try - { - vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); - addNonstationaryVariables(symb_id, - it->second.first, - it->second.second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); - } - catch(...) - { - cerr << "Error: unused exo in nonstationary symbols." << endl; - exit(EXIT_FAILURE); - } -} - void DynamicModel::resetDataTree() { @@ -3483,22 +3442,6 @@ DynamicModel::resetDataTree() second_deriv_external_function_node_map.clear(); } -void -DynamicModel::reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table) -{ - map orig_local_variables_table = local_variables_table; - local_variables_table.clear(); - for (map::const_iterator it = orig_local_variables_table.begin(); - it != orig_local_variables_table.end(); it++) - dynamic_model.AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table)); - - vectoreqbak = equations; - equations.clear(); - for (size_t i = 0; i < eqbak.size(); i++) - dynamic_model.addEquation(eqbak[i]->cloneDynamicReindex(dynamic_model, orig_symbol_table), equations_lineno[i]); -} - void DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const { diff --git a/DynamicModel.hh b/DynamicModel.hh index 79f085de..e6a56675 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -235,15 +235,6 @@ public: /*! It assumes that the dynamic model given in argument has just been allocated */ void cloneDynamic(DynamicModel &dynamic_model) const; - //! reindex equations after change in symbol_table - void reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); - - //! reindex trend_symbol_map after change in symbol_table - void reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); - - //! reindex nonstationary_symbol_map after change in symbol_table - void reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table); - //! reset DataTree vars void resetDataTree(); diff --git a/ModFile.cc b/ModFile.cc index 570ad72a..d9f36dbb 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -314,7 +314,7 @@ ModFile::transformPass(bool nostrict) SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); dynamic_model.resetDataTree(); - dynamic_model.reindexEquations(dynamic_model, orig_symbol_table); + dynamic_model.reindex(orig_symbol_table); vector orig_statements = statements; statements.clear(); for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) diff --git a/ModelTree.cc b/ModelTree.cc index 688d4f29..b95a508e 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1413,6 +1413,70 @@ ModelTree::addAuxEquation(expr_t eq) aux_equations.push_back(beq); } +void +ModelTree::reindex(SymbolTable &orig_symbol_table) +{ + reindexEquations(orig_symbol_table); + reindexTrendSymbolsMap(orig_symbol_table); + reindexNonstationarySymbolsMap(orig_symbol_table); +} + +void +ModelTree::reindexEquations(SymbolTable &orig_symbol_table) +{ + map orig_local_variables_table = local_variables_table; + local_variables_table.clear(); + for (map::const_iterator it = orig_local_variables_table.begin(); + it != orig_local_variables_table.end(); it++) + AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(*this, orig_symbol_table)); + + vectoreqbak = equations; + equations.clear(); + for (size_t i = 0; i < eqbak.size(); i++) + addEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), equations_lineno[i]); +} + +void +ModelTree::reindexTrendSymbolsMap(SymbolTable &orig_symbol_table) +{ + map orig_trend_symbols_map = trend_symbols_map; + trend_symbols_map.clear(); + for (map::const_iterator it = orig_trend_symbols_map.begin(); + it != orig_trend_symbols_map.end(); it++) + try + { + vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); + addTrendVariables(symb_id, it->second->cloneDynamicReindex(*this, orig_symbol_table)); + } + catch(...) + { + cerr << "Error: unused exo in trend symbols." << endl; + exit(EXIT_FAILURE); + } +} + +void +ModelTree::reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table) +{ + nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map; + nonstationary_symbols_map.clear(); + for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin(); + it != orig_nonstationary_symbols_map.end(); it++) + try + { + vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); + addNonstationaryVariables(symb_id, + it->second.first, + it->second.second->cloneDynamicReindex(*this, orig_symbol_table)); + } + catch(...) + { + cerr << "Error: unused exo in nonstationary symbols." << endl; + exit(EXIT_FAILURE); + } +} + void ModelTree::addTrendVariables(vector trend_vars, expr_t growth_factor) throw (TrendException) { diff --git a/ModelTree.hh b/ModelTree.hh index 4d161daf..b86376b2 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -303,6 +303,13 @@ public: void addEquation(expr_t eq, int lineno, vector > &eq_tags); //! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations void addAuxEquation(expr_t eq); + void reindex(SymbolTable &orig_symbol_table); + //! reindex equations after change in symbol_table + void reindexEquations(SymbolTable &orig_symbol_table); + //! reindex trend_symbol_map after change in symbol_table + void reindexTrendSymbolsMap(SymbolTable &orig_symbol_table); + //! reindex nonstationary_symbol_map after change in symbol_table + void reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table); //! Returns the number of equations in the model int equation_number() const; //! Adds a trend variable with its growth factor From 5fb6667f869698b5e8b6341bbb5d6c7120a347ac Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 8 Apr 2015 14:04:05 +0200 Subject: [PATCH 25/74] preprocessor: take care of extra exos in external functions --- DataTree.cc | 8 ++++++- DataTree.hh | 2 ++ ExternalFunctionsTable.cc | 44 +++++++++++++++++++++++++++++++++++++-- ExternalFunctionsTable.hh | 6 +++++- ModelTree.cc | 1 + 5 files changed, 57 insertions(+), 4 deletions(-) diff --git a/DataTree.cc b/DataTree.cc index 3f90a44f..7135c9c6 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -50,6 +50,12 @@ DataTree::~DataTree() delete *it; } +void +DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table) +{ + external_functions_table.reindex(symbol_table, orig_symbol_table); +} + expr_t DataTree::AddNonNegativeConstant(const string &value) { diff --git a/DataTree.hh b/DataTree.hh index f81f19e6..87f61726 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -238,6 +238,8 @@ public: void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv void writePowerDeriv(ostream &output, bool use_dll) const; + //! reindex external functions + void reindexExternalFunctions(SymbolTable &orig_symbol_table); //! Thrown when trying to access an unknown variable by deriv_id class UnknownDerivIDException { diff --git a/ExternalFunctionsTable.cc b/ExternalFunctionsTable.cc index 8554d830..2fa1523d 100644 --- a/ExternalFunctionsTable.cc +++ b/ExternalFunctionsTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * @@ -24,7 +24,6 @@ #include #include "ExternalFunctionsTable.hh" -#include "SymbolTable.hh" ExternalFunctionsTable::ExternalFunctionsTable() { @@ -115,3 +114,44 @@ ExternalFunctionsTable::addExternalFunction(int symb_id, const external_function externalFunctionTable[symb_id] = external_function_options_chng; } + +void +ExternalFunctionsTable::reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table) +{ + external_function_table_type orig_externalFunctionTable = externalFunctionTable; + externalFunctionTable.clear(); + for (external_function_table_type::const_iterator it = orig_externalFunctionTable.begin(); + it != orig_externalFunctionTable.end(); it++) + try + { + external_function_options new_external_function_options; + if (it->second.firstDerivSymbID == eExtFunNotSet || + it->second.firstDerivSymbID == eExtFunSetButNoNameProvided) + new_external_function_options.firstDerivSymbID = it->second.firstDerivSymbID; + else + new_external_function_options.firstDerivSymbID = + new_symbol_table.getID(orig_symbol_table.getName(it->second.firstDerivSymbID)); + + if (it->second.secondDerivSymbID == eExtFunNotSet || + it->second.secondDerivSymbID == eExtFunSetButNoNameProvided) + new_external_function_options.secondDerivSymbID = it->second.secondDerivSymbID; + else + new_external_function_options.secondDerivSymbID = + new_symbol_table.getID(orig_symbol_table.getName(it->second.secondDerivSymbID)); + new_external_function_options.nargs = it->second.nargs; + bool new_track_nargs = true; + if (it->second.nargs == eExtFunNotSet) + { + new_track_nargs = false; + new_external_function_options.nargs = eExtFunSetDefaultNargs; + } + addExternalFunction(new_symbol_table.getID(orig_symbol_table.getName(it->first)), + new_external_function_options, + new_track_nargs); + } + catch (...) + { + cerr << "Error: problem encountered when reindexing external functions table." << endl; + exit(EXIT_FAILURE); + } +} diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index aa4b02cd..b5218bea 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2011 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * @@ -27,6 +27,8 @@ using namespace std; #include #include +#include "SymbolTable.hh" + enum ExternalFunctionSetOrNot { eExtFunSetButNoNameProvided = -2, //! Signifies that the derivative is obtained from the top-level function @@ -76,6 +78,8 @@ public: inline int getSecondDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException); //! Returns the total number of unique external functions declared or used in the .mod file inline int get_total_number_of_unique_model_block_external_functions() const; + //! Reindex external function table (after removal of extra exo) + void reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table); }; inline bool diff --git a/ModelTree.cc b/ModelTree.cc index b95a508e..b252d96d 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1419,6 +1419,7 @@ ModelTree::reindex(SymbolTable &orig_symbol_table) reindexEquations(orig_symbol_table); reindexTrendSymbolsMap(orig_symbol_table); reindexNonstationarySymbolsMap(orig_symbol_table); + reindexExternalFunctions(orig_symbol_table); } void From c22d5f6b2be6470c0d160bf233d2cf412e09be7b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 8 Apr 2015 16:35:09 +0200 Subject: [PATCH 26/74] preprocessor: take care of extra exos in planner_objective --- ComputingTasks.cc | 16 ++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 17 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1d86564e..7700ebc2 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1534,6 +1534,22 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct, WarningC mod_file_struct.planner_objective_present = true; } +Statement * +PlannerObjectiveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + model_tree->reindex(orig_symbol_table); + } + catch (...) + { + cerr << "ERROR: A variable in the planner_objective 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 PlannerObjectiveStatement(model_tree); +} + StaticModel * PlannerObjectiveStatement::getPlannerObjective() const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 4eedddb4..fdb894ee 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -390,6 +390,7 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; //! Return the Planner Objective StaticModel *getPlannerObjective() const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class BVARDensityStatement : public Statement From 5b029637e7ecc81e0978d281a57efdb5da0ded02 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 8 Apr 2015 17:30:45 +0200 Subject: [PATCH 27/74] preprocessor: take care of extra exos in ms_sbvar_irf --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7700ebc2..caad9f15 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1765,6 +1765,29 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } +Statement * +MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the ms_sbvar_irf 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 MSSBVARIrfStatement(new_symbol_list, options_list); +} + void MSSBVARIrfStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index fdb894ee..7d8a7a3b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -475,6 +475,7 @@ public: const OptionsList &options_list_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); }; class MSSBVARForecastStatement : public Statement From 1b81049cb04229d6fa3fb10787a494777aa365af Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:04:36 +0200 Subject: [PATCH 28/74] preprocessor: take care of extra exos in shock_decomposition --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index caad9f15..c4dc0778 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1946,6 +1946,29 @@ ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbo { } +Statement * +ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the shock_decomposition 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 ShockDecompositionStatement(new_symbol_list, options_list); +} + void ShockDecompositionStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 7d8a7a3b..03b1f4ce 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -544,6 +544,7 @@ public: ShockDecompositionStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ConditionalForecastStatement : public Statement From 6b79c05e451fdf10ab374fa182e3ec46c697f0f6 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:12:09 +0200 Subject: [PATCH 29/74] preprocessor: take care of extra exos in conditional_forecast --- ComputingTasks.cc | 30 ++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 31 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index c4dc0778..ebfdb366 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1982,6 +1982,36 @@ ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &op { } +Statement * +ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + OptionsList new_options_list = options_list; + try + { + OptionsList::symbol_list_options_t::const_iterator it = + options_list.symbol_list_options.find("controlled_varexo"); + if (it != options_list.symbol_list_options.end()) + { + SymbolList new_options_symbol_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the conditional_forecast 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 ConditionalForecastStatement(new_options_list); +} + void ConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 03b1f4ce..72c3649f 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -554,6 +554,7 @@ private: public: ConditionalForecastStatement(const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class PlotConditionalForecastStatement : public Statement From f329a2686e13c16c09da778b3bf2e8d8f3532f68 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 12:16:52 +0200 Subject: [PATCH 30/74] preprocessor: take care of extra exos in plot_conditional_forecast --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index ebfdb366..82327b03 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -2025,6 +2025,29 @@ PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_a { } +Statement * +PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + cerr << "ERROR: A variable in the plot_conditional_forecast 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 PlotConditionalForecastStatement(periods, new_symbol_list); +} + void PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 72c3649f..4c761a08 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -566,6 +566,7 @@ private: public: PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CalibSmootherStatement : public Statement From cb086756966db160f407b67b00a927cd8aa5df5d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 15:18:12 +0200 Subject: [PATCH 31/74] preprocessor: pointer to symbol_table unnecessary --- ComputingTasks.cc | 14 ++++++-------- NumericalInitialization.cc | 20 ++++++++------------ 2 files changed, 14 insertions(+), 20 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 82327b03..02adf8d7 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -1184,14 +1184,13 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t Statement * ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); map new_trend_elements; try { for (map::const_iterator it = trend_elements.begin(); it != trend_elements.end(); it++) { - new_symbol_table->getID(it->first); + symbol_table.getID(it->first); new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } } @@ -1201,7 +1200,7 @@ ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, S << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new ObservationTrendsStatement(new_trend_elements, *new_symbol_table); + return new ObservationTrendsStatement(new_trend_elements, symbol_table); } void @@ -1351,7 +1350,6 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso 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 @@ -1359,15 +1357,15 @@ OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Symbol for (var_weights_t::const_iterator it = var_weights.begin(); it != var_weights.end(); it++) { - new_symbol_table->getID(it->first); + 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); + symbol_table.getID(it->first.first); + 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); } @@ -1378,7 +1376,7 @@ OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Symbol << " 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); + return new OptimWeightsStatement(new_var_weights, new_covar_weights, symbol_table); } void diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 943bbb93..de910dc0 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -76,12 +76,11 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const Statement * InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { - return new InitParamStatement(new_symbol_table->getID(orig_symbol_table.getName(symb_id)), + return new InitParamStatement(symbol_table.getID(orig_symbol_table.getName(symb_id)), param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), - *new_symbol_table); + symbol_table); } catch (SymbolTable::UnknownSymbolIDException &e) { @@ -229,12 +228,11 @@ Statement * InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { init_values_t new_init_values; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { for (init_values_t::const_iterator it=init_values.begin(); it != init_values.end(); it++) - new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } catch (SymbolTable::UnknownSymbolIDException &e) @@ -243,7 +241,7 @@ InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new InitValStatement(new_init_values, *new_symbol_table, all_values_required); + return new InitValStatement(new_init_values, symbol_table, all_values_required); } EndValStatement::EndValStatement(const init_values_t &init_values_arg, @@ -296,12 +294,11 @@ Statement * EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { init_values_t new_init_values; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { for (init_values_t::const_iterator it=init_values.begin(); it != init_values.end(); it++) - new_init_values.push_back(make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first)), + new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } catch (SymbolTable::UnknownSymbolIDException &e) @@ -310,7 +307,7 @@ EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new EndValStatement(new_init_values, *new_symbol_table, all_values_required); + return new EndValStatement(new_init_values, symbol_table, all_values_required); } HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, @@ -383,12 +380,11 @@ Statement * HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { hist_values_t new_hist_values; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { for (hist_values_t::const_iterator it=hist_values.begin(); it != hist_values.end(); it++) - new_hist_values[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), + new_hist_values[make_pair(symbol_table.getID(orig_symbol_table.getName(it->first.first)), it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } @@ -398,7 +394,7 @@ HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable << " This likely means that you have declared a varexo that is not used in the model" << endl; exit(EXIT_FAILURE); } - return new HistValStatement(new_hist_values, *new_symbol_table); + return new HistValStatement(new_hist_values, symbol_table); } InitvalFileStatement::InitvalFileStatement(const string &filename_arg) : From 3deea8367db37425888cbe8bf114d733575b7308 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:14:25 +0200 Subject: [PATCH 32/74] preprocessor: remove unnecessary cloneAndReindexSymbIds method --- NumericalInitialization.cc | 7 ------- NumericalInitialization.hh | 1 - 2 files changed, 8 deletions(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index de910dc0..e588bc0d 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -543,10 +543,3 @@ LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) it != content.end(); it++) eval_context[it->first] = atof(it->second.c_str()); } - -Statement * -LoadParamsAndSteadyStateStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - WarningConsolidation warnings(false); - return new LoadParamsAndSteadyStateStatement(filename, *(dynamic_datatree.getSymbolTable()), warnings); -} diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index 913e2730..84f04770 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -174,7 +174,6 @@ public: virtual void writeOutput(ostream &output, const string &basename) const; //! Fill eval context with parameters/variables values void fillEvalContext(eval_context_t &eval_context) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif From bddcc87c6e114932cbd894fc2426f3201812f2c9 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:17:22 +0200 Subject: [PATCH 33/74] preprocessor: replace catch all exceptions in catch statements for clone/reindex methods --- ComputingTasks.cc | 38 +++++++++++++++++++------------------- NumericalInitialization.cc | 8 ++++---- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 02adf8d7..abf45b23 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -192,7 +192,7 @@ StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the stoch_simul 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; @@ -237,7 +237,7 @@ ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the forecast 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; @@ -307,7 +307,7 @@ RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolT new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the ramsey_model 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; @@ -404,7 +404,7 @@ RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Symbol new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the ramsey_policy 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; @@ -487,7 +487,7 @@ DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the discretionary_policy 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; @@ -629,7 +629,7 @@ EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimation 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; @@ -699,7 +699,7 @@ DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, S } } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the dynare_sensitivity 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; @@ -749,7 +749,7 @@ RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable & new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the rplot 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; @@ -891,7 +891,7 @@ EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Sym else new_symbol_table->getID(it->name); } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimated_params 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; @@ -992,7 +992,7 @@ EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, else new_symbol_table->getID(it->name); } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimated_params_init 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; @@ -1084,7 +1084,7 @@ EstimatedParamsBoundsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatre else new_symbol_table->getID(it->name); } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the estimated_params_bounds 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; @@ -1250,7 +1250,7 @@ OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the osr_params 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; @@ -1308,7 +1308,7 @@ OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &or new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the osr 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; @@ -1436,7 +1436,7 @@ DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the dynasave 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; @@ -1474,7 +1474,7 @@ DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the dynatype 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; @@ -1777,7 +1777,7 @@ MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the ms_sbvar_irf 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; @@ -1958,7 +1958,7 @@ ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the shock_decomposition 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; @@ -2001,7 +2001,7 @@ ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the conditional_forecast 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; @@ -2037,7 +2037,7 @@ PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datat new_symbol_list.addSymbol(*it); } } - catch (SymbolTable::UnknownSymbolNameException &e) + catch (...) { cerr << "ERROR: A variable in the plot_conditional_forecast 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; diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index e588bc0d..08a172f8 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -82,7 +82,7 @@ InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), symbol_table); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: encountered in InitParamStatement::cloneAndReindexSymbIds. Should not arrive here" << endl; exit(EXIT_FAILURE); @@ -235,7 +235,7 @@ InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: A variable in the initval 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; @@ -301,7 +301,7 @@ EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: A variable in the endval 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; @@ -388,7 +388,7 @@ HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); } - catch (SymbolTable::UnknownSymbolIDException &e) + catch (...) { cerr << "ERROR: A variable in the hist_val 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; From 6df3bb785e616791ce290071bc9861bdabf00d39 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:17:47 +0200 Subject: [PATCH 34/74] preprocessor: fix error message for InitParamStatement clone/reindex method --- NumericalInitialization.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 08a172f8..501f202b 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -84,7 +84,8 @@ InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTab } catch (...) { - cerr << "ERROR: encountered in InitParamStatement::cloneAndReindexSymbIds. Should not arrive here" << endl; + cerr << "ERROR: A variable in the init_param 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); } } From 8719bbff32387cdad098fba0e127aa727c83deaa Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 9 Apr 2015 16:29:52 +0200 Subject: [PATCH 35/74] preprocessor: take care of extra exos in ramsey_model instruments option --- ComputingTasks.cc | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index abf45b23..01a7205f 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -296,7 +296,8 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol Statement * RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolList new_symbol_list; + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; try { SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); @@ -306,6 +307,19 @@ RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolT new_symbol_table->getID(*it); new_symbol_list.addSymbol(*it); } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + } catch (...) { From 7cc464b5ea9cbe633df27bad6c648da83d8b595b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 12:06:53 +0200 Subject: [PATCH 36/74] preprocessor: take care of exos in prior statements --- ComputingTasks.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 4 +++ 2 files changed, 87 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index bc004ae0..9d1a93b7 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -2974,6 +2974,23 @@ PriorStatement::PriorStatement(const string &name_arg, { } +Statement * +PriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the prior 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 PriorStatement(name, subsample_name, prior_shape, variance, options_list); +} + void PriorStatement::writeOutput(ostream &output, const string &basename) const { @@ -3011,6 +3028,23 @@ StdPriorStatement::StdPriorStatement(const string &name_arg, { } +Statement * +StdPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the std_prior 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 StdPriorStatement(name, subsample_name, prior_shape, variance, options_list, *new_symbol_table); +} + void StdPriorStatement::writeOutput(ostream &output, const string &basename) const { @@ -3074,6 +3108,24 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } } +Statement * +CorrPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + new_symbol_table->getID(name1); + } + catch (...) + { + cerr << "ERROR: A variable in the corr_prior 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 CorrPriorStatement(name, name1, subsample_name, prior_shape, variance, options_list, *new_symbol_table); +} + void CorrPriorStatement::writeOutput(ostream &output, const string &basename) const { @@ -3153,6 +3205,37 @@ PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } +Statement * +PriorEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(to_name1); + if (!to_name2.empty()) + new_symbol_table->getID(to_name2); + + new_symbol_table->getID(from_name1); + if (!from_name2.empty()) + new_symbol_table->getID(from_name2); + } + catch (...) + { + cerr << "ERROR: A variable in the prior equal 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 PriorEqualStatement(to_declaration_type, + to_name1, + to_name2, + to_subsample_name, + from_declaration_type, + from_name1, + from_name2, + from_subsample_name, + *new_symbol_table); +} + void PriorEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 4c761a08..b6625e81 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -756,6 +756,7 @@ public: const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdPriorStatement : public BasicPriorStatement @@ -771,6 +772,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrPriorStatement : public BasicPriorStatement @@ -789,6 +791,7 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class PriorEqualStatement : public Statement @@ -816,6 +819,7 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; 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); }; class BasicOptionsStatement : public Statement From 1165c2608bab8ab94c5027e7143372ac55456df1 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 12:49:15 +0200 Subject: [PATCH 37/74] preprocessor: take care of exos in options statements --- ComputingTasks.cc | 83 +++++++++++++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 4 +++ 2 files changed, 87 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 9d1a93b7..4955fa1c 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3391,6 +3391,23 @@ OptionsStatement::OptionsStatement(const string &name_arg, { } +Statement * +OptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the options 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 OptionsStatement(name, subsample_name, options_list); +} + void OptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3419,6 +3436,23 @@ StdOptionsStatement::StdOptionsStatement(const string &name_arg, { } +Statement * +StdOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + } + catch (...) + { + cerr << "ERROR: A variable in the std_options 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 StdOptionsStatement(name, subsample_name, options_list, *new_symbol_table); +} + void StdOptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3474,6 +3508,24 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } } +Statement * +CorrOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(name); + new_symbol_table->getID(name1); + } + catch (...) + { + cerr << "ERROR: A variable in the corr_options 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 CorrOptionsStatement(name, name1, subsample_name, options_list, *new_symbol_table); +} + void CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const { @@ -3521,6 +3573,37 @@ OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } } +Statement * +OptionsEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + try + { + new_symbol_table->getID(to_name1); + if (!to_name2.empty()) + new_symbol_table->getID(to_name2); + + new_symbol_table->getID(from_name1); + if (!from_name2.empty()) + new_symbol_table->getID(from_name2); + } + catch (...) + { + cerr << "ERROR: A variable in the options equal 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 OptionsEqualStatement(to_declaration_type, + to_name1, + to_name2, + to_subsample_name, + from_declaration_type, + from_name1, + from_name2, + from_subsample_name, + *new_symbol_table); +} + void OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index b6625e81..3d3f07f5 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -850,6 +850,7 @@ public: OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdOptionsStatement : public BasicOptionsStatement @@ -863,6 +864,7 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrOptionsStatement : public BasicOptionsStatement @@ -878,6 +880,7 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename) const; virtual void writeCOutput(ostream &output, const string &basename); + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptionsEqualStatement : public Statement @@ -905,6 +908,7 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; 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); }; class ModelDiagnosticsStatement : public Statement From e4f3d31757c6efe002df0c5eafd062b5bb21c2ea Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 14:42:17 +0200 Subject: [PATCH 38/74] preprocessor: take care of exos in calib_smoother statements --- ComputingTasks.cc | 23 +++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 24 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 4955fa1c..1f10ea5a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3687,6 +3687,29 @@ CalibSmootherStatement::checkPass(ModFileStructure &mod_file_struct, WarningCons mod_file_struct.calib_smoother_present = true; } +Statement * +CalibSmootherStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_symbol_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + } + catch (...) + { + cerr << "ERROR: A variable in the calib_smoother 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 CalibSmootherStatement(new_symbol_list, options_list); +} + void CalibSmootherStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 3d3f07f5..7f17a30a 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -579,6 +579,7 @@ public: const OptionsList &options_list_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); }; class ExtendedPathStatement : public Statement From f76a6cb58b3f485d2a987f8082e2e7a81da17348 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 15:04:46 +0200 Subject: [PATCH 39/74] preprocessor: take care of exos in smoother2histval statement --- ComputingTasks.cc | 35 +++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 1 + 2 files changed, 36 insertions(+) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 5fafda9e..7c290d29 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -3794,6 +3794,41 @@ Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_ { } +Statement * +Smoother2histvalStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +{ + SymbolList new_options_symbol_list; + OptionsList new_options_list = options_list; + try + { + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"invars", "outvars"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + { + new_symbol_table->getID(*it2); + new_options_symbol_list.addSymbol(*it2); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + } + catch (...) + { + cerr << "ERROR: A variable in the smoother2histval 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 Smoother2histvalStatement(new_options_list); +} + void Smoother2histvalStatement::writeOutput(ostream &output, const string &basename) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 7f17a30a..a59ad9ad 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -926,6 +926,7 @@ private: public: Smoother2histvalStatement(const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename) const; + virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif From 0a7172cb50d98aa87cd756514e9b1a8ae8f1a489 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 14 Apr 2015 18:13:28 +0200 Subject: [PATCH 40/74] preprocessor: little fixes for removing unused exos from symbol_table --- SymbolTable.cc | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index 490dbb31..ffaa7bb8 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -482,12 +482,7 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) list idxs; for (set::const_iterator it = unused.begin(); it != unused.end(); it++) - { - string name = getName(*it); - idxs.push_back(symbol_table[name]); - symbol_table.erase(name); - size--; - } + idxs.push_back(getID(getName(*it))); idxs.sort(); idxs.reverse(); @@ -500,10 +495,10 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) } symbol_table.clear(); - int i = 0; + size = 0; for (vector::const_iterator it=name_table.begin(); it != name_table.end(); it++) - symbol_table[*it] = i++; + symbol_table[*it] = size++; assert(size == symbol_table.size()); } From cb1fb288f4887701f7353695e39240161145d4ac Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Apr 2015 14:21:05 +0200 Subject: [PATCH 41/74] preprocessor: remove clearing of num_const_node_map --- DynamicModel.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index e881b302..c6c308e1 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3432,7 +3432,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode void DynamicModel::resetDataTree() { - num_const_node_map.clear(); variable_node_map.clear(); unary_op_node_map.clear(); binary_op_node_map.clear(); From e045d42c12da1bea7d00432cbead9fab1d76717d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Apr 2015 16:16:26 +0200 Subject: [PATCH 42/74] preprocessor: remove resetDataTree method --- DynamicModel.cc | 12 ------------ DynamicModel.hh | 3 --- ModFile.cc | 1 - ModelTree.cc | 8 ++++++++ 4 files changed, 8 insertions(+), 16 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index c6c308e1..1de6bc8c 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3429,18 +3429,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode writeDynamicMFile(t_basename); } -void -DynamicModel::resetDataTree() -{ - variable_node_map.clear(); - unary_op_node_map.clear(); - binary_op_node_map.clear(); - trinary_op_node_map.clear(); - external_function_node_map.clear(); - first_deriv_external_function_node_map.clear(); - second_deriv_external_function_node_map.clear(); -} - void DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const { diff --git a/DynamicModel.hh b/DynamicModel.hh index e6a56675..7c4b5e0e 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -235,9 +235,6 @@ public: /*! It assumes that the dynamic model given in argument has just been allocated */ void cloneDynamic(DynamicModel &dynamic_model) const; - //! reset DataTree vars - void resetDataTree(); - //! Replaces model equations with derivatives of Lagrangian w.r.t. endogenous void computeRamseyPolicyFOCs(const StaticModel &static_model); //! Replaces the model equations in dynamic_model with those in this model diff --git a/ModFile.cc b/ModFile.cc index d9f36dbb..c1c345ff 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -313,7 +313,6 @@ ModFile::transformPass(bool nostrict) { SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); - dynamic_model.resetDataTree(); dynamic_model.reindex(orig_symbol_table); vector orig_statements = statements; statements.clear(); diff --git a/ModelTree.cc b/ModelTree.cc index b252d96d..6f3a10e5 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1416,6 +1416,14 @@ ModelTree::addAuxEquation(expr_t eq) void ModelTree::reindex(SymbolTable &orig_symbol_table) { + variable_node_map.clear(); + unary_op_node_map.clear(); + binary_op_node_map.clear(); + trinary_op_node_map.clear(); + external_function_node_map.clear(); + first_deriv_external_function_node_map.clear(); + second_deriv_external_function_node_map.clear(); + reindexEquations(orig_symbol_table); reindexTrendSymbolsMap(orig_symbol_table); reindexNonstationarySymbolsMap(orig_symbol_table); From b27a60d06ce2a3262548889d70de43b1c7fe0e1a Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Apr 2015 17:00:17 +0200 Subject: [PATCH 43/74] preprocessor: reindex equations marked as [static] --- DynamicModel.cc | 9 +++++++++ DynamicModel.hh | 3 +++ ModFile.cc | 1 + 3 files changed, 13 insertions(+) diff --git a/DynamicModel.cc b/DynamicModel.cc index 1de6bc8c..8805ceb1 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4294,6 +4294,15 @@ DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) static_only_equations_lineno.push_back(lineno); } +void +DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) +{ + vectoreqbak = static_only_equations; + static_only_equations.clear(); + for (size_t i = 0; i < eqbak.size(); i++) + addStaticOnlyEquation(eqbak[i]->cloneDynamic(*this), static_only_equations_lineno[i]); +} + size_t DynamicModel::staticOnlyEquationsNbr() const { diff --git a/DynamicModel.hh b/DynamicModel.hh index 7c4b5e0e..d87093e7 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -243,6 +243,9 @@ public: //! Adds an equation marked as [static] void addStaticOnlyEquation(expr_t eq, int lineno); + //! reindex equations marked as [static] + void reindexStaticOnlyEquations(SymbolTable &orig_symbol_table); + //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; diff --git a/ModFile.cc b/ModFile.cc index c1c345ff..b4767def 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -314,6 +314,7 @@ ModFile::transformPass(bool nostrict) SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); + dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); vector orig_statements = statements; statements.clear(); for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) From a39448b63fd0331ace54c6320982756396389a5e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 16 Apr 2015 16:45:17 +0200 Subject: [PATCH 44/74] fix typo --- ComputingTasks.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 7c290d29..d7d11787 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -317,7 +317,7 @@ RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolT new_symbol_table->getID(*it1); new_options_symbol_list.addSymbol(*it1); } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; } } From 781039752aa8852d59ee043e2aa68fd7564dcf03 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 16 Apr 2015 17:13:19 +0200 Subject: [PATCH 45/74] preprocessor: take care of instruments option in discretionary_policy squash --- ComputingTasks.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index d7d11787..5070ae5a 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -490,7 +490,8 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni Statement * DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolList new_symbol_list; + SymbolList new_symbol_list, new_options_symbol_list; + OptionsList new_options_list = options_list; try { SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); @@ -500,6 +501,18 @@ DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, new_symbol_table->getID(*it); new_symbol_list.addSymbol(*it); } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) + { + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } } catch (...) { From 6905456cb36dda3ceb837f0932c21e581c6fa375 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 16 Apr 2015 15:41:07 +0200 Subject: [PATCH 46/74] preprocessor: provide more info in error message --- ComputingTasks.cc | 1187 +++++++++++++++++++++++------------- NumericalInitialization.cc | 93 ++- 2 files changed, 840 insertions(+), 440 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 5070ae5a..db890793 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -168,34 +168,55 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the stoch_simul 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; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the stoch_simul statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new StochSimulStatement(new_symbol_list, new_options_list); @@ -226,23 +247,31 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, Statement * ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the forecast 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; + cerr << endl + << "ERROR: The following vars were used in the forecast statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } + return new ForecastStatement(new_symbol_list, options_list); } @@ -296,35 +325,55 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol Statement * RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; } - catch (...) + + if (!errors.empty()) { - cerr << "ERROR: A variable in the ramsey_model 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; + cerr << endl + << "ERROR: The following vars were used in the ramsey_model statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new RamseyModelStatement(new_symbol_list, options_list); @@ -394,37 +443,58 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the ramsey_policy 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; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the ramsey_policy statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } - return new RamseyPolicyStatement(new_symbol_list, new_options_list); + return new RamseyPolicyStatement(new_symbol_list, options_list); } void @@ -490,34 +560,55 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni Statement * DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the discretionary_policy 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; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the discretionary_policy statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DiscretionaryPolicyStatement(new_symbol_list, options_list); @@ -632,34 +723,55 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list, new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; - } - } - catch (...) + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); + if (it != options_list.symbol_list_options.end()) { - cerr << "ERROR: A variable in the estimation 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; + symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the estimation statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimationStatement(new_symbol_list, new_options_list); @@ -703,33 +815,53 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct, Warning Statement * DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; - vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - { - OptionsList::symbol_list_options_t::const_iterator it1 = - options_list.symbol_list_options.find(*it); - if (it1 != options_list.symbol_list_options.end()) - { - vector symbols = it1->second.get_symbols(); - for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + try { new_symbol_table->getID(*it2); new_options_symbol_list.addSymbol(*it2); } - new_options_list.symbol_list_options[*it] = new_options_symbol_list; - } - } - } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the dynare_sensitivity 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; + cerr << endl + << "ERROR: The following vars were used in the dynare_sensitivity statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DynareSensitivityStatement(new_options_list); @@ -765,21 +897,28 @@ RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : Statement * RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the rplot 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; + cerr << endl + << "ERROR: The following vars were used in the rplot statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new RplotStatement(new_symbol_list); @@ -904,12 +1043,14 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo Statement * EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; vector new_estim_params_list; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) + + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + try + { if (!it->name2.empty()) { new_symbol_table->getID(it->name); @@ -917,11 +1058,19 @@ EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, Sym } else new_symbol_table->getID(it->name); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the estimated_params 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; + cerr << endl + << "ERROR: The following vars were used in the estimated_params statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimatedParamsStatement(estim_params_list, *new_symbol_table); @@ -1005,12 +1154,13 @@ EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, Warni Statement * EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; vector new_estim_params_list; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + try + { if (!it->name2.empty()) { new_symbol_table->getID(it->name); @@ -1018,11 +1168,19 @@ EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, } else new_symbol_table->getID(it->name); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the estimated_params_init 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; + cerr << endl + << "ERROR: The following vars were used in the estimated_params_init statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimatedParamsInitStatement(estim_params_list, *new_symbol_table, use_calibration); @@ -1097,12 +1255,13 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector errors; vector new_estim_params_list; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) + for (vector::const_iterator it = estim_params_list.begin(); + it != estim_params_list.end(); it++) + try + { if (!it->name2.empty()) { new_symbol_table->getID(it->name); @@ -1110,11 +1269,19 @@ EstimatedParamsBoundsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatre } else new_symbol_table->getID(it->name); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the estimated_params_bounds 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; + cerr << endl + << "ERROR: The following vars were used in the estimated_params_bounds statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EstimatedParamsBoundsStatement(estim_params_list, *new_symbol_table); @@ -1211,20 +1378,31 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t Statement * ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; map new_trend_elements; - try + for (map::const_iterator it = trend_elements.begin(); + it != trend_elements.end(); it++) + try + { + symbol_table.getID(it->first); + new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - for (map::const_iterator it = trend_elements.begin(); - it != trend_elements.end(); it++) - { - symbol_table.getID(it->first); - new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - } - catch (...) - { - cerr << "ERROR: A variable in the observation_trends 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; + cerr << endl + << "ERROR: The following vars were used in the observation_trends statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new ObservationTrendsStatement(new_trend_elements, symbol_table); @@ -1266,21 +1444,28 @@ OsrParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid Statement * OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the osr_params 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; + cerr << endl + << "ERROR: The following vars were used in the osr_params statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new OsrParamsStatement(new_symbol_list); @@ -1324,21 +1509,28 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation Statement * OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the osr 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; + cerr << endl + << "ERROR: The following vars were used in the osr statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new OsrStatement(new_symbol_list, options_list); @@ -1377,30 +1569,51 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; 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++) - { - 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++) - { - symbol_table.getID(it->first.first); - 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 (...) + for (var_weights_t::const_iterator it = var_weights.begin(); + it != var_weights.end(); it++) + try + { + symbol_table.getID(it->first); + new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + for (covar_weights_t::const_iterator it = covar_weights.begin(); + it != covar_weights.end(); it++) + try + { + symbol_table.getID(it->first.first); + 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 (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - 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; + cerr << endl + << "ERROR: The following vars were used in the optim_weights statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new OptimWeightsStatement(new_var_weights, new_covar_weights, symbol_table); @@ -1452,21 +1665,28 @@ DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg, Statement * DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the dynasave 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; + cerr << endl + << "ERROR: The following vars were used in the dynasave statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DynaSaveStatement(new_symbol_list, filename); @@ -1490,21 +1710,28 @@ DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg, Statement * DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the dynatype 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; + cerr << endl + << "ERROR: The following vars were used in the dynatype statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new DynaTypeStatement(new_symbol_list, filename); @@ -1562,14 +1789,26 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct, WarningC Statement * PlannerObjectiveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + string error; try { model_tree->reindex(orig_symbol_table); } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) { - cerr << "ERROR: A variable in the planner_objective 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; + error = orig_symbol_table.getName(e.id); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + error = e.name; + } + + if (!error.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the planner_objective statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << error << endl; exit(EXIT_FAILURE); } return new PlannerObjectiveStatement(model_tree); @@ -1793,21 +2032,28 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the ms_sbvar_irf 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; + cerr << endl + << "ERROR: The following vars were used in the ms_sbvar_irf statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new MSSBVARIrfStatement(new_symbol_list, options_list); @@ -1974,21 +2220,28 @@ ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbo Statement * ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the shock_decomposition 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; + cerr << endl + << "ERROR: The following vars were used in the shock_decomposition statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new ShockDecompositionStatement(new_symbol_list, options_list); @@ -2010,28 +2263,39 @@ ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &op Statement * ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; OptionsList new_options_list = options_list; - try + OptionsList::symbol_list_options_t::const_iterator it = + options_list.symbol_list_options.find("controlled_varexo"); + if (it != options_list.symbol_list_options.end()) { - OptionsList::symbol_list_options_t::const_iterator it = - options_list.symbol_list_options.find("controlled_varexo"); - if (it != options_list.symbol_list_options.end()) - { - SymbolList new_options_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; - } + SymbolList new_options_symbol_list; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = it->second.get_symbols(); + for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) + try + { + new_symbol_table->getID(*it1); + new_options_symbol_list.addSymbol(*it1); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; } - catch (...) + + if (!errors.empty()) { - cerr << "ERROR: A variable in the conditional_forecast 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; + cerr << endl + << "ERROR: The following vars were used in the conditional_forecast statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new ConditionalForecastStatement(new_options_list); @@ -2053,21 +2317,28 @@ PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_a Statement * PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the plot_conditional_forecast 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; + cerr << endl + << "ERROR: The following vars were used in the plot_conditional_forecast statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new PlotConditionalForecastStatement(periods, new_symbol_list); @@ -2995,10 +3266,12 @@ PriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable & SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the prior 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; + cerr << endl + << "ERROR: The following vars were used in the prior statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new PriorStatement(name, subsample_name, prior_shape, variance, options_list); @@ -3049,10 +3322,12 @@ StdPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTabl { new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the std_prior 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; + cerr << endl + << "ERROR: The following vars were used in the std_prior statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new StdPriorStatement(name, subsample_name, prior_shape, variance, options_list, *new_symbol_table); @@ -3124,16 +3399,32 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid Statement * CorrPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { new_symbol_table->getID(name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + try + { new_symbol_table->getID(name1); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the corr_prior 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; + errors.push_back(e.name); + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the std_prior statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new CorrPriorStatement(name, name1, subsample_name, prior_shape, variance, options_list, *new_symbol_table); @@ -3221,21 +3512,32 @@ PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli Statement * PriorEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(to_name1); - if (!to_name2.empty()) - new_symbol_table->getID(to_name2); + vector errors; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string names_to_check[] = {to_name1, to_name2, from_name1, from_name2}; + vector opts (names_to_check, names_to_check + sizeof(names_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + if (!it->empty()) + new_symbol_table->getID(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } - new_symbol_table->getID(from_name1); - if (!from_name2.empty()) - new_symbol_table->getID(from_name2); - } - catch (...) + if (!errors.empty()) { - cerr << "ERROR: A variable in the prior equal 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; + cerr << endl + << "ERROR: The following vars were used in the prior equal statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new PriorEqualStatement(to_declaration_type, @@ -3412,10 +3714,12 @@ OptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the options 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; + cerr << endl + << "ERROR: The following vars were used in the options statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new OptionsStatement(name, subsample_name, options_list); @@ -3457,10 +3761,12 @@ StdOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTa { new_symbol_table->getID(name); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the std_options 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; + cerr << endl + << "ERROR: The following vars were used in the std_options statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << e.name << endl; exit(EXIT_FAILURE); } return new StdOptionsStatement(name, subsample_name, options_list, *new_symbol_table); @@ -3524,18 +3830,36 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol Statement * CorrOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); try { new_symbol_table->getID(name); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + try + { new_symbol_table->getID(name1); } - catch (...) + catch (SymbolTable::UnknownSymbolNameException &e) { - cerr << "ERROR: A variable in the corr_options 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; + errors.push_back(e.name); + } + + if (!errors.empty()) + { + cerr << endl + << "ERROR: The following vars were used in the corr_options statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } + return new CorrOptionsStatement(name, name1, subsample_name, options_list, *new_symbol_table); } @@ -3616,23 +3940,35 @@ OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso Statement * OptionsEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(to_name1); - if (!to_name2.empty()) - new_symbol_table->getID(to_name2); + vector errors; + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string names_to_check[] = {to_name1, to_name2, from_name1, from_name2}; + vector opts (names_to_check, names_to_check + sizeof(names_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + if (!it->empty()) + new_symbol_table->getID(*it); + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } - new_symbol_table->getID(from_name1); - if (!from_name2.empty()) - new_symbol_table->getID(from_name2); - } - catch (...) + if (!errors.empty()) { - cerr << "ERROR: A variable in the options equal 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; + cerr << endl + << "ERROR: The following vars were used in the options equal statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } + return new OptionsEqualStatement(to_declaration_type, to_name1, to_name2, @@ -3730,21 +4066,28 @@ CalibSmootherStatement::checkPass(ModFileStructure &mod_file_struct, WarningCons Statement * CalibSmootherStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_symbol_list; - try + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + vector symbols = symbol_list.get_symbols(); + for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) + try + { + new_symbol_table->getID(*it); + new_symbol_list.addSymbol(*it); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - } - catch (...) - { - cerr << "ERROR: A variable in the calib_smoother 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; + cerr << endl + << "ERROR: The following vars were used in the calib_smoother statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new CalibSmootherStatement(new_symbol_list, options_list); @@ -3810,33 +4153,53 @@ Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_ Statement * Smoother2histvalStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; SymbolList new_options_symbol_list; OptionsList new_options_list = options_list; - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string opts_to_check[] = {"invars", "outvars"}; - vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - { - OptionsList::symbol_list_options_t::const_iterator it1 = - options_list.symbol_list_options.find(*it); - if (it1 != options_list.symbol_list_options.end()) - { - vector symbols = it1->second.get_symbols(); - for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); + string opts_to_check[] = {"invars", "outvars"}; + vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); + for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) + try + { + OptionsList::symbol_list_options_t::const_iterator it1 = + options_list.symbol_list_options.find(*it); + if (it1 != options_list.symbol_list_options.end()) + { + vector symbols = it1->second.get_symbols(); + for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) + try { new_symbol_table->getID(*it2); new_options_symbol_list.addSymbol(*it2); } - new_options_list.symbol_list_options[*it] = new_options_symbol_list; - } - } - } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + new_options_list.symbol_list_options[*it] = new_options_symbol_list; + } + } + catch (SymbolTable::UnknownSymbolIDException &e) + { + errors.push_back(orig_symbol_table.getName(e.id)); + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the smoother2histval 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; + cerr << endl + << "ERROR: The following vars were used in the smoother2histval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new Smoother2histvalStatement(new_options_list); diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 501f202b..44fa2efd 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -76,18 +76,27 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const Statement * InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + string error; try { return new InitParamStatement(symbol_table.getID(orig_symbol_table.getName(symb_id)), param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), symbol_table); } - catch (...) + catch (SymbolTable::UnknownSymbolIDException &e) { - cerr << "ERROR: A variable in the init_param 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); + error = orig_symbol_table.getName(e.id); } + catch (SymbolTable::UnknownSymbolNameException &e) + { + error = e.name; + } + + cerr << endl + << "ERROR: The following vars were used in the init param statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl + << error << endl; + exit(EXIT_FAILURE); } InitOrEndValStatement::InitOrEndValStatement(const init_values_t &init_values_arg, @@ -228,18 +237,27 @@ InitValStatement::writeOutputPostInit(ostream &output) const Statement * InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; init_values_t new_init_values; - try - { - for (init_values_t::const_iterator it=init_values.begin(); - it != init_values.end(); it++) + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + try + { new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the initval 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; + cerr << endl + << "ERROR: The following vars were used in the initval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new InitValStatement(new_init_values, symbol_table, all_values_required); @@ -294,18 +312,28 @@ EndValStatement::writeOutput(ostream &output, const string &basename) const Statement * EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; init_values_t new_init_values; - try - { - for (init_values_t::const_iterator it=init_values.begin(); - it != init_values.end(); it++) + + for (init_values_t::const_iterator it=init_values.begin(); + it != init_values.end(); it++) + try + { new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the endval 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; + cerr << endl + << "ERROR: The following vars were used in the endval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new EndValStatement(new_init_values, symbol_table, all_values_required); @@ -380,19 +408,28 @@ HistValStatement::writeOutput(ostream &output, const string &basename) const Statement * HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) { + vector errors; hist_values_t new_hist_values; - try - { - for (hist_values_t::const_iterator it=hist_values.begin(); - it != hist_values.end(); it++) + for (hist_values_t::const_iterator it=hist_values.begin(); + it != hist_values.end(); it++) + try + { new_hist_values[make_pair(symbol_table.getID(orig_symbol_table.getName(it->first.first)), it->first.second)] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (...) + } + catch (SymbolTable::UnknownSymbolNameException &e) + { + errors.push_back(e.name); + } + + if (!errors.empty()) { - cerr << "ERROR: A variable in the hist_val 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; + cerr << endl + << "ERROR: The following vars were used in the histval statement(s) but were not declared." << endl + << " This likely means that you declared them as varexo and that they're not in the model" << endl; + for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) + cerr << *it << endl; exit(EXIT_FAILURE); } return new HistValStatement(new_hist_values, symbol_table); From 48014c37871fca11c9065debe117507511f74c7c Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 21 Apr 2015 15:06:56 +0200 Subject: [PATCH 47/74] preprocessor: take care of expressions_tree and steady_state_model --- DataTree.cc | 26 ++++++++++++++++++++++++++ DataTree.hh | 2 ++ ModFile.cc | 7 +++++++ ModelTree.cc | 17 +---------------- SymbolTable.cc | 19 +++++++++++++++++++ SymbolTable.hh | 2 ++ 6 files changed, 57 insertions(+), 16 deletions(-) diff --git a/DataTree.cc b/DataTree.cc index 7135c9c6..b45d4479 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -50,6 +50,32 @@ DataTree::~DataTree() delete *it; } +void +DataTree::reindex(SymbolTable &orig_symbol_table) +{ + variable_node_map.clear(); + unary_op_node_map.clear(); + binary_op_node_map.clear(); + trinary_op_node_map.clear(); + external_function_node_map.clear(); + first_deriv_external_function_node_map.clear(); + second_deriv_external_function_node_map.clear(); + + reindexExternalFunctions(orig_symbol_table); + reindexLocalVars(orig_symbol_table); +} + +void +DataTree::reindexLocalVars(SymbolTable &orig_symbol_table) +{ + map orig_local_variables_table = local_variables_table; + local_variables_table.clear(); + for (map::const_iterator it = orig_local_variables_table.begin(); + it != orig_local_variables_table.end(); it++) + AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), + it->second->cloneDynamicReindex(*this, orig_symbol_table)); +} + void DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table) { diff --git a/DataTree.hh b/DataTree.hh index 87f61726..9d0f746c 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -240,6 +240,8 @@ public: void writePowerDeriv(ostream &output, bool use_dll) const; //! reindex external functions void reindexExternalFunctions(SymbolTable &orig_symbol_table); + void reindex(SymbolTable &orig_symbol_table); + void reindexLocalVars(SymbolTable &orig_symbol_table); //! Thrown when trying to access an unknown variable by deriv_id class UnknownDerivIDException { diff --git a/ModFile.cc b/ModFile.cc index b4767def..8824d84b 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -315,6 +315,13 @@ ModFile::transformPass(bool nostrict) symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); + + SymbolTable *exp_tree_symbol_table = expressions_tree.getSymbolTable(); + exp_tree_symbol_table->rmExo(unusedExo, orig_symbol_table); + + SymbolTable *ssm_tree_symbol_table = steady_state_model.getSymbolTable(); + ssm_tree_symbol_table->rmExo(unusedExo, orig_symbol_table); + vector orig_statements = statements; statements.clear(); for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) diff --git a/ModelTree.cc b/ModelTree.cc index 6f3a10e5..9d187b05 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1416,30 +1416,15 @@ ModelTree::addAuxEquation(expr_t eq) void ModelTree::reindex(SymbolTable &orig_symbol_table) { - variable_node_map.clear(); - unary_op_node_map.clear(); - binary_op_node_map.clear(); - trinary_op_node_map.clear(); - external_function_node_map.clear(); - first_deriv_external_function_node_map.clear(); - second_deriv_external_function_node_map.clear(); - + DataTree::reindex(orig_symbol_table); reindexEquations(orig_symbol_table); reindexTrendSymbolsMap(orig_symbol_table); reindexNonstationarySymbolsMap(orig_symbol_table); - reindexExternalFunctions(orig_symbol_table); } void ModelTree::reindexEquations(SymbolTable &orig_symbol_table) { - map orig_local_variables_table = local_variables_table; - local_variables_table.clear(); - for (map::const_iterator it = orig_local_variables_table.begin(); - it != orig_local_variables_table.end(); it++) - AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(*this, orig_symbol_table)); - vectoreqbak = equations; equations.clear(); for (size_t i = 0; i < eqbak.size(); i++) diff --git a/SymbolTable.cc b/SymbolTable.cc index ffaa7bb8..223f4a91 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -503,6 +503,25 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) assert(size == symbol_table.size()); } +void +SymbolTable::rmExo(set &unused, SymbolTable &orig_symbol_table) throw (FrozenException) +{ + if (frozen) + throw FrozenException(); + + for (set::const_iterator it = unused.begin(); it != unused.end(); it++) + try + { + string name = orig_symbol_table.getName(*it); + int symbid = getID(name); + cerr << "ERROR: " << name << "used in expression but not found in model block" << endl; + exit(EXIT_FAILURE); + } + catch (...) + { + } +} + int SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException) { diff --git a/SymbolTable.hh b/SymbolTable.hh index 85267fe6..98f88ee1 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -305,6 +305,8 @@ public: set getOrigEndogenous() const; //! Remove exogenous variables contained in the set void rmExo(set &unused) throw (FrozenException); + //! Remove exogenous variables contained in the set from the orig_symbol_table. If found, quit + void rmExo(set &unused, SymbolTable &orig_symbol_table) throw (FrozenException); }; inline bool From 217123bb191b8a2a6e0d83c03f671f7bfe0afd4d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:31:08 +0200 Subject: [PATCH 48/74] preprocessor: reindex predetermined variables --- SymbolTable.cc | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index 223f4a91..a9e6d1f5 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -486,6 +486,7 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) idxs.sort(); idxs.reverse(); + vector orig_name_table = name_table; for (list::const_iterator it = idxs.begin(); it != idxs.end(); it++) { type_table.erase(type_table.begin() + *it); @@ -499,8 +500,16 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) for (vector::const_iterator it=name_table.begin(); it != name_table.end(); it++) symbol_table[*it] = size++; - assert(size == symbol_table.size()); + + set orig_predetermined_variables = predetermined_variables; + predetermined_variables.clear(); + for (set::const_iterator it=orig_predetermined_variables.begin(); + it != orig_predetermined_variables.end(); it++) + if (orig_name_table[*it] != getName(*it)) + markPredetermined(getID(orig_name_table[*it])); + else + markPredetermined(*it); } void From 1817992f452a9e41eb031be98880111ec7f91d05 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:31:50 +0200 Subject: [PATCH 49/74] preprocessor: remove unnecessary reindexing --- ModFile.cc | 5 ----- 1 file changed, 5 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 0592c620..a206a930 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -316,11 +316,6 @@ ModFile::transformPass(bool nostrict) dynamic_model.reindex(orig_symbol_table); dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); - SymbolTable *exp_tree_symbol_table = expressions_tree.getSymbolTable(); - exp_tree_symbol_table->rmExo(unusedExo, orig_symbol_table); - - SymbolTable *ssm_tree_symbol_table = steady_state_model.getSymbolTable(); - ssm_tree_symbol_table->rmExo(unusedExo, orig_symbol_table); vector orig_statements = statements; statements.clear(); From 549c6637cbb893ec5425afb773a3a30a4ea7b56e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:32:26 +0200 Subject: [PATCH 50/74] preprocessor: move external_functions_table reindexing to modfile::transformpass --- DataTree.cc | 7 ------- DataTree.hh | 2 -- ModFile.cc | 1 + 3 files changed, 1 insertion(+), 9 deletions(-) diff --git a/DataTree.cc b/DataTree.cc index b45d4479..acbae348 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -61,7 +61,6 @@ DataTree::reindex(SymbolTable &orig_symbol_table) first_deriv_external_function_node_map.clear(); second_deriv_external_function_node_map.clear(); - reindexExternalFunctions(orig_symbol_table); reindexLocalVars(orig_symbol_table); } @@ -76,12 +75,6 @@ DataTree::reindexLocalVars(SymbolTable &orig_symbol_table) it->second->cloneDynamicReindex(*this, orig_symbol_table)); } -void -DataTree::reindexExternalFunctions(SymbolTable &orig_symbol_table) -{ - external_functions_table.reindex(symbol_table, orig_symbol_table); -} - expr_t DataTree::AddNonNegativeConstant(const string &value) { diff --git a/DataTree.hh b/DataTree.hh index 9d0f746c..b7cd2565 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -238,8 +238,6 @@ public: void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv void writePowerDeriv(ostream &output, bool use_dll) const; - //! reindex external functions - void reindexExternalFunctions(SymbolTable &orig_symbol_table); void reindex(SymbolTable &orig_symbol_table); void reindexLocalVars(SymbolTable &orig_symbol_table); //! Thrown when trying to access an unknown variable by deriv_id diff --git a/ModFile.cc b/ModFile.cc index a206a930..bc9cea5f 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -316,6 +316,7 @@ ModFile::transformPass(bool nostrict) dynamic_model.reindex(orig_symbol_table); dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); + external_functions_table.reindex(symbol_table, orig_symbol_table); vector orig_statements = statements; statements.clear(); From 5d9aaeef75d80abdeb1a7e5445934e48f94259e7 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:44:46 +0200 Subject: [PATCH 51/74] preprocessor: reindex varobs in symboltable --- SymbolTable.cc | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/SymbolTable.cc b/SymbolTable.cc index a9e6d1f5..edce61db 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -510,6 +510,14 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) markPredetermined(getID(orig_name_table[*it])); else markPredetermined(*it); + + vector orig_varobs = varobs; + varobs.clear(); + for (vector::const_iterator it=orig_varobs.begin(); it != orig_varobs.end(); it++) + if (orig_name_table[*it] != getName(*it)) + addObservedVariable(getID(orig_name_table[*it])); + else + addObservedVariable(*it); } void From 3c7f96e29d1ea0c52f3a884dad024837d31e2417 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 19 May 2015 16:47:44 +0200 Subject: [PATCH 52/74] preprocessor: remove unused, overload of rmExo --- SymbolTable.cc | 19 ------------------- SymbolTable.hh | 2 -- 2 files changed, 21 deletions(-) diff --git a/SymbolTable.cc b/SymbolTable.cc index edce61db..177ac94e 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -520,25 +520,6 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) addObservedVariable(*it); } -void -SymbolTable::rmExo(set &unused, SymbolTable &orig_symbol_table) throw (FrozenException) -{ - if (frozen) - throw FrozenException(); - - for (set::const_iterator it = unused.begin(); it != unused.end(); it++) - try - { - string name = orig_symbol_table.getName(*it); - int symbid = getID(name); - cerr << "ERROR: " << name << "used in expression but not found in model block" << endl; - exit(EXIT_FAILURE); - } - catch (...) - { - } -} - int SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException) { diff --git a/SymbolTable.hh b/SymbolTable.hh index 98f88ee1..85267fe6 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -305,8 +305,6 @@ public: set getOrigEndogenous() const; //! Remove exogenous variables contained in the set void rmExo(set &unused) throw (FrozenException); - //! Remove exogenous variables contained in the set from the orig_symbol_table. If found, quit - void rmExo(set &unused, SymbolTable &orig_symbol_table) throw (FrozenException); }; inline bool From a3619804370cfc7f1c6fa2ccd0f88314c844b08e Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 20 May 2015 12:24:55 +0200 Subject: [PATCH 53/74] preprocessor: move all dynamic model reindexing to DynamicModel --- DynamicModel.cc | 7 +++++++ DynamicModel.hh | 3 +++ ModFile.cc | 2 -- 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 9e767fad..c5480aaa 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4202,6 +4202,13 @@ DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) static_only_equations_lineno.push_back(lineno); } +void +DynamicModel::reindex(SymbolTable &orig_symbol_table) +{ + ModelTree::reindex(orig_symbol_table); + reindexStaticOnlyEquations(orig_symbol_table); +} + void DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) { diff --git a/DynamicModel.hh b/DynamicModel.hh index 835f09b7..7adda7fd 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -244,6 +244,9 @@ public: //! Adds an equation marked as [static] void addStaticOnlyEquation(expr_t eq, int lineno); + //! reindex Dynamic Model after removal of extra exogenous + void reindex(SymbolTable &orig_symbol_table); + //! reindex equations marked as [static] void reindexStaticOnlyEquations(SymbolTable &orig_symbol_table); diff --git a/ModFile.cc b/ModFile.cc index bc9cea5f..ceb68724 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -314,8 +314,6 @@ ModFile::transformPass(bool nostrict) SymbolTable orig_symbol_table = symbol_table; symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); - dynamic_model.reindexStaticOnlyEquations(orig_symbol_table); - external_functions_table.reindex(symbol_table, orig_symbol_table); vector orig_statements = statements; From f6fb8bbf47162547dcd844472aa607395dfb38f8 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 20 May 2015 12:28:42 +0200 Subject: [PATCH 54/74] preprocessor: fix function call in reindexStaticOnlyEquations --- DynamicModel.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index c5480aaa..a43a599b 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4215,7 +4215,8 @@ DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) vectoreqbak = static_only_equations; static_only_equations.clear(); for (size_t i = 0; i < eqbak.size(); i++) - addStaticOnlyEquation(eqbak[i]->cloneDynamic(*this), static_only_equations_lineno[i]); + addStaticOnlyEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), + static_only_equations_lineno[i]); } size_t From 0a2f09566fc5dc337eaf1adc4903c4c3fcd5d9d5 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 26 May 2015 15:47:56 +0200 Subject: [PATCH 55/74] preprocessor: add new field orig_expr for expectation aux vars, closes #773 --- ExprNode.cc | 2 +- SymbolTable.cc | 29 +++++++++++++++++++---------- SymbolTable.hh | 13 ++++++++++--- 3 files changed, 30 insertions(+), 14 deletions(-) diff --git a/ExprNode.cc b/ExprNode.cc index 8798d796..b9c44055 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -2356,7 +2356,7 @@ UnaryOpNode::substituteExpectation(subst_table_t &subst_table, vectoridx); + int symb_id = datatree.symbol_table.addExpectationAuxiliaryVar(expectation_information_set, arg->idx, arg); expr_t newAuxE = datatree.AddVariable(symb_id, 0); if (partial_information_model && expectation_information_set == 0) diff --git a/SymbolTable.cc b/SymbolTable.cc index 9d43b791..2c1a699c 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -25,12 +25,15 @@ #include "SymbolTable.hh" AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg, - int equation_number_for_multiplier_arg) : + int equation_number_for_multiplier_arg, int information_set_arg, + expr_t expectation_expr_node_arg) : symb_id(symb_id_arg), type(type_arg), orig_symb_id(orig_symb_id_arg), orig_lead_lag(orig_lead_lag_arg), - equation_number_for_multiplier(equation_number_for_multiplier_arg) + equation_number_for_multiplier(equation_number_for_multiplier_arg), + information_set(information_set_arg), + expectation_expr_node(expectation_expr_node_arg) { } @@ -243,7 +246,6 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) { case avEndoLead: case avExoLead: - case avExpectation: break; case avEndoLag: case avExoLag: @@ -256,6 +258,13 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException) case avDiffForward: output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl; break; + case avExpectation: + output << "M_.aux_vars(" << i+1 << ").orig_expr = '\\mathbb{E}_{t" + << (aux_vars[i].get_information_set() < 0 ? "" : "+") + << aux_vars[i].get_information_set() << "}("; + aux_vars[i].get_expectation_expr_node()->writeOutput(output, oLatexDynamicModel); + output << ")';" << endl; + break; } } @@ -468,7 +477,7 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenExce exit(EXIT_FAILURE); } - aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLead : avExoLead), 0, 0, 0)); + aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLead : avExoLead), 0, 0, 0, 0, NULL)); return symb_id; } @@ -494,7 +503,7 @@ SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_le exit(EXIT_FAILURE); } - aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLag : avExoLag), orig_symb_id, orig_lead_lag, 0)); + aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLag : avExoLag), orig_symb_id, orig_lead_lag, 0, 0, NULL)); return symb_id; } @@ -524,7 +533,7 @@ SymbolTable::addExoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag) throw (F } int -SymbolTable::addExpectationAuxiliaryVar(int information_set, int index) throw (FrozenException) +SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, expr_t exp_arg) throw (FrozenException) { ostringstream varname; int symb_id; @@ -542,7 +551,7 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index) throw (F exit(EXIT_FAILURE); } - aux_vars.push_back(AuxVarInfo(symb_id, avExpectation, 0, 0, 0)); + aux_vars.push_back(AuxVarInfo(symb_id, avExpectation, 0, 0, 0, information_set, exp_arg)); return symb_id; } @@ -564,7 +573,7 @@ SymbolTable::addMultiplierAuxiliaryVar(int index) throw (FrozenException) exit(EXIT_FAILURE); } - aux_vars.push_back(AuxVarInfo(symb_id, avMultiplier, 0, 0, index)); + aux_vars.push_back(AuxVarInfo(symb_id, avMultiplier, 0, 0, index, 0, NULL)); return symb_id; } @@ -585,7 +594,7 @@ SymbolTable::addDiffForwardAuxiliaryVar(int orig_symb_id) throw (FrozenException exit(EXIT_FAILURE); } - aux_vars.push_back(AuxVarInfo(symb_id, avDiffForward, orig_symb_id, 0, 0)); + aux_vars.push_back(AuxVarInfo(symb_id, avDiffForward, orig_symb_id, 0, 0, 0, NULL)); return symb_id; } diff --git a/SymbolTable.hh b/SymbolTable.hh index 3e4c47e1..4be960a1 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -29,6 +29,9 @@ using namespace std; #include #include "CodeInterpreter.hh" +#include "ExprNode.hh" + +typedef class ExprNode *expr_t; //! Types of auxiliary variables enum aux_var_t @@ -51,13 +54,17 @@ private: int orig_symb_id; //!< Symbol ID of the endo of the original model represented by this aux var. Only used for avEndoLag and avExoLag. int orig_lead_lag; //!< Lead/lag of the endo of the original model represented by this aux var. Only used for avEndoLag and avExoLag. int equation_number_for_multiplier; //!< Stores the original constraint equation number associated with this aux var. Only used for avMultiplier. + int information_set; //! Argument of expectation operator. Only used for avExpectation. + expr_t expectation_expr_node; //! Argument of expectation operator. Only used for avExpectation. public: - AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg); + AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expectation_expr_node_arg); int get_symb_id() const { return symb_id; }; aux_var_t get_type() const { return type; }; int get_orig_symb_id() const { return orig_symb_id; }; int get_orig_lead_lag() const { return orig_lead_lag; }; int get_equation_number_for_multiplier() const { return equation_number_for_multiplier; }; + int get_information_set() const { return information_set; }; + expr_t get_expectation_expr_node() const { return expectation_expr_node; } ; }; //! Stores the symbol table @@ -216,7 +223,7 @@ public: \param[in] index Used to construct the variable name \return the symbol ID of the new symbol */ - int addExpectationAuxiliaryVar(int information_set, int index) throw (FrozenException); + int addExpectationAuxiliaryVar(int information_set, int index, expr_t arg) throw (FrozenException); //! Adds an auxiliary variable for the multiplier for the FOCs of the Ramsey Problem /*! \param[in] index Used to construct the variable name From 35cd407f5fcfe47b83fcc64c8bf050007cc73750 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 28 May 2015 11:42:12 +0200 Subject: [PATCH 56/74] preprocessor: add minimal_workspace option to dynare statement, #946 --- ComputingTasks.cc | 130 ++++++++++++++++++------------------- ComputingTasks.hh | 130 ++++++++++++++++++------------------- DynareMain.cc | 14 ++-- DynareMain2.cc | 6 +- ModFile.cc | 10 ++- ModFile.hh | 3 +- NumericalInitialization.cc | 23 +++---- NumericalInitialization.hh | 20 +++--- Shocks.cc | 12 ++-- Shocks.hh | 12 ++-- SigmaeInitialization.cc | 4 +- SigmaeInitialization.hh | 4 +- Statement.cc | 4 +- Statement.hh | 6 +- 14 files changed, 194 insertions(+), 184 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 76ed6faa..35bda998 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -44,7 +44,7 @@ SteadyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati } void -SteadyStatement::writeOutput(ostream &output, const string &basename) const +SteadyStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "steady;" << endl; @@ -56,7 +56,7 @@ CheckStatement::CheckStatement(const OptionsList &options_list_arg) : } void -CheckStatement::writeOutput(ostream &output, const string &basename) const +CheckStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "oo_.dr.eigval = check(M_,options_,oo_);" << endl; @@ -80,7 +80,7 @@ ModelInfoStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } void -ModelInfoStatement::writeOutput(ostream &output, const string &basename) const +ModelInfoStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "model_info();" << endl; @@ -98,7 +98,7 @@ SimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidatio } void -SimulStatement::writeOutput(ostream &output, const string &basename) const +SimulStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "perfect_foresight_setup;" << endl @@ -111,7 +111,7 @@ PerfectForesightSetupStatement::PerfectForesightSetupStatement(const OptionsList } void -PerfectForesightSetupStatement::writeOutput(ostream &output, const string &basename) const +PerfectForesightSetupStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "perfect_foresight_setup;" << endl; @@ -129,7 +129,7 @@ PerfectForesightSolverStatement::checkPass(ModFileStructure &mod_file_struct, Wa } void -PerfectForesightSolverStatement::writeOutput(ostream &output, const string &basename) const +PerfectForesightSolverStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "perfect_foresight_solver;" << endl; @@ -166,7 +166,7 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } void -StochSimulStatement::writeOutput(ostream &output, const string &basename) const +StochSimulStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { // Ensure that order 3 implies k_order (#844) OptionsList::num_options_t::const_iterator it = options_list.num_options.find("order"); @@ -188,7 +188,7 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, } void -ForecastStatement::writeOutput(ostream &output, const string &basename) const +ForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); @@ -235,7 +235,7 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } void -RamseyModelStatement::writeOutput(ostream &output, const string &basename) const +RamseyModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { // options_.ramsey_policy indicates that a Ramsey model is present in the *.mod file // this affects the computation of the steady state that uses a special algorithm @@ -296,7 +296,7 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } void -RamseyPolicyStatement::writeOutput(ostream &output, const string &basename) const +RamseyPolicyStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { // Ensure that order 3 implies k_order (#844) OptionsList::num_options_t::const_iterator it = options_list.num_options.find("order"); @@ -356,7 +356,7 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni } void -DiscretionaryPolicyStatement::writeOutput(ostream &output, const string &basename) const +DiscretionaryPolicyStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { // Ensure that order 3 implies k_order (#844) OptionsList::num_options_t::const_iterator it = options_list.num_options.find("order"); @@ -462,7 +462,7 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } void -EstimationStatement::writeOutput(ostream &output, const string &basename) const +EstimationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); @@ -497,7 +497,7 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct, Warning } void -DynareSensitivityStatement::writeOutput(ostream &output, const string &basename) const +DynareSensitivityStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output, "options_gsa"); @@ -524,7 +524,7 @@ RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : } void -RplotStatement::writeOutput(ostream &output, const string &basename) const +RplotStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { symbol_list.writeOutput("var_list_", output); output << "rplot(var_list_);" << endl; @@ -535,7 +535,7 @@ UnitRootVarsStatement::UnitRootVarsStatement(void) } void -UnitRootVarsStatement::writeOutput(ostream &output, const string &basename) const +UnitRootVarsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_.diffuse_filter = 1;" << endl << "options_.steadystate.nocheck = 1;" << endl; @@ -546,7 +546,7 @@ PeriodsStatement::PeriodsStatement(int periods_arg) : periods(periods_arg) } void -PeriodsStatement::writeOutput(ostream &output, const string &basename) const +PeriodsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_.periods = " << periods << ";" << endl; } @@ -560,7 +560,7 @@ DsampleStatement::DsampleStatement(int val1_arg, int val2_arg) : val1(val1_arg), } void -DsampleStatement::writeOutput(ostream &output, const string &basename) const +DsampleStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { if (val2 < 0) output << "dsample(" << val1 << ");" << endl; @@ -640,7 +640,7 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo } void -EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) const +EstimatedParamsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "global estim_params_" << endl << "estim_params_.var_exo = [];" << endl @@ -715,7 +715,7 @@ EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, Warni } void -EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename) const +EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { if (use_calibration) output << "options_.use_calibration_initialization = 1;" << endl; @@ -781,7 +781,7 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector::const_iterator it; @@ -869,7 +869,7 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t } void -ObservationTrendsStatement::writeOutput(ostream &output, const string &basename) const +ObservationTrendsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_.trend_coeff_ = {};" << endl; @@ -902,7 +902,7 @@ OsrParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } void -OsrParamsStatement::writeOutput(ostream &output, const string &basename) const +OsrParamsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { symbol_list.writeOutput("osr_params_", output); } @@ -937,7 +937,7 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation } void -OsrStatement::writeOutput(ostream &output, const string &basename) const +OsrStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { // Ensure that order 3 implies k_order (#844) OptionsList::num_options_t::const_iterator it = options_list.num_options.find("order"); @@ -967,7 +967,7 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } void -OptimWeightsStatement::writeOutput(ostream &output, const string &basename) const +OptimWeightsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% OPTIM_WEIGHTS" << endl @@ -1010,7 +1010,7 @@ DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg, } void -DynaSaveStatement::writeOutput(ostream &output, const string &basename) const +DynaSaveStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { symbol_list.writeOutput("var_list_", output); output << "dynasave('" << filename @@ -1025,7 +1025,7 @@ DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg, } void -DynaTypeStatement::writeOutput(ostream &output, const string &basename) const +DynaTypeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { symbol_list.writeOutput("var_list_", output); output << "dynatype('" << filename @@ -1040,7 +1040,7 @@ ModelComparisonStatement::ModelComparisonStatement(const filename_list_t &filena } void -ModelComparisonStatement::writeOutput(ostream &output, const string &basename) const +ModelComparisonStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); @@ -1086,7 +1086,7 @@ PlannerObjectiveStatement::computingPass() } void -PlannerObjectiveStatement::writeOutput(ostream &output, const string &basename) const +PlannerObjectiveStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { model_tree->writeStaticFile(basename + "_objective", false, false, false); } @@ -1104,7 +1104,7 @@ BVARDensityStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } void -BVARDensityStatement::writeOutput(ostream &output, const string &basename) const +BVARDensityStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "bvar_density(" << maxnlags << ");" << endl; @@ -1123,7 +1123,7 @@ BVARForecastStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } void -BVARForecastStatement::writeOutput(ostream &output, const string &basename) const +BVARForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "bvar_forecast(" << nlags << ");" << endl; @@ -1141,7 +1141,7 @@ SBVARStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidatio } void -SBVARStatement::writeOutput(ostream &output, const string &basename) const +SBVARStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); output << "sbvar(M_,options_);" << endl; @@ -1168,7 +1168,7 @@ MSSBVAREstimationStatement::checkPass(ModFileStructure &mod_file_struct, Warning } void -MSSBVAREstimationStatement::writeOutput(ostream &output, const string &basename) const +MSSBVAREstimationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl << "options_.datafile = '';" << endl; @@ -1188,7 +1188,7 @@ MSSBVARSimulationStatement::checkPass(ModFileStructure &mod_file_struct, Warning } void -MSSBVARSimulationStatement::writeOutput(ostream &output, const string &basename) const +MSSBVARSimulationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl; options_list.writeOutput(output); @@ -1216,7 +1216,7 @@ MSSBVARComputeMDDStatement::checkPass(ModFileStructure &mod_file_struct, Warning } void -MSSBVARComputeMDDStatement::writeOutput(ostream &output, const string &basename) const +MSSBVARComputeMDDStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl; options_list.writeOutput(output); @@ -1243,7 +1243,7 @@ MSSBVARComputeProbabilitiesStatement::checkPass(ModFileStructure &mod_file_struc } void -MSSBVARComputeProbabilitiesStatement::writeOutput(ostream &output, const string &basename) const +MSSBVARComputeProbabilitiesStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl; options_list.writeOutput(output); @@ -1289,7 +1289,7 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } void -MSSBVARIrfStatement::writeOutput(ostream &output, const string &basename) const +MSSBVARIrfStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl; symbol_list.writeOutput("var_list_", output); @@ -1316,7 +1316,7 @@ MSSBVARForecastStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo } void -MSSBVARForecastStatement::writeOutput(ostream &output, const string &basename) const +MSSBVARForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl; options_list.writeOutput(output); @@ -1360,7 +1360,7 @@ MSSBVARVarianceDecompositionStatement::checkPass(ModFileStructure &mod_file_stru } void -MSSBVARVarianceDecompositionStatement::writeOutput(ostream &output, const string &basename) const +MSSBVARVarianceDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_ = initialize_ms_sbvar_options(M_, options_);" << endl; options_list.writeOutput(output); @@ -1385,7 +1385,7 @@ IdentificationStatement::checkPass(ModFileStructure &mod_file_struct, WarningCon } void -IdentificationStatement::writeOutput(ostream &output, const string &basename) const +IdentificationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output, "options_ident"); @@ -1412,7 +1412,7 @@ WriteLatexDynamicModelStatement::WriteLatexDynamicModelStatement(const DynamicMo } void -WriteLatexDynamicModelStatement::writeOutput(ostream &output, const string &basename) const +WriteLatexDynamicModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { dynamic_model.writeLatexFile(basename); } @@ -1423,7 +1423,7 @@ WriteLatexStaticModelStatement::WriteLatexStaticModelStatement(const StaticModel } void -WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basename) const +WriteLatexStaticModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { static_model.writeLatexFile(basename); } @@ -1434,7 +1434,7 @@ WriteLatexOriginalModelStatement::WriteLatexOriginalModelStatement(const Dynamic } void -WriteLatexOriginalModelStatement::writeOutput(ostream &output, const string &basename) const +WriteLatexOriginalModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { original_model.writeLatexOriginalFile(basename); } @@ -1447,7 +1447,7 @@ ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbo } void -ShockDecompositionStatement::writeOutput(ostream &output, const string &basename) const +ShockDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); @@ -1460,7 +1460,7 @@ ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &op } void -ConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const +ConditionalForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output, "options_cond_fcst_"); output << "imcforecast(constrained_paths_, constrained_vars_, options_cond_fcst_);" << endl; @@ -1473,7 +1473,7 @@ PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_a } void -PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename) const +PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { symbol_list.writeOutput("var_list_", output); if (periods == -1) @@ -1526,7 +1526,7 @@ SvarIdentificationStatement::checkPass(ModFileStructure &mod_file_struct, Warnin } void -SvarIdentificationStatement::writeOutput(ostream &output, const string &basename) const +SvarIdentificationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { assert(!(upper_cholesky_present && lower_cholesky_present)); output << "%" << endl @@ -1743,7 +1743,7 @@ MarkovSwitchingStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo } void -MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename) const +MarkovSwitchingStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { bool isDurationAVec = true; string infStr("Inf"); @@ -1852,7 +1852,7 @@ SvarStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation } void -SvarStatement::writeOutput(ostream &output, const string &basename) const +SvarStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { OptionsList::num_options_t::const_iterator it0, it1, it2; OptionsList::vec_int_options_t::const_iterator itv; @@ -1898,7 +1898,7 @@ SetTimeStatement::SetTimeStatement(const OptionsList &options_list_arg) : } void -SetTimeStatement::writeOutput(ostream &output, const string &basename) const +SetTimeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); } @@ -1937,7 +1937,7 @@ EstimationDataStatement::checkPass(ModFileStructure &mod_file_struct, WarningCon } void -EstimationDataStatement::writeOutput(ostream &output, const string &basename) const +EstimationDataStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output, "options_.dataset"); } @@ -1959,7 +1959,7 @@ SubsamplesStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } void -SubsamplesStatement::writeOutput(ostream &output, const string &basename) const +SubsamplesStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "subsamples_indx = get_new_or_existing_ei_index('subsamples_index', '" << name1 << "','" << name2 << "');" << endl @@ -2029,7 +2029,7 @@ SubsamplesEqualStatement::SubsamplesEqualStatement(const string &to_name1_arg, } void -SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename) const +SubsamplesEqualStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "subsamples_to_indx = get_new_or_existing_ei_index('subsamples_index', '" << to_name1 << "','" << to_name2 << "');" << endl @@ -2123,7 +2123,7 @@ JointPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } void -JointPriorStatement::writeOutput(ostream &output, const string &basename) const +JointPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { for (vector::const_iterator it = joint_parameters.begin() ; it != joint_parameters.end(); it++) output << "eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', '" @@ -2387,7 +2387,7 @@ PriorStatement::PriorStatement(const string &name_arg, } void -PriorStatement::writeOutput(ostream &output, const string &basename) const +PriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field = "estimation_info.parameter(eifind)"; output << "eifind = get_new_or_existing_ei_index('parameter_prior_index', '" @@ -2424,7 +2424,7 @@ StdPriorStatement::StdPriorStatement(const string &name_arg, } void -StdPriorStatement::writeOutput(ostream &output, const string &basename) const +StdPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field; get_base_name(symbol_table.getType(name), lhs_field); @@ -2487,7 +2487,7 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } void -CorrPriorStatement::writeOutput(ostream &output, const string &basename) const +CorrPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field; get_base_name(symbol_table.getType(name), lhs_field); @@ -2575,7 +2575,7 @@ PriorEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field } void -PriorEqualStatement::writeOutput(ostream &output, const string &basename) const +PriorEqualStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field, rhs_field; @@ -2721,7 +2721,7 @@ OptionsStatement::OptionsStatement(const string &name_arg, } void -OptionsStatement::writeOutput(ostream &output, const string &basename) const +OptionsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field = "estimation_info.parameter(eifind)"; output << "eifind = get_new_or_existing_ei_index('parameter_options_index', '" @@ -2749,7 +2749,7 @@ StdOptionsStatement::StdOptionsStatement(const string &name_arg, } void -StdOptionsStatement::writeOutput(ostream &output, const string &basename) const +StdOptionsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field; get_base_name(symbol_table.getType(name), lhs_field); @@ -2804,7 +2804,7 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } void -CorrOptionsStatement::writeOutput(ostream &output, const string &basename) const +CorrOptionsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field; get_base_name(symbol_table.getType(name), lhs_field); @@ -2887,7 +2887,7 @@ OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_fie } void -OptionsEqualStatement::writeOutput(ostream &output, const string &basename) const +OptionsEqualStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { string lhs_field, rhs_field; @@ -2961,7 +2961,7 @@ CalibSmootherStatement::checkPass(ModFileStructure &mod_file_struct, WarningCons } void -CalibSmootherStatement::writeOutput(ostream &output, const string &basename) const +CalibSmootherStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output); symbol_list.writeOutput("var_list_", output); @@ -2988,7 +2988,7 @@ ExtendedPathStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } void -ExtendedPathStatement::writeOutput(ostream &output, const string &basename) const +ExtendedPathStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { // Beware: options do not have the same name in the interface and in the M code... @@ -3007,7 +3007,7 @@ ModelDiagnosticsStatement::ModelDiagnosticsStatement() } void -ModelDiagnosticsStatement::writeOutput(ostream &output, const string &basename) const +ModelDiagnosticsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "model_diagnostics(M_,options_,oo_);" << endl; } @@ -3018,7 +3018,7 @@ Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_ } void -Smoother2histvalStatement::writeOutput(ostream &output, const string &basename) const +Smoother2histvalStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { options_list.writeOutput(output, "options_smoother2histval"); output << "smoother2histval(options_smoother2histval);" << endl; diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 037ce9b6..51bc055e 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -35,7 +35,7 @@ private: public: SteadyStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class CheckStatement : public Statement @@ -45,7 +45,7 @@ private: public: CheckStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SimulStatement : public Statement @@ -55,7 +55,7 @@ private: public: SimulStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class PerfectForesightSetupStatement : public Statement @@ -64,7 +64,7 @@ private: const OptionsList options_list; public: PerfectForesightSetupStatement(const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class PerfectForesightSolverStatement : public Statement @@ -74,7 +74,7 @@ private: public: PerfectForesightSolverStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ModelInfoStatement : public Statement @@ -84,7 +84,7 @@ private: public: ModelInfoStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class StochSimulStatement : public Statement @@ -96,7 +96,7 @@ public: StochSimulStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ForecastStatement : public Statement @@ -107,7 +107,7 @@ private: public: ForecastStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class RamseyModelStatement : public Statement @@ -119,7 +119,7 @@ public: RamseyModelStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class RamseyPolicyStatement : public Statement @@ -131,7 +131,7 @@ public: RamseyPolicyStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class DiscretionaryPolicyStatement : public Statement @@ -143,7 +143,7 @@ public: DiscretionaryPolicyStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class RplotStatement : public Statement @@ -152,14 +152,14 @@ private: const SymbolList symbol_list; public: RplotStatement(const SymbolList &symbol_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class UnitRootVarsStatement : public Statement { public: UnitRootVarsStatement(void); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class PeriodsStatement : public Statement @@ -168,7 +168,7 @@ private: const int periods; public: PeriodsStatement(int periods_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class DsampleStatement : public Statement @@ -178,7 +178,7 @@ private: public: DsampleStatement(int val1_arg); DsampleStatement(int val1_arg, int val2_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class EstimationStatement : public Statement @@ -190,7 +190,7 @@ public: EstimationStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class DynareSensitivityStatement : public Statement @@ -200,7 +200,7 @@ private: public: DynareSensitivityStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ObservationTrendsStatement : public Statement @@ -213,7 +213,7 @@ private: public: ObservationTrendsStatement(const trend_elements_t &trend_elements_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class OsrParamsStatement : public Statement @@ -223,7 +223,7 @@ private: public: OsrParamsStatement(const SymbolList &symbol_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class OsrStatement : public Statement @@ -235,7 +235,7 @@ public: OsrStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class DynaTypeStatement : public Statement @@ -246,7 +246,7 @@ private: public: DynaTypeStatement(const SymbolList &symbol_list_arg, const string &filename_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class DynaSaveStatement : public Statement @@ -257,7 +257,7 @@ private: public: DynaSaveStatement(const SymbolList &symbol_list_arg, const string &filename_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ModelComparisonStatement : public Statement @@ -270,7 +270,7 @@ private: public: ModelComparisonStatement(const filename_list_t &filename_list_arg, const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; //! Temporary structure used when parsing estimation_params* statements @@ -309,7 +309,7 @@ public: EstimatedParamsStatement(const vector &estim_params_list_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class EstimatedParamsInitStatement : public Statement @@ -323,7 +323,7 @@ public: const SymbolTable &symbol_table_arg, const bool use_calibration_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class EstimatedParamsBoundsStatement : public Statement @@ -334,7 +334,7 @@ private: public: EstimatedParamsBoundsStatement(const vector &estim_params_list_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class OptimWeightsStatement : public Statement @@ -351,7 +351,7 @@ public: const covar_weights_t &covar_weights_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; /*! \todo Make model_tree a member instead of a pointer */ @@ -370,7 +370,7 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); /*! \todo allow for the possibility of disabling temporary terms */ virtual void computingPass(); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; //! Return the Planner Objective StaticModel *getPlannerObjective() const; }; @@ -383,7 +383,7 @@ private: public: BVARDensityStatement(int maxnlags_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class BVARForecastStatement : public Statement @@ -394,7 +394,7 @@ private: public: BVARForecastStatement(int nlags_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SBVARStatement : public Statement @@ -404,7 +404,7 @@ private: public: SBVARStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVAREstimationStatement : public Statement @@ -414,7 +414,7 @@ private: public: MSSBVAREstimationStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVARSimulationStatement : public Statement @@ -424,7 +424,7 @@ private: public: MSSBVARSimulationStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVARComputeMDDStatement : public Statement @@ -434,7 +434,7 @@ private: public: MSSBVARComputeMDDStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVARComputeProbabilitiesStatement : public Statement @@ -444,7 +444,7 @@ private: public: MSSBVARComputeProbabilitiesStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVARIrfStatement : public Statement @@ -456,7 +456,7 @@ public: MSSBVARIrfStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVARForecastStatement : public Statement @@ -466,7 +466,7 @@ private: public: MSSBVARForecastStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MSSBVARVarianceDecompositionStatement : public Statement @@ -476,7 +476,7 @@ private: public: MSSBVARVarianceDecompositionStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class IdentificationStatement : public Statement @@ -486,7 +486,7 @@ private: public: IdentificationStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class WriteLatexDynamicModelStatement : public Statement @@ -495,7 +495,7 @@ private: const DynamicModel &dynamic_model; public: WriteLatexDynamicModelStatement(const DynamicModel &dynamic_model_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class WriteLatexStaticModelStatement : public Statement @@ -504,7 +504,7 @@ private: const StaticModel &static_model; public: WriteLatexStaticModelStatement(const StaticModel &static_model_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class WriteLatexOriginalModelStatement : public Statement @@ -513,7 +513,7 @@ private: const DynamicModel &original_model; public: WriteLatexOriginalModelStatement(const DynamicModel &original_model_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ShockDecompositionStatement : public Statement @@ -524,7 +524,7 @@ private: public: ShockDecompositionStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ConditionalForecastStatement : public Statement @@ -533,7 +533,7 @@ private: const OptionsList options_list; public: ConditionalForecastStatement(const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class PlotConditionalForecastStatement : public Statement @@ -544,7 +544,7 @@ private: const SymbolList symbol_list; public: PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class CalibSmootherStatement : public Statement @@ -556,7 +556,7 @@ public: CalibSmootherStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ExtendedPathStatement : public Statement @@ -566,7 +566,7 @@ private: public: ExtendedPathStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SvarIdentificationStatement : public Statement @@ -597,7 +597,7 @@ public: const bool &constants_exclusion_present_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MarkovSwitchingStatement : public Statement @@ -608,7 +608,7 @@ private: public: MarkovSwitchingStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -619,7 +619,7 @@ private: public: SvarStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SetTimeStatement : public Statement @@ -628,7 +628,7 @@ private: const OptionsList options_list; public: SetTimeStatement(const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class EstimationDataStatement : public Statement @@ -638,7 +638,7 @@ private: public: EstimationDataStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SubsamplesStatement : public Statement @@ -657,7 +657,7 @@ public: const subsample_declaration_map_t subsample_declaration_map_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SubsamplesEqualStatement : public Statement @@ -674,7 +674,7 @@ public: const string &from_name1_arg, const string &from_name2_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class JointPriorStatement : public Statement @@ -688,7 +688,7 @@ public: const PriorDistributions &prior_shape_arg, const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; void writeOutputHelper(ostream &output, const string &field, const string &lhs_field) const; }; @@ -732,7 +732,7 @@ public: const PriorDistributions &prior_shape_arg, const expr_t &variance_arg, const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -747,7 +747,7 @@ public: const expr_t &variance_arg, const OptionsList &options_list_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -765,7 +765,7 @@ public: const OptionsList &options_list_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -793,7 +793,7 @@ public: const SymbolTable &symbol_table_arg); void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class BasicOptionsStatement : public Statement @@ -822,7 +822,7 @@ class OptionsStatement : public BasicOptionsStatement { public: OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -835,7 +835,7 @@ public: const string &subsample_name_arg, const OptionsList &options_list_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -850,7 +850,7 @@ public: const OptionsList &options_list_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -878,14 +878,14 @@ public: const SymbolTable &symbol_table_arg); void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ModelDiagnosticsStatement : public Statement { public: ModelDiagnosticsStatement(); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class Smoother2histvalStatement : public Statement @@ -894,7 +894,7 @@ private: const OptionsList options_list; public: Smoother2histvalStatement(const OptionsList &options_list_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; #endif diff --git a/DynareMain.cc b/DynareMain.cc index 9320a4af..0535663c 100644 --- a/DynareMain.cc +++ b/DynareMain.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -38,7 +38,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode, - bool parallel_test, bool nostrict, bool check_model_changes, FileOutputType output_mode, LanguageOutputType lang + bool parallel_test, bool nostrict, bool check_model_changes, bool minimal_workspace, FileOutputType output_mode, LanguageOutputType lang #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -48,8 +48,8 @@ void usage() { cerr << "Dynare usage: dynare mod_file [debug] [noclearall] [onlyclearglobals] [savemacro[=macro_file]] [onlymacro] [nolinemacro] [notmpterms] [nolog] [warn_uninit]" - << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test] " - << " [-D[=]] [nostrict] [fast] [output=dynamic|first|second|third] [language=C|C++]" + << " [console] [nograph] [nointeractive] [parallel[=cluster_name]] [conffile=parallel_config_path_and_filename] [parallel_slave_open_mode] [parallel_test]" + << " [-D[=]] [nostrict] [fast] [minimal_workspace] [output=dynamic|first|second|third] [language=C|C++]" #if defined(_WIN32) || defined(__CYGWIN32__) << " [cygwin] [msvc]" #endif @@ -98,6 +98,7 @@ main(int argc, char **argv) bool parallel_test = false; bool nostrict = false; bool check_model_changes = false; + bool minimal_workspace = false; map defines; FileOutputType output_mode = none; LanguageOutputType language = matlab; @@ -168,6 +169,8 @@ main(int argc, char **argv) nostrict = true; else if (!strcmp(argv[arg], "fast")) check_model_changes = true; + else if (!strcmp(argv[arg], "minimal_workspace")) + minimal_workspace = true; else if (strlen(argv[arg]) >= 8 && !strncmp(argv[arg], "parallel", 8)) { parallel = true; @@ -288,7 +291,8 @@ main(int argc, char **argv) // Do the rest main2(macro_output, basename, debug, clear_all, clear_global, no_tmp_terms, no_log, no_warn, warn_uninit, console, nograph, nointeractive, - parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, check_model_changes, output_mode, language + parallel, parallel_config_file, cluster_name, parallel_slave_open_mode, parallel_test, nostrict, check_model_changes, minimal_workspace, + output_mode, language #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc #endif diff --git a/DynareMain2.cc b/DynareMain2.cc index fe1c6942..33782aff 100644 --- a/DynareMain2.cc +++ b/DynareMain2.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2008-2014 Dynare Team + * Copyright (C) 2008-2015 Dynare Team * * This file is part of Dynare. * @@ -27,7 +27,7 @@ void main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear_global, bool no_tmp_terms, bool no_log, bool no_warn, bool warn_uninit, bool console, bool nograph, bool nointeractive, bool parallel, const string ¶llel_config_file, const string &cluster_name, bool parallel_slave_open_mode, - bool parallel_test, bool nostrict, bool check_model_changes, FileOutputType output_mode, LanguageOutputType language + bool parallel_test, bool nostrict, bool check_model_changes, bool minimal_workspace, FileOutputType output_mode, LanguageOutputType language #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -61,7 +61,7 @@ main2(stringstream &in, string &basename, bool debug, bool clear_all, bool clear mod_file->writeExternalFiles(basename, output_mode, language); else mod_file->writeOutputFiles(basename, clear_all, clear_global, no_log, no_warn, console, nograph, - nointeractive, config_file, check_model_changes + nointeractive, config_file, check_model_changes, minimal_workspace #if defined(_WIN32) || defined(__CYGWIN32__) , cygwin, msvc #endif diff --git a/ModFile.cc b/ModFile.cc index 0a7860c4..575d55fb 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -526,8 +526,9 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output) } void -ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, bool console, bool nograph, - bool nointeractive, const ConfigFile &config_file, bool check_model_changes +ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, + bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, + bool check_model_changes, bool minimal_workspace #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif @@ -587,6 +588,9 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo if (!no_log) mOutputFile << "diary('" << basename << ".log');" << endl; + if (minimal_workspace) + mOutputFile << "options_.minimal_workspace = 1;" << endl; + if (console) mOutputFile << "options_.console_mode = 1;" << endl << "options_.nodisplay = 1;" << endl; @@ -740,7 +744,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo for (vector::const_iterator it = statements.begin(); it != statements.end(); it++) { - (*it)->writeOutput(mOutputFile, basename); + (*it)->writeOutput(mOutputFile, basename, minimal_workspace); /* Special treatment for initval block: insert initial values for the auxiliary variables and initialize exo det */ diff --git a/ModFile.hh b/ModFile.hh index bf363668..34b3b30b 100644 --- a/ModFile.hh +++ b/ModFile.hh @@ -146,7 +146,8 @@ public: \param msvc Should the MEX command of use_dll be adapted for MSVC? */ void writeOutputFiles(const string &basename, bool clear_all, bool clear_global, bool no_log, bool no_warn, - bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, bool check_model_changes + bool console, bool nograph, bool nointeractive, const ConfigFile &config_file, + bool check_model_changes, bool minimal_workspace #if defined(_WIN32) || defined(__CYGWIN32__) , bool cygwin, bool msvc #endif diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 3df225fc..85055905 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -41,13 +41,14 @@ InitParamStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } void -InitParamStatement::writeOutput(ostream &output, const string &basename) const +InitParamStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { int id = symbol_table.getTypeSpecificID(symb_id) + 1; output << "M_.params( " << id << " ) = "; param_value->writeOutput(output); output << ";" << endl; - output << symbol_table.getName(symb_id) << " = M_.params( " << id << " );\n"; + if (!minimal_workspace) + output << symbol_table.getName(symb_id) << " = M_.params( " << id << " );" << endl; } void @@ -186,7 +187,7 @@ InitValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat } void -InitValStatement::writeOutput(ostream &output, const string &basename) const +InitValStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% INITVAL instructions" << endl @@ -242,7 +243,7 @@ EndValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati } void -EndValStatement::writeOutput(ostream &output, const string &basename) const +EndValStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% ENDVAL instructions" << endl @@ -268,7 +269,7 @@ HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat } void -HistValStatement::writeOutput(ostream &output, const string &basename) const +HistValStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% HISTVAL instructions" << endl @@ -326,7 +327,7 @@ InitvalFileStatement::InitvalFileStatement(const string &filename_arg) : } void -InitvalFileStatement::writeOutput(ostream &output, const string &basename) const +InitvalFileStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% INITVAL_FILE statement" << endl @@ -341,7 +342,7 @@ HistvalFileStatement::HistvalFileStatement(const string &filename_arg) : } void -HistvalFileStatement::writeOutput(ostream &output, const string &basename) const +HistvalFileStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "histvalf('" << filename << "');" << endl; } @@ -354,7 +355,7 @@ HomotopyStatement::HomotopyStatement(const homotopy_values_t &homotopy_values_ar } void -HomotopyStatement::writeOutput(ostream &output, const string &basename) const +HomotopyStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% HOMOTOPY_SETUP instructions" << endl @@ -388,7 +389,7 @@ SaveParamsAndSteadyStateStatement::SaveParamsAndSteadyStateStatement(const strin } void -SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const +SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "save_params_and_steady_state('" << filename << "');" << endl; } @@ -429,7 +430,7 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin } void -LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const +LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { for (map::const_iterator it = content.begin(); it != content.end(); it++) diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index c61d41e1..142838f7 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -40,7 +40,7 @@ public: InitParamStatement(int symb_id_arg, const expr_t param_value_arg, const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); //! Fill eval context with parameter value void fillEvalContext(eval_context_t &eval_context) const; @@ -77,7 +77,7 @@ public: const SymbolTable &symbol_table_arg, const bool &all_values_required_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; //! Writes initializations for oo_.exo_simul and oo_.exo_det_simul void writeOutputPostInit(ostream &output) const; }; @@ -90,7 +90,7 @@ public: const bool &all_values_required_arg); //! Workaround for trac ticket #35 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class HistValStatement : public Statement @@ -110,7 +110,7 @@ public: const SymbolTable &symbol_table_arg); //! Workaround for trac ticket #157 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class InitvalFileStatement : public Statement @@ -119,7 +119,7 @@ private: const string filename; public: InitvalFileStatement(const string &filename_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class HistvalFileStatement : public Statement @@ -128,7 +128,7 @@ private: const string filename; public: HistvalFileStatement(const string &filename_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class HomotopyStatement : public Statement @@ -143,7 +143,7 @@ private: public: HomotopyStatement(const homotopy_values_t &homotopy_values_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class SaveParamsAndSteadyStateStatement : public Statement @@ -152,7 +152,7 @@ private: const string filename; public: SaveParamsAndSteadyStateStatement(const string &filename_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class LoadParamsAndSteadyStateStatement : public Statement @@ -166,7 +166,7 @@ public: LoadParamsAndSteadyStateStatement(const string &filename, const SymbolTable &symbol_table_arg, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; //! Fill eval context with parameters/variables values void fillEvalContext(eval_context_t &eval_context) const; }; diff --git a/Shocks.cc b/Shocks.cc index d0aecd96..b2ebd79e 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -83,7 +83,7 @@ ShocksStatement::ShocksStatement(bool overwrite_arg, } void -ShocksStatement::writeOutput(ostream &output, const string &basename) const +ShocksStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% SHOCKS instructions" << endl @@ -340,7 +340,7 @@ MShocksStatement::MShocksStatement(bool overwrite_arg, } void -MShocksStatement::writeOutput(ostream &output, const string &basename) const +MShocksStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "%" << endl << "% MSHOCKS instructions" << endl @@ -380,7 +380,7 @@ ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct, } void -ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &basename) const +ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { assert(path_length > 0); output << "constrained_vars_ = [];" << endl @@ -420,7 +420,7 @@ MomentCalibration::MomentCalibration(const constraints_t &constraints_arg, } void -MomentCalibration::writeOutput(ostream &output, const string &basename) const +MomentCalibration::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_.endogenous_prior_restrictions.moment = {" << endl; for (size_t i = 0; i < constraints.size(); i++) @@ -442,7 +442,7 @@ IrfCalibration::IrfCalibration(const constraints_t &constraints_arg, } void -IrfCalibration::writeOutput(ostream &output, const string &basename) const +IrfCalibration::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { output << "options_.endogenous_prior_restrictions.irf = {" << endl; for (size_t i = 0; i < constraints.size(); i++) diff --git a/Shocks.hh b/Shocks.hh index 6ab43a64..155ef967 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -77,7 +77,7 @@ public: const covar_and_corr_shocks_t &covar_shocks_arg, const covar_and_corr_shocks_t &corr_shocks_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); }; @@ -87,7 +87,7 @@ public: MShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class ConditionalForecastPathsStatement : public Statement @@ -98,7 +98,7 @@ private: public: ConditionalForecastPathsStatement(const AbstractShocksStatement::det_shocks_t &paths_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class MomentCalibration : public Statement @@ -117,7 +117,7 @@ private: public: MomentCalibration(const constraints_t &constraints_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class IrfCalibration : public Statement @@ -136,7 +136,7 @@ private: public: IrfCalibration(const constraints_t &constraints_arg, const SymbolTable &symbol_table_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; #endif diff --git a/SigmaeInitialization.cc b/SigmaeInitialization.cc index acc0a0a3..63d6a0b5 100644 --- a/SigmaeInitialization.cc +++ b/SigmaeInitialization.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -59,7 +59,7 @@ SigmaeStatement::determineMatrixForm(const matrix_t &matrix) throw (MatrixFormEx } void -SigmaeStatement::writeOutput(ostream &output, const string &basename) const +SigmaeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { size_t ic, ic1, ir, ir1; diff --git a/SigmaeInitialization.hh b/SigmaeInitialization.hh index ddfcc7f1..41e24e32 100644 --- a/SigmaeInitialization.hh +++ b/SigmaeInitialization.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2010 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -57,7 +57,7 @@ private: public: SigmaeStatement(const matrix_t &matrix_arg) throw (MatrixFormException); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; #endif diff --git a/Statement.cc b/Statement.cc index d4d522e7..25cf2732 100644 --- a/Statement.cc +++ b/Statement.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Dynare Team + * Copyright (C) 2006-2015 Dynare Team * * This file is part of Dynare. * @@ -79,7 +79,7 @@ NativeStatement::NativeStatement(const string &native_statement_arg) : } void -NativeStatement::writeOutput(ostream &output, const string &basename) const +NativeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { using namespace boost::xpressive; string date_regex = "(-?\\d+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4]\\d|5[0-2])))"; diff --git a/Statement.hh b/Statement.hh index 5bdade39..eb36d8ba 100644 --- a/Statement.hh +++ b/Statement.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2006-2014 Dynare Team + * Copyright (C) 2006-2015 Dynare Team * * This file is part of Dynare. * @@ -134,7 +134,7 @@ public: \param output is the output stream of the main matlab file \param basename is the name of the modfile (without extension) which can be used to build auxiliary files */ - virtual void writeOutput(ostream &output, const string &basename) const = 0; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const = 0; virtual void writeCOutput(ostream &output, const string &basename); }; @@ -144,7 +144,7 @@ private: const string native_statement; public: NativeStatement(const string &native_statement_arg); - virtual void writeOutput(ostream &output, const string &basename) const; + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; class OptionsList From fca6e232c0854c4df03141a4c45c2b3d620ccd0d Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Thu, 28 May 2015 16:13:04 +0200 Subject: [PATCH 57/74] preprocessor: fix bug in merge of rmExtraExo branch --- ExprNode.hh | 1 + ExternalFunctionsTable.hh | 1 + 2 files changed, 2 insertions(+) diff --git a/ExprNode.hh b/ExprNode.hh index bef4a415..048196ca 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -34,6 +34,7 @@ using namespace std; class DataTree; class VariableNode; class BinaryOpNode; +class SymbolTable; typedef class ExprNode *expr_t; diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index b5218bea..0dfe698a 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -28,6 +28,7 @@ using namespace std; #include #include "SymbolTable.hh" +class SymbolTable; enum ExternalFunctionSetOrNot { From 60a33fb4a1b128261c94a33b16de33bbb2a25124 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Sun, 31 May 2015 12:18:06 +0200 Subject: [PATCH 58/74] Adding 'ramsey_constraints' block to declare contraints for Ramsey problems. Note that LMMCP (solve_algo=10) still doesn't work in all cases. --- ComputingTasks.cc | 103 ++++++++++++++++++++++++++++++++++++++++++++++ ComputingTasks.hh | 18 ++++++++ DynareBison.yy | 23 ++++++++++- DynareFlex.ll | 1 + ParsingDriver.cc | 51 +++++++++++++++++++++++ ParsingDriver.hh | 14 +++++++ 6 files changed, 208 insertions(+), 2 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 6057fad5..4e95890d 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -397,6 +397,109 @@ RamseyModelStatement::writeOutput(ostream &output, const string &basename, bool options_list.writeOutput(output); } +RamseyConstraintsStatement::RamseyConstraintsStatement(const constraints_t &constraints_arg) : + constraints(constraints_arg) +{ +} + +void +RamseyConstraintsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) +{ + if ((mod_file_struct.ramsey_model_present != true) || ( mod_file_struct.ramsey_policy_present != true)) + cerr << "ramsey_constraints: can only be used with ramsey_model or ramsey_policy" << endl; +} + +void +RamseyConstraintsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + output << "M_.ramsey_model_constraints = {" << endl; + for (RamseyConstraintsStatement::constraints_t::const_iterator it = constraints.begin(); it != constraints.end(); ++it) + { + if (it != constraints.begin()) + output << ", "; + output << "{" << it->endo + 1 << ", '"; + switch(it->code) + { + case oLess: + output << '<'; + break; + case oGreater: + output << '>'; + break; + case oLessEqual: + output << "<="; + break; + case oGreaterEqual: + output << ">="; + break; + default: + cerr << "Ramsey constraints: this shouldn't happen." << endl; + exit(1); + } + output << "', '"; + it->expression->writeOutput(output); + output << "'}" << endl; + } + output << "};" << endl; +} + +// Statement * +// RamseyConstraintsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) +// { +// vector errors; +// SymbolList new_symbol_list, new_options_symbol_list; +// OptionsList new_options_list = options_list; +// SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); +// vector symbols = symbol_list.get_symbols(); + +// for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) +// try +// { +// new_symbol_table->getID(*it); +// new_symbol_list.addSymbol(*it); +// } +// catch (SymbolTable::UnknownSymbolIDException &e) +// { +// errors.push_back(orig_symbol_table.getName(e.id)); +// } +// catch (SymbolTable::UnknownSymbolNameException &e) +// { +// errors.push_back(e.name); +// } + +// OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); +// if (it != options_list.symbol_list_options.end()) +// { +// symbols = it->second.get_symbols(); +// for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) +// try +// { +// new_symbol_table->getID(*it1); +// new_options_symbol_list.addSymbol(*it1); +// } +// catch (SymbolTable::UnknownSymbolIDException &e) +// { +// errors.push_back(orig_symbol_table.getName(e.id)); +// } +// catch (SymbolTable::UnknownSymbolNameException &e) +// { +// errors.push_back(e.name); +// } +// new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; +// } + +// if (!errors.empty()) +// { +// cerr << endl +// << "ERROR: The following vars were used in the ramsey_policy statement(s) but were not declared." << endl +// << " This likely means that you declared them as varexo and that they're not in the model" << endl; +// for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) +// cerr << *it << endl; +// exit(EXIT_FAILURE); +// } +// return new RamseyPolicyStatement(new_symbol_list, options_list); +// } + RamseyPolicyStatement::RamseyPolicyStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg) : symbol_list(symbol_list_arg), diff --git a/ComputingTasks.hh b/ComputingTasks.hh index 572d8016..b9b65d46 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -125,6 +125,24 @@ public: virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; +class RamseyConstraintsStatement : public Statement +{ +public: + struct Constraint { + int endo; + BinaryOpcode code; + expr_t expression; + }; + typedef vector constraints_t; +private: + const constraints_t constraints; +public: + RamseyConstraintsStatement(const constraints_t &constraints_arg); + virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; + // virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); +}; + class RamseyPolicyStatement : public Statement { private: diff --git a/DynareBison.yy b/DynareBison.yy index 5893b6dc..d886fb0f 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -122,7 +122,7 @@ class ParsingDriver; %token SHOCKS SHOCK_DECOMPOSITION SIGMA_E SIMUL SIMUL_ALGO SIMUL_SEED ENDOGENOUS_TERMINAL_PERIOD %token SMOOTHER SMOOTHER2HISTVAL SQUARE_ROOT_SOLVER STACK_SOLVE_ALGO STEADY_STATE_MODEL SOLVE_ALGO SOLVER_PERIODS %token STDERR STEADY STOCH_SIMUL SURPRISE SYLVESTER SYLVESTER_FIXED_POINT_TOL REGIMES REGIME -%token TEX RAMSEY_MODEL RAMSEY_POLICY PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL +%token TEX RAMSEY_MODEL RAMSEY_POLICY RAMSEY_CONSTRAINTS PLANNER_DISCOUNT DISCRETIONARY_POLICY DISCRETIONARY_TOL %token TEX_NAME %token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED %token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES @@ -239,7 +239,8 @@ statement : parameters | planner_objective | ramsey_model | ramsey_policy - | discretionary_policy + | ramsey_constraints + | discretionary_policy | bvar_density | bvar_forecast | sbvar @@ -1903,6 +1904,24 @@ ramsey_policy : RAMSEY_POLICY ';' { driver.ramsey_policy(); } ; +ramsey_constraints : RAMSEY_CONSTRAINTS ';' ramsey_constraints_list END ';' + { driver.add_ramsey_constraints_statement(); } + ; + +ramsey_constraints_list : ramsey_constraints_list ramsey_constraint + | ramsey_constraint + ; + +ramsey_constraint : NAME LESS expression ';' + { driver.ramsey_constraint_add_less($1,$3); } + | NAME GREATER expression ';' + { driver.ramsey_constraint_add_greater($1,$3); } + | NAME LESS_EQUAL expression ';' + { driver.ramsey_constraint_add_less_equal($1,$3); } + | NAME GREATER expression ';' + { driver.ramsey_constraint_add_greater_equal($1,$3); } + ; + discretionary_policy : DISCRETIONARY_POLICY ';' { driver.discretionary_policy(); } | DISCRETIONARY_POLICY '(' discretionary_policy_options_list ')' ';' diff --git a/DynareFlex.ll b/DynareFlex.ll index 92d52ecf..5dcd575d 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -199,6 +199,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 svar_identification {BEGIN DYNARE_BLOCK; return token::SVAR_IDENTIFICATION;} moment_calibration {BEGIN DYNARE_BLOCK; return token::MOMENT_CALIBRATION;} irf_calibration {BEGIN DYNARE_BLOCK; return token::IRF_CALIBRATION;} +ramsey_constraints {BEGIN DYNARE_BLOCK; return token::RAMSEY_CONSTRAINTS;} /* For the semicolon after an "end" keyword */ ; {return Dynare::parser::token_type (yytext[0]);} diff --git a/ParsingDriver.cc b/ParsingDriver.cc index ba541ec8..94679f0a 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2772,3 +2772,54 @@ ParsingDriver::perfect_foresight_solver() mod_file->addStatement(new PerfectForesightSolverStatement(options_list)); options_list.clear(); } + +void +ParsingDriver::add_ramsey_constraints_statement() +{ + mod_file->addStatement(new RamseyConstraintsStatement(ramsey_constraints)); + ramsey_constraints.clear(); +} + +void +ParsingDriver::ramsey_constraint_add_less(const string *name, const expr_t rhs) +{ + add_ramsey_constraint(name,oLess,rhs); +} + +void +ParsingDriver::ramsey_constraint_add_greater(const string *name, const expr_t rhs) +{ + add_ramsey_constraint(name,oGreater,rhs); +} + +void +ParsingDriver::ramsey_constraint_add_less_equal(const string *name, const expr_t rhs) +{ + add_ramsey_constraint(name,oLessEqual,rhs); +} + +void +ParsingDriver::ramsey_constraint_add_greater_equal(const string *name, const expr_t rhs) +{ + add_ramsey_constraint(name,oGreaterEqual,rhs); +} + +void +ParsingDriver::add_ramsey_constraint(const string *name, BinaryOpcode op_code, const expr_t rhs) +{ + check_symbol_existence(*name); + int symb_id = mod_file->symbol_table.getID(*name); + SymbolType type = mod_file->symbol_table.getType(symb_id); + + if (type != eEndogenous) + error("ramsey_constraints: " + *name + " should be an endogenous variable"); + + RamseyConstraintsStatement::Constraint C; + C.endo = symb_id; + C.code = op_code; + C.expression = rhs; + ramsey_constraints.push_back(C); + + delete name; +} + diff --git a/ParsingDriver.hh b/ParsingDriver.hh index dd93276c..d7da536c 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -157,6 +157,8 @@ private: MomentCalibration::constraints_t moment_calibration_constraints; //! Temporary storage for irf_calibration IrfCalibration::constraints_t irf_calibration_constraints; + //! Temporary storage for ramsey_constraints + RamseyConstraintsStatement::constraints_t ramsey_constraints; //! Temporary storage for svar_identification blocks SvarIdentificationStatement::svar_identification_restrictions_t svar_ident_restrictions; //! Temporary storage for mapping the equation number to the restrictions within an svar_identification block @@ -506,6 +508,18 @@ public: void end_planner_objective(expr_t expr); //! Ramsey model statement void ramsey_model(); + //! Ramsey constraints statement + void add_ramsey_constraints_statement(); + //! Ramsey less constraint + void ramsey_constraint_add_less(const string *name, const expr_t rhs); + //! Ramsey greater constraint + void ramsey_constraint_add_greater(const string *name, const expr_t rhs); + //! Ramsey less or equal constraint + void ramsey_constraint_add_less_equal(const string *name, const expr_t rhs); + //! Ramsey greater or equal constraint + void ramsey_constraint_add_greater_equal(const string *name, const expr_t rhs); + //! Ramsey constraint helper function + void add_ramsey_constraint(const string *name, BinaryOpcode op_code, const expr_t rhs); //! Ramsey policy statement void ramsey_policy(); //! Discretionary policy statement From dae14ac19ecd10bcb8dd7e19de846f297bfe0871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Hermes=29?= Date: Mon, 1 Jun 2015 12:27:16 +0200 Subject: [PATCH 59/74] Fixed bug introduced in c22d31330c7d3978f882003ffb999f65be70c4a5 (Ramsey constraints). --- DynareBison.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index d886fb0f..b6a110a1 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -1918,7 +1918,7 @@ ramsey_constraint : NAME LESS expression ';' { driver.ramsey_constraint_add_greater($1,$3); } | NAME LESS_EQUAL expression ';' { driver.ramsey_constraint_add_less_equal($1,$3); } - | NAME GREATER expression ';' + | NAME GREATER_EQUAL expression ';' { driver.ramsey_constraint_add_greater_equal($1,$3); } ; From f914837aff2a3051b397adf2a3df02ddec8258a9 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Tue, 2 Jun 2015 17:38:04 +0200 Subject: [PATCH 60/74] adding options LMMCP and OCCBIN to perfect_foresight_solver and extended_path --- DynareBison.yy | 8 +++++++- DynareFlex.ll | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index b6a110a1..808fa6a7 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -127,7 +127,7 @@ class ParsingDriver; %token UNIFORM_PDF UNIT_ROOT_VARS USE_DLL USEAUTOCORR GSA_SAMPLE_FILE USE_UNIVARIATE_FILTERS_IF_SINGULARITY_IS_DETECTED %token VALUES VAR VAREXO VAREXO_DET VAROBS PREDETERMINED_VARIABLES %token WRITE_LATEX_DYNAMIC_MODEL WRITE_LATEX_STATIC_MODEL WRITE_LATEX_ORIGINAL_MODEL -%token XLS_SHEET XLS_RANGE LONG_NAME +%token XLS_SHEET XLS_RANGE LONG_NAME LMMCP OCCBIN %left COMMA %left EQUAL_EQUAL EXCLAMATION_EQUAL %left LESS GREATER LESS_EQUAL GREATER_EQUAL @@ -1012,6 +1012,8 @@ perfect_foresight_solver_options : o_stack_solve_algo | o_simul_maxit | o_endogenous_terminal_period | o_no_homotopy + | o_lmmcp + | o_occbin ; simul : SIMUL ';' @@ -2453,6 +2455,8 @@ extended_path_option : o_periods | o_solver_periods | o_extended_path_order | o_hybrid + | o_lmmcp + | o_occbin ; model_diagnostics : MODEL_DIAGNOSTICS ';' @@ -3020,6 +3024,8 @@ o_invars : INVARS EQUAL '(' symbol_list ')' { driver.option_symbol_list("invars" o_period : PERIOD EQUAL INT_NUMBER { driver.option_num("period", $3); }; o_outfile : OUTFILE EQUAL filename { driver.option_str("outfile", $3); }; o_outvars : OUTVARS EQUAL '(' symbol_list ')' { driver.option_symbol_list("outvars"); }; +o_lmmcp : LMMCP {driver.option_num("lmmcp", "1"); }; +o_occbin : OCCBIN {driver.option_num("occbin", "1"); }; range : symbol ':' symbol { diff --git a/DynareFlex.ll b/DynareFlex.ll index 5dcd575d..43466da5 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -576,6 +576,8 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 tarb_mode_compute {return token::TARB_MODE_COMPUTE;} tarb_new_block_probability {return token::TARB_NEW_BLOCK_PROBABILITY;} tarb_optim {return token::TARB_OPTIM;} +lmmcp {return token::LMMCP;} +occbin {return token::OCCBIN;} [\$][^$]*[\$] { strtok(yytext+1, "$"); From 567156aad40b9bf07abc9346ef5ff365765ab881 Mon Sep 17 00:00:00 2001 From: Michel Juillard Date: Thu, 4 Jun 2015 14:16:52 +0200 Subject: [PATCH 61/74] option occbin allows for more equations than variables --- ComputingTasks.cc | 9 +++++++++ ModFile.cc | 1 + Statement.cc | 3 ++- Statement.hh | 2 ++ 4 files changed, 14 insertions(+), 1 deletion(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 4e95890d..32d3690b 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -126,6 +126,10 @@ void PerfectForesightSolverStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) { mod_file_struct.perfect_foresight_solver_present = true; + // Fill in option_occbin of mod_file_struct + OptionsList::string_options_t::const_iterator it = options_list.num_options.find("occbin"); + if (it != options_list.string_options.end()) + mod_file_struct.occbin_option = true; } void @@ -4221,6 +4225,11 @@ ExtendedPathStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso cerr << "ERROR: the 'periods' option of 'extended_path' is mandatory" << endl; exit(EXIT_FAILURE); } + + // Fill in option_occbin of mod_file_struct + OptionsList::string_options_t::const_iterator it = options_list.num_options.find("occbin"); + if (it != options_list.string_options.end()) + mod_file_struct.occbin_option = true; } void diff --git a/ModFile.cc b/ModFile.cc index 9c303b01..862fd4ca 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -421,6 +421,7 @@ ModFile::transformPass(bool nostrict) */ if (!(mod_file_struct.ramsey_model_present || mod_file_struct.discretionary_policy_present) && !(mod_file_struct.bvar_present && dynamic_model.equation_number() == 0) + && !(mod_file_struct.occbin_option) && (dynamic_model.equation_number() != symbol_table.endo_nbr())) { cerr << "ERROR: There are " << dynamic_model.equation_number() << " equations but " << symbol_table.endo_nbr() << " endogenous variables!" << endl; diff --git a/Statement.cc b/Statement.cc index b7669c11..a061a6b6 100644 --- a/Statement.cc +++ b/Statement.cc @@ -50,7 +50,8 @@ ModFileStructure::ModFileStructure() : estimation_data_statement_present(false), last_markov_switching_chain(0), calib_smoother_present(false), - estim_params_use_calib(false) + estim_params_use_calib(false), + occbin_option(false) { } diff --git a/Statement.hh b/Statement.hh index 4075524d..4c53f9fc 100644 --- a/Statement.hh +++ b/Statement.hh @@ -118,6 +118,8 @@ public: bool corr_options_statement_present; //! Whether a Markov Switching DSGE is present bool ms_dsge_present; + //! Whether occbin is present + bool occbin_option; }; class Statement From 979fe9344e1667bf3d187d189f62bc1279fe3d73 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 8 Jun 2015 10:32:33 +0200 Subject: [PATCH 62/74] preprocessor: fix sign comparison warning --- Shocks.cc | 2 +- SymbolTable.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Shocks.cc b/Shocks.cc index 10aca26f..81a9cdde 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -76,7 +76,7 @@ AbstractShocksStatement::reindexDetShocksSymbIds(DataTree &dynamic_datatree, Sym try { vector det_shock_vec; - for (int i=0; isecond.size(); i++) + for (size_t i = 0; i < it->second.size(); i++) { DetShockElement dse; dse.period1 = it->second[i].period1; diff --git a/SymbolTable.cc b/SymbolTable.cc index 8ddfc429..dc45f5d1 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -509,7 +509,7 @@ SymbolTable::rmExo(set &unused) throw (FrozenException) for (vector::const_iterator it=name_table.begin(); it != name_table.end(); it++) symbol_table[*it] = size++; - assert(size == symbol_table.size()); + assert((size_t)size == symbol_table.size()); set orig_predetermined_variables = predetermined_variables; predetermined_variables.clear(); From 3740c4a28bc7100592ee1612362a78b402e022e0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 27 May 2015 15:03:27 +0200 Subject: [PATCH 63/74] preprocessor: replace extra exos in steady state model (commit lost in merge) (cherry picked from commit d7db5070e7cf8d1b043062b04d3bd3c4e18ce6c1) --- ModFile.cc | 1 + SteadyStateModel.cc | 33 ++++++++++++++++++++++++++++++++- SteadyStateModel.hh | 4 +++- 3 files changed, 36 insertions(+), 2 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 862fd4ca..97ec4a20 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -315,6 +315,7 @@ ModFile::transformPass(bool nostrict) symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); external_functions_table.reindex(symbol_table, orig_symbol_table); + steady_state_model.reindex(orig_symbol_table); vector orig_statements = statements; statements.clear(); diff --git a/SteadyStateModel.cc b/SteadyStateModel.cc index 7712e9f2..86599eaa 100644 --- a/SteadyStateModel.cc +++ b/SteadyStateModel.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * @@ -104,6 +104,37 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c } } +void +SteadyStateModel::reindex(SymbolTable orig_symbol_table) +{ + if (def_table.empty()) + return; + + DataTree *dt = dynamic_cast (this); + vector new_symb_ids; + vector, expr_t> > orig_def_table = def_table; + def_table.clear(); + for (vector, expr_t> >::const_iterator it = orig_def_table.begin(); + it != orig_def_table.end(); it++) + try + { + new_symb_ids.clear(); + for (vector::const_iterator it1 = it->first.begin(); + it1 != it->first.end(); it1++) + if (symbol_table.getName(*it1) == orig_symbol_table.getName(*it1)) + new_symb_ids.push_back(*it1); + else + new_symb_ids.push_back(symbol_table.getID(orig_symbol_table.getName(*it1))); + addMultipleDefinitions(new_symb_ids, + it->second->cloneDynamicReindex(*dt, orig_symbol_table)); + } + catch (...) + { + cerr << "ERROR: an unused exogenous variable was found in the steady_state_model block" << endl; + exit(EXIT_FAILURE); + } +} + void SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model) const { diff --git a/SteadyStateModel.hh b/SteadyStateModel.hh index 64b78573..8ed9d97d 100644 --- a/SteadyStateModel.hh +++ b/SteadyStateModel.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2014 Dynare Team + * Copyright (C) 2010-2015 Dynare Team * * This file is part of Dynare. * @@ -51,6 +51,8 @@ public: void writeSteadyStateFile(const string &basename, bool ramsey_model) const; // in ExternalFiles.cc void writeSteadyStateFileC(const string &basename, bool ramsey_model) const; + //! Used to reindex def_table after removal of extra exogenous + void reindex(SymbolTable orig_symbol_table); }; #endif From 6c1c1c9bf6e1edf72efd3a8e762031da9a716c3d Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Mon, 22 Sep 2014 10:38:58 +0200 Subject: [PATCH 64/74] Allow for relative_irf option in estimation command The option was used and inherited from stoch_simul before --- DynareBison.yy | 1 + 1 file changed, 1 insertion(+) diff --git a/DynareBison.yy b/DynareBison.yy index 808fa6a7..a7b7b2f2 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -1658,6 +1658,7 @@ estimation_options : o_datafile | o_nodecomposition | o_nodiagnostic | o_bayesian_irf + | o_relative_irf | o_dsge_var | o_dsge_varlag | o_irf From 342d479e8b614e032660c23be7f309ac7a862f7b Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Thu, 14 May 2015 08:27:28 +0200 Subject: [PATCH 65/74] Add preprocessor option silent_optimizer --- DynareBison.yy | 5 ++++- DynareFlex.ll | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 808fa6a7..58dfb561 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -83,7 +83,7 @@ class ParsingDriver; } %token AIM_SOLVER ANALYTIC_DERIVATION AR AUTOCORR TARB_MODE_COMPUTE -%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB TARB_NEW_BLOCK_PROBABILITY +%token BAYESIAN_IRF BETA_PDF BLOCK USE_CALIBRATION USE_TARB TARB_NEW_BLOCK_PROBABILITY SILENT_OPTIMIZER %token BVAR_DENSITY BVAR_FORECAST NODECOMPOSITION DR_DISPLAY_TOL HUGE_NUMBER %token BVAR_PRIOR_DECAY BVAR_PRIOR_FLAT BVAR_PRIOR_LAMBDA TARB_OPTIM %token BVAR_PRIOR_MU BVAR_PRIOR_OMEGA BVAR_PRIOR_TAU BVAR_PRIOR_TRAIN @@ -1722,6 +1722,7 @@ estimation_options : o_datafile | o_tarb_mode_compute | o_tarb_new_block_probability | o_tarb_optim + | o_silent_optimizer | o_proposal_distribution | o_student_degrees_of_freedom ; @@ -1791,6 +1792,7 @@ osr_options : stoch_simul_primary_options | o_opt_algo | o_optim | o_huge_number + | o_silent_optimizer ; osr : OSR ';' @@ -2917,6 +2919,7 @@ o_equations : EQUATIONS EQUAL vec_int o_use_tarb : USE_TARB { driver.option_num("TaRB.use_TaRB", "1"); }; o_tarb_mode_compute : TARB_MODE_COMPUTE EQUAL INT_NUMBER { driver.option_num("TaRB.mode_compute", $3); }; o_tarb_new_block_probability : TARB_NEW_BLOCK_PROBABILITY EQUAL non_negative_number {driver.option_num("TaRB.new_block_probability",$3); }; +o_silent_optimizer : SILENT_OPTIMIZER { driver.option_num("silent_optimizer", "1"); }; o_instruments : INSTRUMENTS EQUAL '(' symbol_list ')' {driver.option_symbol_list("instruments"); }; o_ext_func_name : EXT_FUNC_NAME EQUAL filename { driver.external_function_option("name", $3); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 43466da5..3687d4c2 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -576,6 +576,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 tarb_mode_compute {return token::TARB_MODE_COMPUTE;} tarb_new_block_probability {return token::TARB_NEW_BLOCK_PROBABILITY;} tarb_optim {return token::TARB_OPTIM;} +silent_optimizer {return token::SILENT_OPTIMIZER;} lmmcp {return token::LMMCP;} occbin {return token::OCCBIN;} From 2318fb31c1e6a4d1f2812b35daa85830f014b959 Mon Sep 17 00:00:00 2001 From: Johannes Pfeifer Date: Sun, 17 May 2015 15:33:18 +0200 Subject: [PATCH 66/74] Enable tex option for stoch_simul --- DynareBison.yy | 1 + 1 file changed, 1 insertion(+) diff --git a/DynareBison.yy b/DynareBison.yy index 808fa6a7..8d50f3ab 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -1098,6 +1098,7 @@ stoch_simul_primary_options : o_dr_algo | o_dr_logarithmic_reduction_maxiter | o_irf_plot_threshold | o_dr_display_tol + | o_tex ; stoch_simul_options : stoch_simul_primary_options From 8fe889bf2ff5ad4964e43addbbadc91a37fa36ce Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 9 Jun 2015 16:40:14 +0200 Subject: [PATCH 67/74] Revert "preprocessor: replace extra exos in steady state model" This reverts commit 8bc946c148b3e3321e23bfbace19c91feb2893dc. --- ModFile.cc | 1 - SteadyStateModel.cc | 33 +-------------------------------- SteadyStateModel.hh | 4 +--- 3 files changed, 2 insertions(+), 36 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 97ec4a20..862fd4ca 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -315,7 +315,6 @@ ModFile::transformPass(bool nostrict) symbol_table.rmExo(unusedExo); dynamic_model.reindex(orig_symbol_table); external_functions_table.reindex(symbol_table, orig_symbol_table); - steady_state_model.reindex(orig_symbol_table); vector orig_statements = statements; statements.clear(); diff --git a/SteadyStateModel.cc b/SteadyStateModel.cc index 86599eaa..7712e9f2 100644 --- a/SteadyStateModel.cc +++ b/SteadyStateModel.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Dynare Team + * Copyright (C) 2010-2014 Dynare Team * * This file is part of Dynare. * @@ -104,37 +104,6 @@ SteadyStateModel::checkPass(bool ramsey_model, WarningConsolidation &warnings) c } } -void -SteadyStateModel::reindex(SymbolTable orig_symbol_table) -{ - if (def_table.empty()) - return; - - DataTree *dt = dynamic_cast (this); - vector new_symb_ids; - vector, expr_t> > orig_def_table = def_table; - def_table.clear(); - for (vector, expr_t> >::const_iterator it = orig_def_table.begin(); - it != orig_def_table.end(); it++) - try - { - new_symb_ids.clear(); - for (vector::const_iterator it1 = it->first.begin(); - it1 != it->first.end(); it1++) - if (symbol_table.getName(*it1) == orig_symbol_table.getName(*it1)) - new_symb_ids.push_back(*it1); - else - new_symb_ids.push_back(symbol_table.getID(orig_symbol_table.getName(*it1))); - addMultipleDefinitions(new_symb_ids, - it->second->cloneDynamicReindex(*dt, orig_symbol_table)); - } - catch (...) - { - cerr << "ERROR: an unused exogenous variable was found in the steady_state_model block" << endl; - exit(EXIT_FAILURE); - } -} - void SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model) const { diff --git a/SteadyStateModel.hh b/SteadyStateModel.hh index 8ed9d97d..64b78573 100644 --- a/SteadyStateModel.hh +++ b/SteadyStateModel.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Dynare Team + * Copyright (C) 2010-2014 Dynare Team * * This file is part of Dynare. * @@ -51,8 +51,6 @@ public: void writeSteadyStateFile(const string &basename, bool ramsey_model) const; // in ExternalFiles.cc void writeSteadyStateFileC(const string &basename, bool ramsey_model) const; - //! Used to reindex def_table after removal of extra exogenous - void reindex(SymbolTable orig_symbol_table); }; #endif From 8f121273bc235b5989f4e9a056ad3ecefa4f721f Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 9 Jun 2015 16:41:00 +0200 Subject: [PATCH 68/74] Revert "preprocessor: fix bug in merge of rmExtraExo branch" This reverts commit def2bf81d2b8dacda4b72d4250020eb793f28b20. --- ExprNode.hh | 1 - ExternalFunctionsTable.hh | 1 - 2 files changed, 2 deletions(-) diff --git a/ExprNode.hh b/ExprNode.hh index 048196ca..bef4a415 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -34,7 +34,6 @@ using namespace std; class DataTree; class VariableNode; class BinaryOpNode; -class SymbolTable; typedef class ExprNode *expr_t; diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index 0dfe698a..b5218bea 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -28,7 +28,6 @@ using namespace std; #include #include "SymbolTable.hh" -class SymbolTable; enum ExternalFunctionSetOrNot { From 4102e0cc5651255db464c4d4de4877b095eca91b Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 9 Jun 2015 16:42:51 +0200 Subject: [PATCH 69/74] Revert "Merge branch 'rmExtraExo'" This reverts commit 28ffa9c56fd021cc75415aeafc13d3810d1b3132, reversing changes made to 60b3577a09f3eb9cf3cc590241343b1f0fee8706. Conflicts: preprocessor/Shocks.cc preprocessor/SymbolTable.cc --- ComputingTasks.cc | 1188 ------------------------------------ ComputingTasks.hh | 32 - DataTree.cc | 27 +- DataTree.hh | 5 +- DynamicModel.cc | 17 - DynamicModel.hh | 8 +- ExprNode.cc | 71 --- ExprNode.hh | 12 - ExternalFunctionsTable.cc | 44 +- ExternalFunctionsTable.hh | 6 +- ModFile.cc | 17 +- ModelTree.cc | 58 -- ModelTree.hh | 9 +- NumericalInitialization.cc | 118 +--- NumericalInitialization.hh | 5 - Shocks.cc | 96 --- Shocks.hh | 4 +- Statement.cc | 6 - Statement.hh | 7 - SymbolTable.cc | 47 -- SymbolTable.hh | 2 - 21 files changed, 10 insertions(+), 1769 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 32d3690b..2b4063af 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -169,63 +169,6 @@ StochSimulStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } -Statement * -StochSimulStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list, new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - try - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the stoch_simul statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new StochSimulStatement(new_symbol_list, new_options_list); -} - void StochSimulStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -248,37 +191,6 @@ ForecastStatement::ForecastStatement(const SymbolList &symbol_list_arg, { } -Statement * -ForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the forecast statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - - return new ForecastStatement(new_symbol_list, options_list); -} - void ForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -326,63 +238,6 @@ RamseyModelStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol mod_file_struct.k_order_solver = true; } -Statement * -RamseyModelStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list, new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - try - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the ramsey_model statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new RamseyModelStatement(new_symbol_list, options_list); -} - void RamseyModelStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -547,63 +402,6 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.k_order_solver = true; } -Statement * -RamseyPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list, new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - try - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the ramsey_policy statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new RamseyPolicyStatement(new_symbol_list, options_list); -} - void RamseyPolicyStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -664,63 +462,6 @@ DiscretionaryPolicyStatement::checkPass(ModFileStructure &mod_file_struct, Warni mod_file_struct.k_order_solver = true; } -Statement * -DiscretionaryPolicyStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list, new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("instruments"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - try - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options["instruments"] = new_options_symbol_list; - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the discretionary_policy statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new DiscretionaryPolicyStatement(new_symbol_list, options_list); -} - void DiscretionaryPolicyStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -827,63 +568,6 @@ EstimationStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } -Statement * -EstimationStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list, new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - OptionsList::symbol_list_options_t::const_iterator it = options_list.symbol_list_options.find("irf_shocks"); - if (it != options_list.symbol_list_options.end()) - { - symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - try - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options["irf_shocks"] = new_options_symbol_list; - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the estimation statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new EstimationStatement(new_symbol_list, new_options_list); -} - void EstimationStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -919,61 +603,6 @@ DynareSensitivityStatement::checkPass(ModFileStructure &mod_file_struct, Warning mod_file_struct.identification_present = true; } -Statement * -DynareSensitivityStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string opts_to_check[] = {"namendo", "namlagendo", "namexo", "var_rmse"}; - vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - try - { - OptionsList::symbol_list_options_t::const_iterator it1 = - options_list.symbol_list_options.find(*it); - if (it1 != options_list.symbol_list_options.end()) - { - vector symbols = it1->second.get_symbols(); - for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) - try - { - new_symbol_table->getID(*it2); - new_options_symbol_list.addSymbol(*it2); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options[*it] = new_options_symbol_list; - } - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the dynare_sensitivity statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new DynareSensitivityStatement(new_options_list); -} - void DynareSensitivityStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1001,36 +630,6 @@ RplotStatement::RplotStatement(const SymbolList &symbol_list_arg) : { } -Statement * -RplotStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the rplot statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new RplotStatement(new_symbol_list); -} - void RplotStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1147,42 +746,6 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo mod_file_struct.estimated_parameters.insert(symbol_table.getID(it->name)); } -Statement * -EstimatedParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - vector new_estim_params_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) - try - { - if (!it->name2.empty()) - { - new_symbol_table->getID(it->name); - new_symbol_table->getID(it->name2); - } - else - new_symbol_table->getID(it->name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the estimated_params statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new EstimatedParamsStatement(estim_params_list, *new_symbol_table); -} - void EstimatedParamsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1258,41 +821,6 @@ EstimatedParamsInitStatement::checkPass(ModFileStructure &mod_file_struct, Warni mod_file_struct.estim_params_use_calib = true; } -Statement * -EstimatedParamsInitStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - vector new_estim_params_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) - try - { - if (!it->name2.empty()) - { - new_symbol_table->getID(it->name); - new_symbol_table->getID(it->name2); - } - else - new_symbol_table->getID(it->name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the estimated_params_init statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new EstimatedParamsInitStatement(estim_params_list, *new_symbol_table, use_calibration); -} - void EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1359,41 +887,6 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector errors; - vector new_estim_params_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - for (vector::const_iterator it = estim_params_list.begin(); - it != estim_params_list.end(); it++) - try - { - if (!it->name2.empty()) - { - new_symbol_table->getID(it->name); - new_symbol_table->getID(it->name2); - } - else - new_symbol_table->getID(it->name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the estimated_params_bounds statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new EstimatedParamsBoundsStatement(estim_params_list, *new_symbol_table); -} - void EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1482,39 +975,6 @@ ObservationTrendsStatement::ObservationTrendsStatement(const trend_elements_t &t { } -Statement * -ObservationTrendsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - map new_trend_elements; - for (map::const_iterator it = trend_elements.begin(); - it != trend_elements.end(); it++) - try - { - symbol_table.getID(it->first); - new_trend_elements[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the observation_trends statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new ObservationTrendsStatement(new_trend_elements, symbol_table); -} - void ObservationTrendsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1548,36 +1008,6 @@ OsrParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid mod_file_struct.osr_params_present = true; } -Statement * -OsrParamsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the osr_params statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new OsrParamsStatement(new_symbol_list); -} - void OsrParamsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1613,36 +1043,6 @@ OsrStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation mod_file_struct.k_order_solver = true; } -Statement * -OsrStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the osr statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new OsrStatement(new_symbol_list, options_list); -} - void OsrStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1673,59 +1073,6 @@ OptimWeightsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.optim_weights_present = true; } -Statement * -OptimWeightsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - var_weights_t new_var_weights; - covar_weights_t new_covar_weights; - - for (var_weights_t::const_iterator it = var_weights.begin(); - it != var_weights.end(); it++) - try - { - symbol_table.getID(it->first); - new_var_weights[it->first] = it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - for (covar_weights_t::const_iterator it = covar_weights.begin(); - it != covar_weights.end(); it++) - try - { - symbol_table.getID(it->first.first); - 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 (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the optim_weights statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new OptimWeightsStatement(new_var_weights, new_covar_weights, symbol_table); -} - void OptimWeightsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1769,36 +1116,6 @@ DynaSaveStatement::DynaSaveStatement(const SymbolList &symbol_list_arg, { } -Statement * -DynaSaveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the dynasave statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new DynaSaveStatement(new_symbol_list, filename); -} - void DynaSaveStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1814,36 +1131,6 @@ DynaTypeStatement::DynaTypeStatement(const SymbolList &symbol_list_arg, { } -Statement * -DynaTypeStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the dynatype statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new DynaTypeStatement(new_symbol_list, filename); -} - void DynaTypeStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -1893,34 +1180,6 @@ PlannerObjectiveStatement::checkPass(ModFileStructure &mod_file_struct, WarningC mod_file_struct.planner_objective_present = true; } -Statement * -PlannerObjectiveStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - string error; - try - { - model_tree->reindex(orig_symbol_table); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - error = orig_symbol_table.getName(e.id); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - error = e.name; - } - - if (!error.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the planner_objective statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl - << error << endl; - exit(EXIT_FAILURE); - } - return new PlannerObjectiveStatement(model_tree); -} - StaticModel * PlannerObjectiveStatement::getPlannerObjective() const { @@ -2136,36 +1395,6 @@ MSSBVARIrfStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } -Statement * -MSSBVARIrfStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the ms_sbvar_irf statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new MSSBVARIrfStatement(new_symbol_list, options_list); -} - void MSSBVARIrfStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -2324,36 +1553,6 @@ ShockDecompositionStatement::ShockDecompositionStatement(const SymbolList &symbo { } -Statement * -ShockDecompositionStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the shock_decomposition statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new ShockDecompositionStatement(new_symbol_list, options_list); -} - void ShockDecompositionStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -2367,47 +1566,6 @@ ConditionalForecastStatement::ConditionalForecastStatement(const OptionsList &op { } -Statement * -ConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - OptionsList new_options_list = options_list; - OptionsList::symbol_list_options_t::const_iterator it = - options_list.symbol_list_options.find("controlled_varexo"); - if (it != options_list.symbol_list_options.end()) - { - SymbolList new_options_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = it->second.get_symbols(); - for (vector::const_iterator it1 = symbols.begin(); it1 != symbols.end(); it1++) - try - { - new_symbol_table->getID(*it1); - new_options_symbol_list.addSymbol(*it1); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options["controlled_varexo"] = new_options_symbol_list; - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the conditional_forecast statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new ConditionalForecastStatement(new_options_list); -} - void ConditionalForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -2421,36 +1579,6 @@ PlotConditionalForecastStatement::PlotConditionalForecastStatement(int periods_a { } -Statement * -PlotConditionalForecastStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the plot_conditional_forecast statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new PlotConditionalForecastStatement(periods, new_symbol_list); -} - void PlotConditionalForecastStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -3365,25 +2493,6 @@ PriorStatement::PriorStatement(const string &name_arg, { } -Statement * -PriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - new_symbol_table->getID(name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - cerr << endl - << "ERROR: The following vars were used in the prior statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl - << e.name << endl; - exit(EXIT_FAILURE); - } - return new PriorStatement(name, subsample_name, prior_shape, variance, options_list); -} - void PriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -3421,25 +2530,6 @@ StdPriorStatement::StdPriorStatement(const string &name_arg, { } -Statement * -StdPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - cerr << endl - << "ERROR: The following vars were used in the std_prior statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl - << e.name << endl; - exit(EXIT_FAILURE); - } - return new StdPriorStatement(name, subsample_name, prior_shape, variance, options_list, *new_symbol_table); -} - void StdPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -3503,40 +2593,6 @@ CorrPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolid } } -Statement * -CorrPriorStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - try - { - new_symbol_table->getID(name1); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the std_prior statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new CorrPriorStatement(name, name1, subsample_name, prior_shape, variance, options_list, *new_symbol_table); -} - void CorrPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -3616,48 +2672,6 @@ PriorEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli } } -Statement * -PriorEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string names_to_check[] = {to_name1, to_name2, from_name1, from_name2}; - vector opts (names_to_check, names_to_check + sizeof(names_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - try - { - if (!it->empty()) - new_symbol_table->getID(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the prior equal statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new PriorEqualStatement(to_declaration_type, - to_name1, - to_name2, - to_subsample_name, - from_declaration_type, - from_name1, - from_name2, - from_subsample_name, - *new_symbol_table); -} - void PriorEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { @@ -3813,25 +2827,6 @@ OptionsStatement::OptionsStatement(const string &name_arg, { } -Statement * -OptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - try - { - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - new_symbol_table->getID(name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - cerr << endl - << "ERROR: The following vars were used in the options statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl - << e.name << endl; - exit(EXIT_FAILURE); - } - return new OptionsStatement(name, subsample_name, options_list); -} - void OptionsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -3860,25 +2855,6 @@ StdOptionsStatement::StdOptionsStatement(const string &name_arg, { } -Statement * -StdOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - cerr << endl - << "ERROR: The following vars were used in the std_options statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl - << e.name << endl; - exit(EXIT_FAILURE); - } - return new StdOptionsStatement(name, subsample_name, options_list, *new_symbol_table); -} - void StdOptionsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -3934,42 +2910,6 @@ CorrOptionsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsol } } -Statement * -CorrOptionsStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - try - { - new_symbol_table->getID(name); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - try - { - new_symbol_table->getID(name1); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the corr_options statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - - return new CorrOptionsStatement(name, name1, subsample_name, options_list, *new_symbol_table); -} - void CorrOptionsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -4044,49 +2984,6 @@ OptionsEqualStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso } } -Statement * -OptionsEqualStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string names_to_check[] = {to_name1, to_name2, from_name1, from_name2}; - vector opts (names_to_check, names_to_check + sizeof(names_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - try - { - if (!it->empty()) - new_symbol_table->getID(*it); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the options equal statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - - return new OptionsEqualStatement(to_declaration_type, - to_name1, - to_name2, - to_subsample_name, - from_declaration_type, - from_name1, - from_name2, - from_subsample_name, - *new_symbol_table); -} - void OptionsEqualStatement::get_base_name(const SymbolType symb_type, string &lhs_field) const { @@ -4170,36 +3067,6 @@ CalibSmootherStatement::checkPass(ModFileStructure &mod_file_struct, WarningCons mod_file_struct.calib_smoother_present = true; } -Statement * -CalibSmootherStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_symbol_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - vector symbols = symbol_list.get_symbols(); - for (vector::const_iterator it = symbols.begin(); it != symbols.end(); it++) - try - { - new_symbol_table->getID(*it); - new_symbol_list.addSymbol(*it); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the calib_smoother statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new CalibSmootherStatement(new_symbol_list, options_list); -} - void CalibSmootherStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { @@ -4262,61 +3129,6 @@ Smoother2histvalStatement::Smoother2histvalStatement(const OptionsList &options_ { } -Statement * -Smoother2histvalStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - SymbolList new_options_symbol_list; - OptionsList new_options_list = options_list; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - string opts_to_check[] = {"invars", "outvars"}; - vector opts (opts_to_check, opts_to_check + sizeof(opts_to_check)/sizeof(string)); - for (vector::const_iterator it=opts.begin(); it != opts.end(); it++) - try - { - OptionsList::symbol_list_options_t::const_iterator it1 = - options_list.symbol_list_options.find(*it); - if (it1 != options_list.symbol_list_options.end()) - { - vector symbols = it1->second.get_symbols(); - for (vector::const_iterator it2 = symbols.begin(); it2 != symbols.end(); it2++) - try - { - new_symbol_table->getID(*it2); - new_options_symbol_list.addSymbol(*it2); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - new_options_list.symbol_list_options[*it] = new_options_symbol_list; - } - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - errors.push_back(orig_symbol_table.getName(e.id)); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the smoother2histval statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new Smoother2histvalStatement(new_options_list); -} - void Smoother2histvalStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const { diff --git a/ComputingTasks.hh b/ComputingTasks.hh index b9b65d46..7e6d863b 100644 --- a/ComputingTasks.hh +++ b/ComputingTasks.hh @@ -97,7 +97,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ForecastStatement : public Statement @@ -109,7 +108,6 @@ public: ForecastStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RamseyModelStatement : public Statement @@ -122,7 +120,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RamseyConstraintsStatement : public Statement @@ -153,7 +150,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DiscretionaryPolicyStatement : public Statement @@ -166,7 +162,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class RplotStatement : public Statement @@ -176,7 +171,6 @@ private: public: RplotStatement(const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class UnitRootVarsStatement : public Statement @@ -215,7 +209,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynareSensitivityStatement : public Statement @@ -226,7 +219,6 @@ public: DynareSensitivityStatement(const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ObservationTrendsStatement : public Statement @@ -240,7 +232,6 @@ public: ObservationTrendsStatement(const trend_elements_t &trend_elements_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OsrParamsStatement : public Statement @@ -251,7 +242,6 @@ public: OsrParamsStatement(const SymbolList &symbol_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OsrStatement : public Statement @@ -264,7 +254,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynaTypeStatement : public Statement @@ -276,7 +265,6 @@ public: DynaTypeStatement(const SymbolList &symbol_list_arg, const string &filename_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class DynaSaveStatement : public Statement @@ -288,7 +276,6 @@ public: DynaSaveStatement(const SymbolList &symbol_list_arg, const string &filename_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ModelComparisonStatement : public Statement @@ -341,7 +328,6 @@ public: const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EstimatedParamsInitStatement : public Statement @@ -356,7 +342,6 @@ public: const bool use_calibration_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EstimatedParamsBoundsStatement : public Statement @@ -368,7 +353,6 @@ public: EstimatedParamsBoundsStatement(const vector &estim_params_list_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptimWeightsStatement : public Statement @@ -386,7 +370,6 @@ public: const SymbolTable &symbol_table_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; /*! \todo Make model_tree a member instead of a pointer */ @@ -408,7 +391,6 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; //! Return the Planner Objective StaticModel *getPlannerObjective() const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class BVARDensityStatement : public Statement @@ -493,7 +475,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class MSSBVARForecastStatement : public Statement @@ -562,7 +543,6 @@ public: ShockDecompositionStatement(const SymbolList &symbol_list_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ConditionalForecastStatement : public Statement @@ -572,7 +552,6 @@ private: public: ConditionalForecastStatement(const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class PlotConditionalForecastStatement : public Statement @@ -584,7 +563,6 @@ private: public: PlotConditionalForecastStatement(int periods_arg, const SymbolList &symbol_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CalibSmootherStatement : public Statement @@ -597,7 +575,6 @@ public: const OptionsList &options_list_arg); virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ExtendedPathStatement : public Statement @@ -775,7 +752,6 @@ public: const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdPriorStatement : public BasicPriorStatement @@ -791,7 +767,6 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrPriorStatement : public BasicPriorStatement @@ -810,7 +785,6 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class PriorEqualStatement : public Statement @@ -838,7 +812,6 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class BasicOptionsStatement : public Statement @@ -869,7 +842,6 @@ public: OptionsStatement(const string &name_arg, const string &subsample_name_arg, const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class StdOptionsStatement : public BasicOptionsStatement @@ -883,7 +855,6 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class CorrOptionsStatement : public BasicOptionsStatement @@ -899,7 +870,6 @@ public: virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void writeCOutput(ostream &output, const string &basename); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class OptionsEqualStatement : public Statement @@ -927,7 +897,6 @@ public: void get_base_name(const SymbolType symb_type, string &lhs_field) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ModelDiagnosticsStatement : public Statement @@ -944,7 +913,6 @@ private: public: Smoother2histvalStatement(const OptionsList &options_list_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; #endif diff --git a/DataTree.cc b/DataTree.cc index acbae348..3f90a44f 100644 --- a/DataTree.cc +++ b/DataTree.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -50,31 +50,6 @@ DataTree::~DataTree() delete *it; } -void -DataTree::reindex(SymbolTable &orig_symbol_table) -{ - variable_node_map.clear(); - unary_op_node_map.clear(); - binary_op_node_map.clear(); - trinary_op_node_map.clear(); - external_function_node_map.clear(); - first_deriv_external_function_node_map.clear(); - second_deriv_external_function_node_map.clear(); - - reindexLocalVars(orig_symbol_table); -} - -void -DataTree::reindexLocalVars(SymbolTable &orig_symbol_table) -{ - map orig_local_variables_table = local_variables_table; - local_variables_table.clear(); - for (map::const_iterator it = orig_local_variables_table.begin(); - it != orig_local_variables_table.end(); it++) - AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(*this, orig_symbol_table)); -} - expr_t DataTree::AddNonNegativeConstant(const string &value) { diff --git a/DataTree.hh b/DataTree.hh index b7cd2565..d7c53645 100644 --- a/DataTree.hh +++ b/DataTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -233,13 +233,10 @@ public: //! Returns the minimum lag (as a negative number) of the given symbol in the whole data tree (and not only in the equations !!) /*! Returns 0 if the symbol is not used */ int minLagForSymbol(int symb_id) const; - inline SymbolTable *getSymbolTable() const { return &symbol_table; }; //! Write the Header for getPowerDeriv when use_dll is used void writePowerDerivCHeader(ostream &output) const; //! Write getPowerDeriv void writePowerDeriv(ostream &output, bool use_dll) const; - void reindex(SymbolTable &orig_symbol_table); - void reindexLocalVars(SymbolTable &orig_symbol_table); //! Thrown when trying to access an unknown variable by deriv_id class UnknownDerivIDException { diff --git a/DynamicModel.cc b/DynamicModel.cc index a43a599b..339cbe97 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -4202,23 +4202,6 @@ DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno) static_only_equations_lineno.push_back(lineno); } -void -DynamicModel::reindex(SymbolTable &orig_symbol_table) -{ - ModelTree::reindex(orig_symbol_table); - reindexStaticOnlyEquations(orig_symbol_table); -} - -void -DynamicModel::reindexStaticOnlyEquations(SymbolTable &orig_symbol_table) -{ - vectoreqbak = static_only_equations; - static_only_equations.clear(); - for (size_t i = 0; i < eqbak.size(); i++) - addStaticOnlyEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), - static_only_equations_lineno[i]); -} - size_t DynamicModel::staticOnlyEquationsNbr() const { diff --git a/DynamicModel.hh b/DynamicModel.hh index 7adda7fd..d96a7d50 100644 --- a/DynamicModel.hh +++ b/DynamicModel.hh @@ -244,15 +244,9 @@ public: //! Adds an equation marked as [static] void addStaticOnlyEquation(expr_t eq, int lineno); - //! reindex Dynamic Model after removal of extra exogenous - void reindex(SymbolTable &orig_symbol_table); - - //! reindex equations marked as [static] - void reindexStaticOnlyEquations(SymbolTable &orig_symbol_table); - //! Returns number of static only equations size_t staticOnlyEquationsNbr() const; - + //! Returns number of dynamic only equations size_t dynamicOnlyEquationsNbr() const; diff --git a/ExprNode.cc b/ExprNode.cc index c1619806..b9c44055 100644 --- a/ExprNode.cc +++ b/ExprNode.cc @@ -360,12 +360,6 @@ NumConstNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddNonNegativeConstant(datatree.num_constants.get(id)); } -expr_t -NumConstNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - return dynamic_datatree.AddNonNegativeConstant(datatree.num_constants.get(id)); -} - int NumConstNode::maxEndoLead() const { @@ -1006,12 +1000,6 @@ VariableNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddVariable(symb_id, lag); } -expr_t -VariableNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - return dynamic_datatree.AddVariable(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), lag); -} - int VariableNode::maxEndoLead() const { @@ -2264,13 +2252,6 @@ UnaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarUnaryOpNode(substarg, dynamic_datatree); } -expr_t -UnaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - expr_t substarg = arg->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - return buildSimilarUnaryOpNode(substarg, dynamic_datatree); -} - int UnaryOpNode::maxEndoLead() const { @@ -3496,14 +3477,6 @@ BinaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarBinaryOpNode(substarg1, substarg2, dynamic_datatree); } -expr_t -BinaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - expr_t substarg1 = arg1->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - expr_t substarg2 = arg2->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - return buildSimilarBinaryOpNode(substarg1, substarg2, dynamic_datatree); -} - int BinaryOpNode::maxEndoLead() const { @@ -4180,15 +4153,6 @@ TrinaryOpNode::cloneDynamic(DataTree &dynamic_datatree) const return buildSimilarTrinaryOpNode(substarg1, substarg2, substarg3, dynamic_datatree); } -expr_t -TrinaryOpNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - expr_t substarg1 = arg1->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - expr_t substarg2 = arg2->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - expr_t substarg3 = arg3->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - return buildSimilarTrinaryOpNode(substarg1, substarg2, substarg3, dynamic_datatree); -} - int TrinaryOpNode::maxEndoLead() const { @@ -4961,17 +4925,6 @@ ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments); } -expr_t -ExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - vector dynamic_arguments; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); - return dynamic_datatree.AddExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), - dynamic_arguments); -} - expr_t ExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { @@ -5267,18 +5220,6 @@ FirstDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const inputIndex); } -expr_t -FirstDerivExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - vector dynamic_arguments; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); - return dynamic_datatree.AddFirstDerivExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), - dynamic_arguments, - inputIndex); -} - expr_t FirstDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { @@ -5514,18 +5455,6 @@ SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const inputIndex1, inputIndex2); } -expr_t -SecondDerivExternalFunctionNode::cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const -{ - vector dynamic_arguments; - for (vector::const_iterator it = arguments.begin(); - it != arguments.end(); it++) - dynamic_arguments.push_back((*it)->cloneDynamicReindex(dynamic_datatree, orig_symbol_table)); - return dynamic_datatree.AddSecondDerivExternalFunction(dynamic_datatree.symbol_table.getID(orig_symbol_table.getName(symb_id)), - dynamic_arguments, - inputIndex1, inputIndex2); -} - expr_t SecondDerivExternalFunctionNode::buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const { diff --git a/ExprNode.hh b/ExprNode.hh index bef4a415..0500ff6d 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -410,9 +410,6 @@ public: //! Add ExprNodes to the provided datatree virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; - //! Add ExprNodes to the provided datatree, changing the symbol id from those provided in orig_symbol_table - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const = 0; - //! Move a trend variable with lag/lead to time t by dividing/multiplying by its growth factor virtual expr_t removeTrendLeadLag(map trend_symbols_map) const = 0; @@ -474,7 +471,6 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -538,7 +534,6 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -617,7 +612,6 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -709,7 +703,6 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; //! Function to write out the oPowerNode in expr_t terms as opposed to writing out the function itself expr_t unpackPowerDeriv() const; @@ -781,7 +774,6 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -858,7 +850,6 @@ public: virtual expr_t replaceTrendVar() const; virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const = 0; virtual expr_t removeTrendLeadLag(map trend_symbols_map) const; virtual bool isInStaticForm() const; }; @@ -889,7 +880,6 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; class FirstDerivExternalFunctionNode : public AbstractExternalFunctionNode @@ -924,7 +914,6 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; class SecondDerivExternalFunctionNode : public AbstractExternalFunctionNode @@ -961,7 +950,6 @@ public: virtual expr_t toStatic(DataTree &static_datatree) const; virtual expr_t buildSimilarExternalFunctionNode(vector &alt_args, DataTree &alt_datatree) const; virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const; - virtual expr_t cloneDynamicReindex(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) const; }; #endif diff --git a/ExternalFunctionsTable.cc b/ExternalFunctionsTable.cc index 2fa1523d..8554d830 100644 --- a/ExternalFunctionsTable.cc +++ b/ExternalFunctionsTable.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Dynare Team + * Copyright (C) 2010-2011 Dynare Team * * This file is part of Dynare. * @@ -24,6 +24,7 @@ #include #include "ExternalFunctionsTable.hh" +#include "SymbolTable.hh" ExternalFunctionsTable::ExternalFunctionsTable() { @@ -114,44 +115,3 @@ ExternalFunctionsTable::addExternalFunction(int symb_id, const external_function externalFunctionTable[symb_id] = external_function_options_chng; } - -void -ExternalFunctionsTable::reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table) -{ - external_function_table_type orig_externalFunctionTable = externalFunctionTable; - externalFunctionTable.clear(); - for (external_function_table_type::const_iterator it = orig_externalFunctionTable.begin(); - it != orig_externalFunctionTable.end(); it++) - try - { - external_function_options new_external_function_options; - if (it->second.firstDerivSymbID == eExtFunNotSet || - it->second.firstDerivSymbID == eExtFunSetButNoNameProvided) - new_external_function_options.firstDerivSymbID = it->second.firstDerivSymbID; - else - new_external_function_options.firstDerivSymbID = - new_symbol_table.getID(orig_symbol_table.getName(it->second.firstDerivSymbID)); - - if (it->second.secondDerivSymbID == eExtFunNotSet || - it->second.secondDerivSymbID == eExtFunSetButNoNameProvided) - new_external_function_options.secondDerivSymbID = it->second.secondDerivSymbID; - else - new_external_function_options.secondDerivSymbID = - new_symbol_table.getID(orig_symbol_table.getName(it->second.secondDerivSymbID)); - new_external_function_options.nargs = it->second.nargs; - bool new_track_nargs = true; - if (it->second.nargs == eExtFunNotSet) - { - new_track_nargs = false; - new_external_function_options.nargs = eExtFunSetDefaultNargs; - } - addExternalFunction(new_symbol_table.getID(orig_symbol_table.getName(it->first)), - new_external_function_options, - new_track_nargs); - } - catch (...) - { - cerr << "Error: problem encountered when reindexing external functions table." << endl; - exit(EXIT_FAILURE); - } -} diff --git a/ExternalFunctionsTable.hh b/ExternalFunctionsTable.hh index b5218bea..aa4b02cd 100644 --- a/ExternalFunctionsTable.hh +++ b/ExternalFunctionsTable.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2010-2015 Dynare Team + * Copyright (C) 2010-2011 Dynare Team * * This file is part of Dynare. * @@ -27,8 +27,6 @@ using namespace std; #include #include -#include "SymbolTable.hh" - enum ExternalFunctionSetOrNot { eExtFunSetButNoNameProvided = -2, //! Signifies that the derivative is obtained from the top-level function @@ -78,8 +76,6 @@ public: inline int getSecondDerivSymbID(int symb_id) const throw (UnknownExternalFunctionSymbolIDException); //! Returns the total number of unique external functions declared or used in the .mod file inline int get_total_number_of_unique_model_block_external_functions() const; - //! Reindex external function table (after removal of extra exo) - void reindex(SymbolTable &new_symbol_table, SymbolTable &orig_symbol_table); }; inline bool diff --git a/ModFile.cc b/ModFile.cc index 862fd4ca..285532a5 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -300,28 +300,13 @@ ModFile::checkPass() if (++it != unusedExo.end()) warnings << ", "; } - warnings << ") are declared but not used in the model. We have removed them and will attempt to continue..." << endl; + warnings << ") are declared but not used in the model. This may lead to crashes or unexpected behaviour." << endl; } } void ModFile::transformPass(bool nostrict) { - // Remove unused exogenous from symbol table and update dynamic_model - set unusedExo = dynamic_model.findUnusedExogenous(); - if (unusedExo.size() > 0) - { - SymbolTable orig_symbol_table = symbol_table; - symbol_table.rmExo(unusedExo); - dynamic_model.reindex(orig_symbol_table); - external_functions_table.reindex(symbol_table, orig_symbol_table); - - vector orig_statements = statements; - statements.clear(); - for (vector::iterator it = orig_statements.begin(); it != orig_statements.end(); it++) - addStatement((*it)->cloneAndReindexSymbIds(dynamic_model, orig_symbol_table)); - } - // Save the original model (must be done before any model transformations by preprocessor) dynamic_model.cloneDynamic(original_model); diff --git a/ModelTree.cc b/ModelTree.cc index 9d187b05..688d4f29 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1413,64 +1413,6 @@ ModelTree::addAuxEquation(expr_t eq) aux_equations.push_back(beq); } -void -ModelTree::reindex(SymbolTable &orig_symbol_table) -{ - DataTree::reindex(orig_symbol_table); - reindexEquations(orig_symbol_table); - reindexTrendSymbolsMap(orig_symbol_table); - reindexNonstationarySymbolsMap(orig_symbol_table); -} - -void -ModelTree::reindexEquations(SymbolTable &orig_symbol_table) -{ - vectoreqbak = equations; - equations.clear(); - for (size_t i = 0; i < eqbak.size(); i++) - addEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), equations_lineno[i]); -} - -void -ModelTree::reindexTrendSymbolsMap(SymbolTable &orig_symbol_table) -{ - map orig_trend_symbols_map = trend_symbols_map; - trend_symbols_map.clear(); - for (map::const_iterator it = orig_trend_symbols_map.begin(); - it != orig_trend_symbols_map.end(); it++) - try - { - vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); - addTrendVariables(symb_id, it->second->cloneDynamicReindex(*this, orig_symbol_table)); - } - catch(...) - { - cerr << "Error: unused exo in trend symbols." << endl; - exit(EXIT_FAILURE); - } -} - -void -ModelTree::reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table) -{ - nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map; - nonstationary_symbols_map.clear(); - for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin(); - it != orig_nonstationary_symbols_map.end(); it++) - try - { - vector symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first))); - addNonstationaryVariables(symb_id, - it->second.first, - it->second.second->cloneDynamicReindex(*this, orig_symbol_table)); - } - catch(...) - { - cerr << "Error: unused exo in nonstationary symbols." << endl; - exit(EXIT_FAILURE); - } -} - void ModelTree::addTrendVariables(vector trend_vars, expr_t growth_factor) throw (TrendException) { diff --git a/ModelTree.hh b/ModelTree.hh index b86376b2..4d161daf 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2015 Dynare Team + * Copyright (C) 2003-2014 Dynare Team * * This file is part of Dynare. * @@ -303,13 +303,6 @@ public: void addEquation(expr_t eq, int lineno, vector > &eq_tags); //! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations void addAuxEquation(expr_t eq); - void reindex(SymbolTable &orig_symbol_table); - //! reindex equations after change in symbol_table - void reindexEquations(SymbolTable &orig_symbol_table); - //! reindex trend_symbol_map after change in symbol_table - void reindexTrendSymbolsMap(SymbolTable &orig_symbol_table); - //! reindex nonstationary_symbol_map after change in symbol_table - void reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table); //! Returns the number of equations in the model int equation_number() const; //! Adds a trend variable with its growth factor diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index a86cedfc..85055905 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -74,32 +74,6 @@ InitParamStatement::fillEvalContext(eval_context_t &eval_context) const } } -Statement * -InitParamStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - string error; - try - { - return new InitParamStatement(symbol_table.getID(orig_symbol_table.getName(symb_id)), - param_value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table), - symbol_table); - } - catch (SymbolTable::UnknownSymbolIDException &e) - { - error = orig_symbol_table.getName(e.id); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - error = e.name; - } - - cerr << endl - << "ERROR: The following vars were used in the init param statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl - << error << endl; - exit(EXIT_FAILURE); -} - InitOrEndValStatement::InitOrEndValStatement(const init_values_t &init_values_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : @@ -235,35 +209,6 @@ InitValStatement::writeOutputPostInit(ostream &output) const <<"end;" << endl; } -Statement * -InitValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - init_values_t new_init_values; - for (init_values_t::const_iterator it=init_values.begin(); - it != init_values.end(); it++) - try - { - new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the initval statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new InitValStatement(new_init_values, symbol_table, all_values_required); -} - EndValStatement::EndValStatement(const init_values_t &init_values_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : @@ -310,36 +255,6 @@ EndValStatement::writeOutput(ostream &output, const string &basename, bool minim writeInitValues(output); } -Statement * -EndValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - init_values_t new_init_values; - - for (init_values_t::const_iterator it=init_values.begin(); - it != init_values.end(); it++) - try - { - new_init_values.push_back(make_pair(symbol_table.getID(orig_symbol_table.getName(it->first)), - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table))); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the endval statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new EndValStatement(new_init_values, symbol_table, all_values_required); -} - HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, const SymbolTable &symbol_table_arg) : hist_values(hist_values_arg), @@ -406,36 +321,6 @@ HistValStatement::writeOutput(ostream &output, const string &basename, bool mini } } -Statement * -HistValStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - vector errors; - hist_values_t new_hist_values; - for (hist_values_t::const_iterator it=hist_values.begin(); - it != hist_values.end(); it++) - try - { - new_hist_values[make_pair(symbol_table.getID(orig_symbol_table.getName(it->first.first)), - it->first.second)] = - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (SymbolTable::UnknownSymbolNameException &e) - { - errors.push_back(e.name); - } - - if (!errors.empty()) - { - cerr << endl - << "ERROR: The following vars were used in the histval statement(s) but were not declared." << endl - << " This likely means that you declared them as varexo and that they're not in the model" << endl; - for (vector::const_iterator it = errors.begin(); it != errors.end(); it++) - cerr << *it << endl; - exit(EXIT_FAILURE); - } - return new HistValStatement(new_hist_values, symbol_table); -} - InitvalFileStatement::InitvalFileStatement(const string &filename_arg) : filename(filename_arg) { @@ -509,10 +394,9 @@ SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba output << "save_params_and_steady_state('" << filename << "');" << endl; } -LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename_arg, +LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename, const SymbolTable &symbol_table_arg, WarningConsolidation &warnings) : - filename(filename_arg), symbol_table(symbol_table_arg) { cout << "Reading " << filename << "." << endl; diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index a8573f2e..142838f7 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -44,7 +44,6 @@ public: virtual void writeCOutput(ostream &output, const string &basename); //! Fill eval context with parameter value void fillEvalContext(eval_context_t &eval_context) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class InitOrEndValStatement : public Statement @@ -81,7 +80,6 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; //! Writes initializations for oo_.exo_simul and oo_.exo_det_simul void writeOutputPostInit(ostream &output) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class EndValStatement : public InitOrEndValStatement @@ -93,7 +91,6 @@ public: //! Workaround for trac ticket #35 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class HistValStatement : public Statement @@ -114,7 +111,6 @@ public: //! Workaround for trac ticket #157 virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class InitvalFileStatement : public Statement @@ -162,7 +158,6 @@ public: class LoadParamsAndSteadyStateStatement : public Statement { private: - const string filename; const SymbolTable &symbol_table; //! Content of the file /*! Maps symbol ID to numeric value (stored as string) */ diff --git a/Shocks.cc b/Shocks.cc index 81a9cdde..b2ebd79e 100644 --- a/Shocks.cc +++ b/Shocks.cc @@ -67,31 +67,6 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const output << "M_.exo_det_length = " << exo_det_length << ";\n"; } -AbstractShocksStatement::det_shocks_t -AbstractShocksStatement::reindexDetShocksSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - det_shocks_t new_det_shocks; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - for (det_shocks_t::const_iterator it=det_shocks.begin(); it!=det_shocks.end(); it++) - try - { - vector det_shock_vec; - for (size_t i = 0; i < it->second.size(); i++) - { - DetShockElement dse; - dse.period1 = it->second[i].period1; - dse.period2 = it->second[i].period2; - dse.value = it->second[i].value->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - det_shock_vec.push_back(dse); - } - new_det_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = det_shock_vec; - } - catch (...) - { - } - return new_det_shocks; -} - ShocksStatement::ShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const var_and_std_shocks_t &var_shocks_arg, @@ -357,69 +332,6 @@ ShocksStatement::has_calibrated_measurement_errors() const return false; } -Statement * -ShocksStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - var_and_std_shocks_t new_var_shocks, new_std_shocks; - covar_and_corr_shocks_t new_covar_shocks, new_corr_shocks; - SymbolTable *new_symbol_table = dynamic_datatree.getSymbolTable(); - - for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); - it != var_shocks.end(); it++) - try - { - new_var_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (...) - { - } - - for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); - it != std_shocks.end(); it++) - try - { - new_std_shocks[new_symbol_table->getID(orig_symbol_table.getName(it->first))] = - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (...) - { - } - - for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); - it != covar_shocks.end(); it++) - try - { - new_covar_shocks[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), - new_symbol_table->getID(orig_symbol_table.getName(it->first.second)))] = - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (...) - { - } - - for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); - it != corr_shocks.end(); it++) - try - { - new_corr_shocks[make_pair(new_symbol_table->getID(orig_symbol_table.getName(it->first.first)), - new_symbol_table->getID(orig_symbol_table.getName(it->first.second)))] = - it->second->cloneDynamicReindex(dynamic_datatree, orig_symbol_table); - } - catch (...) - { - } - - return new ShocksStatement(overwrite, - reindexDetShocksSymbIds(dynamic_datatree, orig_symbol_table), - new_var_shocks, - new_std_shocks, - new_covar_shocks, - new_corr_shocks, - *(dynamic_datatree.getSymbolTable())); -} - - MShocksStatement::MShocksStatement(bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg) : @@ -440,14 +352,6 @@ MShocksStatement::writeOutput(ostream &output, const string &basename, bool mini writeDetShocks(output); } -Statement * -MShocksStatement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - return new MShocksStatement(overwrite, - reindexDetShocksSymbIds(dynamic_datatree, orig_symbol_table), - *(dynamic_datatree.getSymbolTable())); -} - ConditionalForecastPathsStatement::ConditionalForecastPathsStatement(const AbstractShocksStatement::det_shocks_t &paths_arg) : paths(paths_arg), path_length(-1) diff --git a/Shocks.hh b/Shocks.hh index dc11dbc3..155ef967 100644 --- a/Shocks.hh +++ b/Shocks.hh @@ -50,7 +50,7 @@ protected: const det_shocks_t det_shocks; const SymbolTable &symbol_table; void writeDetShocks(ostream &output) const; - det_shocks_t reindexDetShocksSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); + AbstractShocksStatement(bool mshocks_arg, bool overwrite_arg, const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); @@ -79,7 +79,6 @@ public: const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; virtual void checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings); - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class MShocksStatement : public AbstractShocksStatement @@ -89,7 +88,6 @@ public: const det_shocks_t &det_shocks_arg, const SymbolTable &symbol_table_arg); virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class ConditionalForecastPathsStatement : public Statement diff --git a/Statement.cc b/Statement.cc index a061a6b6..5da10f1f 100644 --- a/Statement.cc +++ b/Statement.cc @@ -74,12 +74,6 @@ Statement::computingPass() { } -Statement * -Statement::cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table) -{ - return this; -} - NativeStatement::NativeStatement(const string &native_statement_arg) : native_statement(native_statement_arg) { diff --git a/Statement.hh b/Statement.hh index 4c53f9fc..6fe1e7aa 100644 --- a/Statement.hh +++ b/Statement.hh @@ -27,8 +27,6 @@ #include "SymbolList.hh" #include "WarningConsolidation.hh" -#include "SymbolTable.hh" -#include "DataTree.hh" class ModFileStructure { @@ -140,11 +138,6 @@ public: */ virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const = 0; virtual void writeCOutput(ostream &output, const string &basename); - //! clone a statement while updating all symbol ids that are contained within it. - /* Symbol id's are updated from the symbol table contained in dynamic_datatree - The original symbol table is contained in orig_symbol_table - */ - virtual Statement *cloneAndReindexSymbIds(DataTree &dynamic_datatree, SymbolTable &orig_symbol_table); }; class NativeStatement : public Statement diff --git a/SymbolTable.cc b/SymbolTable.cc index dc45f5d1..2c1a699c 100644 --- a/SymbolTable.cc +++ b/SymbolTable.cc @@ -21,7 +21,6 @@ #include #include #include -#include #include "SymbolTable.hh" @@ -483,52 +482,6 @@ SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index) throw (FrozenExce return symb_id; } -void -SymbolTable::rmExo(set &unused) throw (FrozenException) -{ - if (frozen) - throw FrozenException(); - - list idxs; - for (set::const_iterator it = unused.begin(); it != unused.end(); it++) - idxs.push_back(getID(getName(*it))); - - idxs.sort(); - idxs.reverse(); - vector orig_name_table = name_table; - for (list::const_iterator it = idxs.begin(); it != idxs.end(); it++) - { - type_table.erase(type_table.begin() + *it); - name_table.erase(name_table.begin() + *it); - tex_name_table.erase(tex_name_table.begin() + *it); - long_name_table.erase(long_name_table.begin() + *it); - } - - symbol_table.clear(); - size = 0; - for (vector::const_iterator it=name_table.begin(); - it != name_table.end(); it++) - symbol_table[*it] = size++; - assert((size_t)size == symbol_table.size()); - - set orig_predetermined_variables = predetermined_variables; - predetermined_variables.clear(); - for (set::const_iterator it=orig_predetermined_variables.begin(); - it != orig_predetermined_variables.end(); it++) - if (orig_name_table[*it] != getName(*it)) - markPredetermined(getID(orig_name_table[*it])); - else - markPredetermined(*it); - - vector orig_varobs = varobs; - varobs.clear(); - for (vector::const_iterator it=orig_varobs.begin(); it != orig_varobs.end(); it++) - if (orig_name_table[*it] != getName(*it)) - addObservedVariable(getID(orig_name_table[*it])); - else - addObservedVariable(*it); -} - int SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag) throw (FrozenException) { diff --git a/SymbolTable.hh b/SymbolTable.hh index d6d29362..4be960a1 100644 --- a/SymbolTable.hh +++ b/SymbolTable.hh @@ -310,8 +310,6 @@ public: bool isAuxiliaryVariable(int symb_id) const; //! Get list of endogenous variables without aux vars set getOrigEndogenous() const; - //! Remove exogenous variables contained in the set - void rmExo(set &unused) throw (FrozenException); }; inline bool From f94c7ab33250281ac03d926fc4353a787e58ccf9 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 16 Jun 2015 12:48:32 +0200 Subject: [PATCH 70/74] preprocessor: add VerbatimStatement class. Closes #953 --- DynareFlex.ll | 4 ++-- ParsingDriver.cc | 17 +++++++++++++++++ ParsingDriver.hh | 4 ++++ Statement.cc | 11 +++++++++++ Statement.hh | 9 +++++++++ 5 files changed, 43 insertions(+), 2 deletions(-) diff --git a/DynareFlex.ll b/DynareFlex.ll index 43466da5..56e8f941 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -819,11 +819,11 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 } \n { if (strlen(yytext) > 1) - driver.add_native_remove_charset(yytext, "\n"); + driver.add_verbatim_remove_charset(yytext, "\n"); } . { yymore(); } <> { - driver.add_native(eofbuff); + driver.add_verbatim(eofbuff); yyterminate(); } diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 94679f0a..f2621fcf 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -2586,6 +2586,23 @@ ParsingDriver::add_native_remove_charset(const char *s, const string &token) add_native(str); } +void +ParsingDriver::add_verbatim(const string &s) +{ + mod_file->addStatement(new VerbatimStatement(s)); +} + +void +ParsingDriver::add_verbatim_remove_charset(const char *s, const string &token) +{ + string str = string(s); + size_t found = str.find(token); + + assert(found != string::npos); + str.resize(found); + add_verbatim(str); +} + void ParsingDriver::begin_steady_state_model() { diff --git a/ParsingDriver.hh b/ParsingDriver.hh index d7da536c..7ad6aaf4 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -658,6 +658,10 @@ public: void add_native(const string &s); //! Adds a native statement, first removing the set of characters passed in token (and everything after) void add_native_remove_charset(const char *s, const string &token); + //! Adds a verbatim statement + void add_verbatim(const string &s); + //! Adds a verbatim statement, first removing the set of characters passed in token (and everything after) + void add_verbatim_remove_charset(const char *s, const string &token); //! Resets data_tree and model_tree pointers to default (i.e. mod_file->expressions_tree) void reset_data_tree(); //! Begin a steady_state_model block diff --git a/Statement.cc b/Statement.cc index 5da10f1f..2ec5b031 100644 --- a/Statement.cc +++ b/Statement.cc @@ -92,6 +92,17 @@ NativeStatement::writeOutput(ostream &output, const string &basename, bool minim output << ns << endl; } +VerbatimStatement::VerbatimStatement(const string &verbatim_statement_arg) : + verbatim_statement(verbatim_statement_arg) +{ +} + +void +VerbatimStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const +{ + output << verbatim_statement << endl; +} + void OptionsList::writeOutput(ostream &output) const { diff --git a/Statement.hh b/Statement.hh index 6fe1e7aa..2ac8edba 100644 --- a/Statement.hh +++ b/Statement.hh @@ -149,6 +149,15 @@ public: virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; }; +class VerbatimStatement : public Statement +{ +private: + const string verbatim_statement; +public: + VerbatimStatement(const string &verbatim_statement_arg); + virtual void writeOutput(ostream &output, const string &basename, bool minimal_workspace) const; +}; + class OptionsList { public: From 663d7d82bb512806e6393bd89bb69575b3b9e782 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Tue, 30 Jun 2015 12:12:49 +0200 Subject: [PATCH 71/74] fix typo --- ModFile.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/ModFile.cc b/ModFile.cc index 285532a5..987f0d4b 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -544,8 +544,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo mOutputFile.open(fname.c_str(), ios::out | ios::binary); if (!mOutputFile.is_open()) { - cerr << "ERROR: Can't open file " << fname - << " for writing" << endl; + cerr << "ERROR: Can't open file " << fname << " for writing" << endl; exit(EXIT_FAILURE); } } @@ -556,7 +555,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo } mOutputFile << "%" << endl - << "% Status : main Dynare file " << endl + << "% Status : main Dynare file" << endl << "%" << endl << "% Warning : this file is generated automatically by Dynare" << endl << "% from model file (.mod)" << endl << endl; From 6e52dfb8284f46cd96c2e7b6e6ef815ff6100b9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Sun, 5 Jul 2015 21:57:29 +0200 Subject: [PATCH 72/74] New option linear_approximation for perfect foresight models. This approach only requires one evaluation of the dynamic model (and its jacobian) instead of T (the number of perdiods). Also (because the model is linear) the equilibrium paths are obtained by inverting the jacobian of the stacked equations (no need for a Newton algorithm). Only available with stack_solve_algo==0 (which is the default algorithm for solving perfect foresight models). If possible, the option is triggered automatically if the model is declared linear. TODO: * Write a linear version of perfect_foresight_problem routine. * Evaluate the approxilation error (just need to evaluate the system of stacked non linear equations). --- DynareBison.yy | 4 +++- DynareFlex.ll | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 58dfb561..9d1f1e3c 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -102,7 +102,7 @@ class ParsingDriver; %token INT_NUMBER %token INV_GAMMA_PDF INV_GAMMA1_PDF INV_GAMMA2_PDF IRF IRF_SHOCKS IRF_PLOT_THRESHOLD IRF_CALIBRATION %token KALMAN_ALGO KALMAN_TOL DIFFUSE_KALMAN_TOL SUBSAMPLES OPTIONS TOLF -%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV +%token LAPLACE LIK_ALGO LIK_INIT LINEAR LOAD_IDENT_FILES LOAD_MH_FILE LOAD_PARAMS_AND_STEADY_STATE LOGLINEAR LOGDATA LYAPUNOV LINEAR_APPROXIMATION %token LYAPUNOV_FIXED_POINT_TOL LYAPUNOV_DOUBLING_TOL LYAPUNOV_SQUARE_ROOT_SOLVER_TOL LOG_DEFLATOR LOG_TREND_VAR LOG_GROWTH_FACTOR MARKOWITZ MARGINAL_DENSITY MAX MAXIT %token MFS MH_CONF_SIG MH_DROP MH_INIT_SCALE MH_JSCALE MH_MODE MH_NBLOCKS MH_REPLIC MH_RECOVER POSTERIOR_MAX_SUBSAMPLE_DRAWS MIN MINIMAL_SOLVING_PERIODS %token MODE_CHECK MODE_CHECK_NEIGHBOURHOOD_SIZE MODE_CHECK_SYMMETRIC_PLOTS MODE_CHECK_NUMBER_OF_POINTS MODE_COMPUTE MODE_FILE MODEL MODEL_COMPARISON MODEL_INFO MSHOCKS ABS SIGN @@ -993,6 +993,7 @@ perfect_foresight_setup_options_list : perfect_foresight_setup_options_list COMM ; perfect_foresight_setup_options : o_periods + | o_linear_approximation | o_datafile ; @@ -2675,6 +2676,7 @@ o_mh_mode : MH_MODE EQUAL INT_NUMBER { driver.option_num("mh_mode", $3); }; o_mh_nblocks : MH_NBLOCKS EQUAL INT_NUMBER { driver.option_num("mh_nblck", $3); }; o_load_mh_file : LOAD_MH_FILE { driver.option_num("load_mh_file", "1"); }; o_loglinear : LOGLINEAR { driver.option_num("loglinear", "1"); }; +o_linear_approximation : LINEAR_APPROXIMATION { driver.option_num("linear_approximation", "1"); }; o_logdata : LOGDATA { driver.option_num("logdata", "1"); }; o_nodiagnostic : NODIAGNOSTIC { driver.option_num("nodiagnostic", "1"); }; o_bayesian_irf : BAYESIAN_IRF { driver.option_num("bayesian_irf", "1"); }; diff --git a/DynareFlex.ll b/DynareFlex.ll index 430c66a7..5948febc 100644 --- a/DynareFlex.ll +++ b/DynareFlex.ll @@ -286,6 +286,7 @@ DATE -?[0-9]+([YyAa]|[Mm]([1-9]|1[0-2])|[Qq][1-4]|[Ww]([1-9]{1}|[1-4][0-9]|5[0-2 mh_nblocks {return token::MH_NBLOCKS;} load_mh_file {return token::LOAD_MH_FILE;} loglinear {return token::LOGLINEAR;} +linear_approximation {return token::LINEAR_APPROXIMATION;} logdata {return token::LOGDATA;} nodiagnostic {return token::NODIAGNOSTIC;} kalman_algo {return token::KALMAN_ALGO;} From 7dfba933e508884f0ac8873065305901297be605 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Adjemian=20=28Charybdis=29?= Date: Wed, 8 Jul 2015 11:11:22 +0200 Subject: [PATCH 73/74] Fied bug. Moved option linear_approximation. --- DynareBison.yy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DynareBison.yy b/DynareBison.yy index 9d1f1e3c..0cabe6cd 100644 --- a/DynareBison.yy +++ b/DynareBison.yy @@ -993,7 +993,6 @@ perfect_foresight_setup_options_list : perfect_foresight_setup_options_list COMM ; perfect_foresight_setup_options : o_periods - | o_linear_approximation | o_datafile ; @@ -1012,6 +1011,7 @@ perfect_foresight_solver_options : o_stack_solve_algo | o_minimal_solving_periods | o_simul_maxit | o_endogenous_terminal_period + | o_linear_approximation | o_no_homotopy | o_lmmcp | o_occbin From 947ca384406fa5e8ad6a5afecd04a69dc27e0e69 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Wed, 15 Jul 2015 08:58:15 +0200 Subject: [PATCH 74/74] preprocessor: split creation of latex model files. closes #966 --- DynamicModel.cc | 4 ++-- ModelTree.cc | 34 +++++++++++++++++++++++----------- ModelTree.hh | 4 ++-- StaticModel.cc | 2 +- 4 files changed, 28 insertions(+), 16 deletions(-) diff --git a/DynamicModel.cc b/DynamicModel.cc index 339cbe97..beca6f1f 100644 --- a/DynamicModel.cc +++ b/DynamicModel.cc @@ -3907,13 +3907,13 @@ DynamicModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int l void DynamicModel::writeLatexFile(const string &basename) const { - writeLatexModelFile(basename + "_dynamic.tex", oLatexDynamicModel); + writeLatexModelFile(basename + "_dynamic", oLatexDynamicModel); } void DynamicModel::writeLatexOriginalFile(const string &basename) const { - writeLatexModelFile(basename + "_original.tex", oLatexDynamicModel); + writeLatexModelFile(basename + "_original", oLatexDynamicModel); } void diff --git a/ModelTree.cc b/ModelTree.cc index 688d4f29..14149f59 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -1339,9 +1339,12 @@ ModelTree::Write_Inf_To_Bin_File(const string &basename, } void -ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output_type) const +ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output_type) const { - ofstream output; + ofstream output, content_output; + string filename = basename + ".tex"; + string content_basename = basename + "_content"; + string content_filename = content_basename + ".tex"; output.open(filename.c_str(), ios::out | ios::binary); if (!output.is_open()) { @@ -1349,6 +1352,13 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output exit(EXIT_FAILURE); } + content_output.open(content_filename.c_str(), ios::out | ios::binary); + if (!content_output.is_open()) + { + cerr << "ERROR: Can't open file " << content_filename << " for writing" << endl; + exit(EXIT_FAILURE); + } + output << "\\documentclass[10pt,a4paper]{article}" << endl << "\\usepackage[landscape]{geometry}" << endl << "\\usepackage{fullpage}" << endl @@ -1364,25 +1374,27 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output int id = it->first; expr_t value = it->second; - output << "\\begin{dmath*}" << endl - << symbol_table.getName(id) << " = "; + content_output << "\\begin{dmath*}" << endl + << symbol_table.getName(id) << " = "; // Use an empty set for the temporary terms - value->writeOutput(output, output_type); - output << endl << "\\end{dmath*}" << endl; + value->writeOutput(content_output, output_type); + content_output << endl << "\\end{dmath*}" << endl; } for (int eq = 0; eq < (int) equations.size(); eq++) { - output << "\\begin{dmath}" << endl - << "% Equation " << eq+1 << endl; + content_output << "\\begin{dmath}" << endl + << "% Equation " << eq+1 << endl; // Here it is necessary to cast to superclass ExprNode, otherwise the overloaded writeOutput() method is not found - dynamic_cast(equations[eq])->writeOutput(output, output_type); - output << endl << "\\end{dmath}" << endl; + dynamic_cast(equations[eq])->writeOutput(content_output, output_type); + content_output << endl << "\\end{dmath}" << endl; } - output << "\\end{document}" << endl; + output << "\\include{" << content_basename << "}" << endl + << "\\end{document}" << endl; output.close(); + content_output.close(); } void diff --git a/ModelTree.hh b/ModelTree.hh index 4d161daf..ea799585 100644 --- a/ModelTree.hh +++ b/ModelTree.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2003-2014 Dynare Team + * Copyright (C) 2003-2015 Dynare Team * * This file is part of Dynare. * @@ -183,7 +183,7 @@ protected: void compileModelEquations(ostream &code_file, unsigned int &instruction_number, const temporary_terms_t &tt, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic) const; //! Writes LaTeX model file - void writeLatexModelFile(const string &filename, ExprNodeOutputType output_type) const; + void writeLatexModelFile(const string &basename, ExprNodeOutputType output_type) const; //! Sparse matrix of double to store the values of the Jacobian /*! First index is equation number, second index is endogenous type specific ID */ diff --git a/StaticModel.cc b/StaticModel.cc index 045e6336..523c0ab9 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -1893,7 +1893,7 @@ StaticModel::writeChainRuleDerivative(ostream &output, int eqr, int varr, int la void StaticModel::writeLatexFile(const string &basename) const { - writeLatexModelFile(basename + "_static.tex", oLatexStaticModel); + writeLatexModelFile(basename + "_static", oLatexStaticModel); } void