From e2ce87b7d58944f755bc380f3f60fd7455537a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= Date: Mon, 11 Oct 2010 12:52:27 +0200 Subject: [PATCH] Preprocessor: don't create auxiliary variables for expressions appearing only in unused model local variables --- preprocessor/DynamicModel.cc | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/preprocessor/DynamicModel.cc b/preprocessor/DynamicModel.cc index 619dabefe..ea4b544ed 100644 --- a/preprocessor/DynamicModel.cc +++ b/preprocessor/DynamicModel.cc @@ -3328,30 +3328,35 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model ExprNode::subst_table_t subst_table; vector neweqs; - // Substitute in model local variables - for (map::iterator it = local_variables_table.begin(); - it != local_variables_table.end(); it++) + // Substitute in used model local variables + set used_local_vars; + for (size_t i = 0; i < equations.size(); i++) + equations[i]->collectModelLocalVariables(used_local_vars); + + for (set::const_iterator it = used_local_vars.begin(); + it != used_local_vars.end(); ++it) { + const expr_t value = local_variables_table.find(*it)->second; expr_t subst; switch (type) { case avEndoLead: - subst = it->second->substituteEndoLeadGreaterThanTwo(subst_table, neweqs, deterministic_model); + subst = value->substituteEndoLeadGreaterThanTwo(subst_table, neweqs, deterministic_model); break; case avEndoLag: - subst = it->second->substituteEndoLagGreaterThanTwo(subst_table, neweqs); + subst = value->substituteEndoLagGreaterThanTwo(subst_table, neweqs); break; case avExoLead: - subst = it->second->substituteExoLead(subst_table, neweqs, deterministic_model); + subst = value->substituteExoLead(subst_table, neweqs, deterministic_model); break; case avExoLag: - subst = it->second->substituteExoLag(subst_table, neweqs); + subst = value->substituteExoLag(subst_table, neweqs); break; default: cerr << "DynamicModel::substituteLeadLagInternal: impossible case" << endl; exit(EXIT_FAILURE); } - it->second = subst; + local_variables_table[*it] = subst; } // Substitute in equations