diff --git a/ComputingTasks.cc b/ComputingTasks.cc index 1926b67ac600889779b779127e7df34a95f3de84..7bf65090dfd80c441f1536cbef74aa5cce4dfd2c 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 3af3faa58495b2e44cffa89dd7aa7dbfb4645681..32a7211543ba37d97813704d53586d93b1531fbf 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<string>::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<int,int>::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<int, int>::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 843026517243ddd088d32a72024f8cf9f1cda271..ad199014b8862e6cccbc03a7738a834312aea3dc 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 58a7e6e0437298f37f1ddfc540ddacbccb318caf..16f5acd1df1112b8d065d68ced1c95205bcecc06 100644 --- a/NumericalInitialization.hh +++ b/NumericalInitialization.hh @@ -107,12 +107,15 @@ public: Maps pairs (symbol_id, lag) to expr_t */ typedef map<pair<int, int>, expr_t> hist_values_t; + typedef map<int, int> 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 565db4b1a6016788dc0b5389e8828a94c61b9c9c..52f1177ba4e55732400eba5566c309b32328d524 100644 --- a/ParsingDriver.cc +++ b/ParsingDriver.cc @@ -549,11 +549,7 @@ ParsingDriver::hist_val(string *name, string *lag, expr_t rhs) pair<int, int> 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 2504b8084a36ece5a0686f12dd1cdda79207977d..6a2da6ef6b02e917b0ed48f6c51d9de01bb69382 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 db7d5606b1bdb6411f96ad14a4a9dc8195cbab3c..70395a35c22f874e14d452184df517937948fccf 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<string> ramsey_state_variables; + //! Histval values that do not have the appropriate lag + map<int, int> hist_vals_wrong_lag; }; class Statement