diff --git a/src/ModelTree.cc b/src/ModelTree.cc index f6ec39b38715a77d3c5e8588e3ec85272e0e86a1..ba5b30e8827509d03131b195dbe11f98278e6915 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -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 diff --git a/src/ModelTree.hh b/src/ModelTree.hh index 5d7ad1cbf2b5b44d876c7ae01cdde52a6dc6309a..7f5c5686a614b3416428ba9516e3c46c11046796 100644 --- a/src/ModelTree.hh +++ b/src/ModelTree.hh @@ -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;