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
parent
fe974c4c31
commit
5fe94ed606
|
@ -6344,3 +6344,24 @@ DynamicModel::checkNoRemainingPacExpectation() const
|
||||||
exit(EXIT_FAILURE);
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -589,5 +589,9 @@ public:
|
||||||
bool ParamUsedWithLeadLag() const;
|
bool ParamUsedWithLeadLag() const;
|
||||||
|
|
||||||
bool isChecksumMatching(const string &basename, bool block) 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
|
#endif
|
||||||
|
|
|
@ -1938,7 +1938,7 @@ expr_t
|
||||||
VariableNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const
|
VariableNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const
|
||||||
{
|
{
|
||||||
/* Do not recurse into model-local variables definitions, since MLVs are
|
/* 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. */
|
This is also necessary because of #65. */
|
||||||
for (auto &it : table)
|
for (auto &it : table)
|
||||||
if (it.first->symb_id == symb_id)
|
if (it.first->symb_id == symb_id)
|
||||||
|
|
|
@ -1629,25 +1629,6 @@ ModelTree::includeExcludeEquations(set<pair<string, string>> &eqs, bool exclude_
|
||||||
return excluded_vars;
|
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
|
void
|
||||||
ModelTree::findConstantEquationsWithoutMcpTag(map<VariableNode *, NumConstNode *> &subst_table) const
|
ModelTree::findConstantEquationsWithoutMcpTag(map<VariableNode *, NumConstNode *> &subst_table) const
|
||||||
{
|
{
|
||||||
|
|
|
@ -440,9 +440,6 @@ public:
|
||||||
//! Is a given variable non-stationary?
|
//! Is a given variable non-stationary?
|
||||||
bool isNonstationary(int symb_id) const;
|
bool isNonstationary(int symb_id) const;
|
||||||
void set_cutoff_to_zero();
|
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
|
/*! Reorder auxiliary variables so that they appear in recursive order in
|
||||||
set_auxiliary_variables.m and dynamic_set_auxiliary_series.m */
|
set_auxiliary_variables.m and dynamic_set_auxiliary_series.m */
|
||||||
void reorderAuxiliaryEquations();
|
void reorderAuxiliaryEquations();
|
||||||
|
|
Loading…
Reference in New Issue