Simplify constant equations also in equations marked [static]

The simplifyEquations() methods had to be moved to DynamicModel, in order to
access the static_only_equations member.
pac-components
Sébastien Villemot 2021-12-06 16:29:24 +01:00
parent fe974c4c31
commit 5fe94ed606
No known key found for this signature in database
GPG Key ID: 2CECE9350ECEBE4A
5 changed files with 26 additions and 23 deletions

View File

@ -6344,3 +6344,24 @@ DynamicModel::checkNoRemainingPacExpectation() const
exit(EXIT_FAILURE);
}
}
void
DynamicModel::simplifyEquations()
{
size_t last_subst_table_size = 0;
map<VariableNode *, NumConstNode *> 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<BinaryOpNode *>(equation->replaceVarsInEquation(subst_table));
for (auto &equation : static_only_equations)
equation = dynamic_cast<BinaryOpNode *>(equation->replaceVarsInEquation(subst_table));
subst_table.clear();
findConstantEquationsWithoutMcpTag(subst_table);
}
}

View File

@ -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

View File

@ -1938,7 +1938,7 @@ expr_t
VariableNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &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)

View File

@ -1629,25 +1629,6 @@ ModelTree::includeExcludeEquations(set<pair<string, string>> &eqs, bool exclude_
return excluded_vars;
}
void
ModelTree::simplifyEquations()
{
size_t last_subst_table_size = 0;
map<VariableNode *, NumConstNode *> 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<BinaryOpNode *>(equation->replaceVarsInEquation(subst_table));
subst_table.clear();
findConstantEquationsWithoutMcpTag(subst_table);
}
}
void
ModelTree::findConstantEquationsWithoutMcpTag(map<VariableNode *, NumConstNode *> &subst_table) const
{

View File

@ -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();