From 5c24fea3227a946d8c4001094570ddcd038b8ff0 Mon Sep 17 00:00:00 2001 From: Houtan Bastani Date: Mon, 11 Sep 2017 18:14:56 +0200 Subject: [PATCH] preprocessor: allow variables that become state variables in ramsey_policy to be set in histval. closes #1193 --- ComputingTasks.cc | 5 +++++ ModFile.cc | 23 +++++++++++++++++++++++ NumericalInitialization.cc | 3 +++ NumericalInitialization.hh | 3 +++ ParsingDriver.cc | 8 ++------ ParsingDriver.hh | 2 ++ Statement.hh | 4 ++++ 7 files changed, 42 insertions(+), 6 deletions(-) diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1926b67a..7bf65090 100644 --- a/ComputingTasks.cc +++ b/ComputingTasks.cc @@ -604,6 +604,11 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso mod_file_struct.order_option = max(mod_file_struct.order_option, order + 1); } + OptionsList::symbol_list_options_t::const_iterator itsl = + options_list.symbol_list_options.find("instruments"); + if (itsl != options_list.symbol_list_options.end()) + mod_file_struct.ramsey_state_variables = itsl->second.get_symbols(); + // Fill in mod_file_struct.partial_information it = options_list.num_options.find("partial_information"); if (it != options_list.num_options.end() && it->second == "1") diff --git a/ModFile.cc b/ModFile.cc index 3af3faa5..32a72115 100644 --- a/ModFile.cc +++ b/ModFile.cc @@ -149,6 +149,29 @@ ModFile::checkPass(bool nostrict, bool stochastic) exit(EXIT_FAILURE); } + // Workaround for #1193 + if (!mod_file_struct.hist_vals_wrong_lag.empty()) + { + for (vector::const_iterator it = mod_file_struct.ramsey_state_variables.begin(); + it != mod_file_struct.ramsey_state_variables.end(); it++) + { + int symb_id = symbol_table.getID(*it); + map::const_iterator it1 = mod_file_struct.hist_vals_wrong_lag.find(symb_id); + if (it1 != mod_file_struct.hist_vals_wrong_lag.end() && it1->second < 0) + mod_file_struct.hist_vals_wrong_lag.erase(symb_id); + } + + if (!mod_file_struct.hist_vals_wrong_lag.empty()) + { + for (map::const_iterator it = mod_file_struct.hist_vals_wrong_lag.begin(); + it != mod_file_struct.hist_vals_wrong_lag.end(); it++) + cerr << "ERROR: histval: variable " << symbol_table.getName(it->first) + << " does not appear in the model with the lag " << it->second + << " (see the reference manual for the timing convention in 'histval')" << endl; + exit(EXIT_FAILURE); + } + } + if ((mod_file_struct.ramsey_model_present || mod_file_struct.ramsey_policy_present) && mod_file_struct.discretionary_policy_present) { diff --git a/NumericalInitialization.cc b/NumericalInitialization.cc index 84302651..ad199014 100644 --- a/NumericalInitialization.cc +++ b/NumericalInitialization.cc @@ -308,9 +308,11 @@ EndValStatement::writeJsonOutput(ostream &output) const } HistValStatement::HistValStatement(const hist_values_t &hist_values_arg, + const hist_vals_wrong_lag_t hist_vals_wrong_lag_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg) : hist_values(hist_values_arg), + hist_vals_wrong_lag(hist_vals_wrong_lag_arg), symbol_table(symbol_table_arg), all_values_required(all_values_required_arg) { @@ -356,6 +358,7 @@ HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat if (unused_endo.size() > 0 || unused_exo.size() > 0) exit(EXIT_FAILURE); } + mod_file_struct.hist_vals_wrong_lag = hist_vals_wrong_lag; } void diff --git a/NumericalInitialization.hh b/NumericalInitialization.hh index 58a7e6e0..16f5acd1 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -107,12 +107,15 @@ public: Maps pairs (symbol_id, lag) to expr_t */ typedef map, expr_t> hist_values_t; + typedef map hist_vals_wrong_lag_t; private: const hist_values_t hist_values; + const hist_vals_wrong_lag_t hist_vals_wrong_lag; const SymbolTable &symbol_table; const bool all_values_required; public: HistValStatement(const hist_values_t &hist_values_arg, + const hist_vals_wrong_lag_t hist_vals_wrong_lag_arg, const SymbolTable &symbol_table_arg, const bool &all_values_required_arg); //! Workaround for trac ticket #157 diff --git a/ParsingDriver.cc b/ParsingDriver.cc index 565db4b1..52f1177b 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -549,11 +549,7 @@ ParsingDriver::hist_val(string *name, string *lag, expr_t rhs) pair key(symb_id, ilag); if (mod_file->dynamic_model.minLagForSymbol(symb_id) > ilag - 1) - { - ostringstream s; - s << ilag-1; - error("histval: variable " + *name + " does not appear in the model with the lag " + s.str() + " (see the reference manual for the timing convention in 'histval')"); - } + hist_vals_wrong_lag[symb_id] = ilag-1; if (hist_values.find(key) != hist_values.end()) error("hist_val: (" + *name + ", " + *lag + ") declared twice"); @@ -669,7 +665,7 @@ ParsingDriver::end_endval(bool all_values_required) void ParsingDriver::end_histval(bool all_values_required) { - mod_file->addStatement(new HistValStatement(hist_values, mod_file->symbol_table, all_values_required)); + mod_file->addStatement(new HistValStatement(hist_values, hist_vals_wrong_lag, mod_file->symbol_table, all_values_required)); hist_values.clear(); } diff --git a/ParsingDriver.hh b/ParsingDriver.hh index 2504b808..6a2da6ef 100644 --- a/ParsingDriver.hh +++ b/ParsingDriver.hh @@ -157,6 +157,8 @@ private: InitOrEndValStatement::init_values_t init_values; //! Temporary storage for histval blocks HistValStatement::hist_values_t hist_values; + //! Temporary storage for histval blocks + HistValStatement::hist_vals_wrong_lag_t hist_vals_wrong_lag; //! Temporary storage for homotopy_setup blocks HomotopyStatement::homotopy_values_t homotopy_values; //! Temporary storage for moment_calibration diff --git a/Statement.hh b/Statement.hh index db7d5606..70395a35 100644 --- a/Statement.hh +++ b/Statement.hh @@ -123,6 +123,10 @@ public: bool steady_state_model_present; //! Whether there is a write_latex_steady_state_model statement present bool write_latex_steady_state_model_present; + //! Set list of variables that become state variables when ramsey_policy is used + vector ramsey_state_variables; + //! Histval values that do not have the appropriate lag + map hist_vals_wrong_lag; }; class Statement