diff --git a/src/DynamicModel.cc b/src/DynamicModel.cc index 1bae113b..b32617c5 100644 --- a/src/DynamicModel.cc +++ b/src/DynamicModel.cc @@ -6344,3 +6344,24 @@ DynamicModel::checkNoRemainingPacExpectation() const exit(EXIT_FAILURE); } } + +void +DynamicModel::simplifyEquations() +{ + size_t last_subst_table_size = 0; + map subst_table; + // Equations with “mcp” tag are excluded, see dynare#1697 + findConstantEquationsWithoutMcpTag(subst_table); + while (subst_table.size() != last_subst_table_size) + { + last_subst_table_size = subst_table.size(); + for (auto &[id, definition] : local_variables_table) + definition = definition->replaceVarsInEquation(subst_table); + for (auto &equation : equations) + equation = dynamic_cast(equation->replaceVarsInEquation(subst_table)); + for (auto &equation : static_only_equations) + equation = dynamic_cast(equation->replaceVarsInEquation(subst_table)); + subst_table.clear(); + findConstantEquationsWithoutMcpTag(subst_table); + } +} diff --git a/src/DynamicModel.hh b/src/DynamicModel.hh index 1ce54fb8..09d4d900 100644 --- a/src/DynamicModel.hh +++ b/src/DynamicModel.hh @@ -589,5 +589,9 @@ public: bool ParamUsedWithLeadLag() const; bool isChecksumMatching(const string &basename, bool block) const; + + //! Simplify model equations: if a variable is equal to a constant, replace that variable elsewhere in the model + /*! Equations with MCP tags are excluded, see dynare#1697 */ + void simplifyEquations(); }; #endif diff --git a/src/ExprNode.cc b/src/ExprNode.cc index ddd42699..c2a35b04 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -1938,7 +1938,7 @@ expr_t VariableNode::replaceVarsInEquation(map &table) const { /* Do not recurse into model-local variables definitions, since MLVs are - already handled by ModelTree::simplifyEquations(). + already handled by DynamicModel::simplifyEquations(). This is also necessary because of #65. */ for (auto &it : table) if (it.first->symb_id == symb_id) diff --git a/src/ModelTree.cc b/src/ModelTree.cc index c6216131..da71df01 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -1629,25 +1629,6 @@ ModelTree::includeExcludeEquations(set> &eqs, bool exclude_ return excluded_vars; } -void -ModelTree::simplifyEquations() -{ - size_t last_subst_table_size = 0; - map subst_table; - // Equations with “mcp” tag are excluded, see dynare#1697 - findConstantEquationsWithoutMcpTag(subst_table); - while (subst_table.size() != last_subst_table_size) - { - last_subst_table_size = subst_table.size(); - for (auto &[id, definition] : local_variables_table) - definition = definition->replaceVarsInEquation(subst_table); - for (auto &equation : equations) - equation = dynamic_cast(equation->replaceVarsInEquation(subst_table)); - subst_table.clear(); - findConstantEquationsWithoutMcpTag(subst_table); - } -} - void ModelTree::findConstantEquationsWithoutMcpTag(map &subst_table) const { diff --git a/src/ModelTree.hh b/src/ModelTree.hh index a5e3d1bd..4596df66 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -440,9 +440,6 @@ public: //! Is a given variable non-stationary? bool isNonstationary(int symb_id) const; void set_cutoff_to_zero(); - //! Simplify model equations: if a variable is equal to a constant, replace that variable elsewhere in the model - /*! Equations with MCP tags are excluded, see dynare#1697 */ - void simplifyEquations(); /*! Reorder auxiliary variables so that they appear in recursive order in set_auxiliary_variables.m and dynamic_set_auxiliary_series.m */ void reorderAuxiliaryEquations();