Fix error message when “ramsey_policy” follows a “ramsey_model” statement

By the way, also fix error message when there are several “ramsey_model” or
“ramsey_policy” statements.

Closes: #90
fix-tolerance-parameters
Sébastien Villemot 2022-02-21 16:43:18 +01:00
parent b78ac1d31f
commit 17c5e1935d
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
2 changed files with 19 additions and 0 deletions

View File

@ -2054,6 +2054,13 @@ ParsingDriver::end_planner_objective(expr_t expr)
void
ParsingDriver::ramsey_model()
{
// Some checks to ensure correct error messages (see #90)
if (ramsey_policy_seen)
error("A 'ramsey_model' statement cannot follow a 'ramsey_policy' statement.");
if (ramsey_model_seen)
error("Several 'ramsey_model' statements cannot appear in a given .mod file.");
ramsey_model_seen = true;
if (!mod_file->symbol_table.exists("optimal_policy_discount_factor"))
{
if (!planner_discount)
@ -2081,6 +2088,13 @@ ParsingDriver::ramsey_policy()
{
warning("The 'ramsey_policy' statement is deprecated. Please use 'ramsey_model', 'stoch_simul', and 'evaluate_planner_objective' instead.");
// Some checks to ensure correct error messages (see #90)
if (ramsey_model_seen)
error("A 'ramsey_policy' statement cannot follow a 'ramsey_model' statement.");
if (ramsey_policy_seen)
error("Several 'ramsey_policy' statements cannot appear in a given .mod file.");
ramsey_policy_seen = true;
if (!mod_file->symbol_table.exists("optimal_policy_discount_factor"))
{
if (!planner_discount)

View File

@ -274,6 +274,11 @@ private:
//! True when parsing pac_model statement
bool parsing_pac_model{false};
//! True if a ramsey_model statement has already been seen
bool ramsey_model_seen{false};
//! True if a ramsey_policy statement has already been seen
bool ramsey_policy_seen{false};
public:
ParsingDriver(WarningConsolidation &warnings_arg, bool nostrict_arg) :
warnings{warnings_arg}, nostrict{nostrict_arg}