diff --git a/preprocessor/ComputingTasks.cc b/preprocessor/ComputingTasks.cc index 30615f63f0fc46817fe4efef8548ea03d1b3e8bb..a2284842a361099ab87846c4d337d378e51a2e4c 100644 --- a/preprocessor/ComputingTasks.cc +++ b/preprocessor/ComputingTasks.cc @@ -432,6 +432,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/preprocessor/ModFile.cc b/preprocessor/ModFile.cc index 8d6150a26278ee8793a87083b865905457f7900b..400cb056f03f01e4f5741b41fa7f0715fb529ba1 100644 --- a/preprocessor/ModFile.cc +++ b/preprocessor/ModFile.cc @@ -141,6 +141,29 @@ ModFile::checkPass(bool nostrict) 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/preprocessor/NumericalInitialization.cc b/preprocessor/NumericalInitialization.cc index 7d94397648575616b7af7cd0ca9e04fe6a5fe75d..593800fd989f3a4b8aec4b117d840a76c7e7e704 100644 --- a/preprocessor/NumericalInitialization.cc +++ b/preprocessor/NumericalInitialization.cc @@ -268,9 +268,11 @@ EndValStatement::writeOutput(ostream &output, const string &basename, bool minim } 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) { @@ -316,6 +318,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/preprocessor/NumericalInitialization.hh b/preprocessor/NumericalInitialization.hh index 2e34677b816155039e4dce226f387938a9b84d0b..c2a42b166a581ad44393d4fa5071a573ed5aa60c 100644 --- a/preprocessor/NumericalInitialization.hh +++ b/preprocessor/NumericalInitialization.hh @@ -103,12 +103,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/preprocessor/ParsingDriver.cc b/preprocessor/ParsingDriver.cc index 32b1b3ac24043f92e191d64845f523c4b8422649..9569c27b35d20e9745c8578654677eecf0ee6d7e 100644 --- a/preprocessor/ParsingDriver.cc +++ b/preprocessor/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/preprocessor/ParsingDriver.hh b/preprocessor/ParsingDriver.hh index 80eb4c0a2ac116c86c4682158699af3ba0b47eb1..f8dbe487b66568e6cb4fb06a222b609e9b5d295d 100644 --- a/preprocessor/ParsingDriver.hh +++ b/preprocessor/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/preprocessor/Statement.hh b/preprocessor/Statement.hh index 3e303d8d69b7b94322459ad3e7e622daef9095f2..c99d79eb7bab6fcb4ab18c7be547faa97319c057 100644 --- a/preprocessor/Statement.hh +++ b/preprocessor/Statement.hh @@ -117,7 +117,10 @@ public: int orig_eq_nbr; //! Stores the number of equations added to the Ramsey model int ramsey_eq_nbr; - + //! 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