diff --git a/src/ExprNode.cc b/src/ExprNode.cc index 4c76b5376882f14c0dc0c8421d940c4e71174a5f..ef78d87873a833e01a04398519ec31648b7e199b 100644 --- a/src/ExprNode.cc +++ b/src/ExprNode.cc @@ -1740,9 +1740,9 @@ VariableNode::decreaseLeadsLags(int n) const expr_t VariableNode::decreaseLeadsLagsPredeterminedVariables() const { - if (get_type() == SymbolType::modelLocalVariable) - return datatree.getLocalVariable(symb_id)->decreaseLeadsLagsPredeterminedVariables(); - + /* Do not recurse into model-local variables definitions, since MLVs are + already handled by DynamicModel::transformPredeterminedVariables(). + This is also necessary because of #65. */ if (datatree.symbol_table.isPredetermined(symb_id)) return decreaseLeadsLags(1); else @@ -2118,8 +2118,9 @@ VariableNode::findConstantEquations(map<VariableNode *, NumConstNode *> &table) expr_t VariableNode::replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const { - /* Do not recurse into model-local variables definition, because otherwise - this would substitute MLV in the original model (see #65). */ + /* Do not recurse into model-local variables definitions, since MLVs are + already handled by ModelTree::simplifyEquations(). + This is also necessary because of #65. */ for (auto &it : table) if (it.first->symb_id == symb_id) return it.second; diff --git a/src/ModelTree.cc b/src/ModelTree.cc index f9c757a1880de449fdef18b8759a5417fb58ff1b..bedc4104cbf8ad82d1c3d973403162abcfad5172 100644 --- a/src/ModelTree.cc +++ b/src/ModelTree.cc @@ -2027,6 +2027,8 @@ ModelTree::simplifyEquations() 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();