Commit bef537d4 authored by Sébastien Villemot's avatar Sébastien Villemot

Do not simplify constant equations which have a tag attached

In particular, in the case of an 'mcp' tag, this could lead to a convergence
failure.

Ref. dynare#1697
parent 0f3f6a23
Pipeline #2987 passed with stages
in 3 minutes and 22 seconds
......@@ -2019,22 +2019,24 @@ ModelTree::simplifyEquations()
{
size_t last_subst_table_size = 0;
map<VariableNode *, NumConstNode *> subst_table;
findConstantEquations(subst_table);
// Equations with tags are excluded, in particular because of MCPs, see dynare#1697
findConstantEquationsWithoutTags(subst_table);
while (subst_table.size() != last_subst_table_size)
{
last_subst_table_size = subst_table.size();
for (auto &equation : equations)
equation = dynamic_cast<BinaryOpNode *>(equation->replaceVarsInEquation(subst_table));
subst_table.clear();
findConstantEquations(subst_table);
findConstantEquationsWithoutTags(subst_table);
}
}
void
ModelTree::findConstantEquations(map<VariableNode *, NumConstNode *> &subst_table) const
ModelTree::findConstantEquationsWithoutTags(map<VariableNode *, NumConstNode *> &subst_table) const
{
for (auto &equation : equations)
equation->findConstantEquations(subst_table);
for (size_t i = 0; i < equations.size(); i++)
if (getEquationTags(i).empty())
equations[i]->findConstantEquations(subst_table);
}
void
......
......@@ -374,12 +374,14 @@ public:
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 tags are excluded, in particular because of MCPs, 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();
//! Find equations where variable is equal to a constant
void findConstantEquations(map<VariableNode *, NumConstNode *> &subst_table) const;
//! Find equations of the form “variable=constant”, excluding equations with tags
void findConstantEquationsWithoutTags(map<VariableNode *, NumConstNode *> &subst_table) const;
//! Helper for writing the Jacobian elements in MATLAB and C
/*! Writes either (i+1,j+1) or [i+j*no_eq] */
void jacobianHelper(ostream &output, int eq_nb, int col_nb, ExprNodeOutputType output_type) const;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment