preprocessor: move reindexing functions from DynamicModel to ModelTree
parent
47d0516d4f
commit
ef640070c2
|
@ -3429,47 +3429,6 @@ DynamicModel::writeDynamicFile(const string &basename, bool block, bool bytecode
|
|||
writeDynamicMFile(t_basename);
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table)
|
||||
{
|
||||
map<int, expr_t> orig_trend_symbols_map = trend_symbols_map;
|
||||
trend_symbols_map.clear();
|
||||
for (map<int, expr_t>::const_iterator it = orig_trend_symbols_map.begin();
|
||||
it != orig_trend_symbols_map.end(); it++)
|
||||
try
|
||||
{
|
||||
vector<int> symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first)));
|
||||
addTrendVariables(symb_id,
|
||||
it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
cerr << "Error: unused exo in trend symbols." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table)
|
||||
{
|
||||
nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map;
|
||||
nonstationary_symbols_map.clear();
|
||||
for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin();
|
||||
it != orig_nonstationary_symbols_map.end(); it++)
|
||||
try
|
||||
{
|
||||
vector<int> symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first)));
|
||||
addNonstationaryVariables(symb_id,
|
||||
it->second.first,
|
||||
it->second.second->cloneDynamicReindex(dynamic_model, orig_symbol_table));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
cerr << "Error: unused exo in nonstationary symbols." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::resetDataTree()
|
||||
{
|
||||
|
@ -3483,22 +3442,6 @@ DynamicModel::resetDataTree()
|
|||
second_deriv_external_function_node_map.clear();
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table)
|
||||
{
|
||||
map<int, expr_t> orig_local_variables_table = local_variables_table;
|
||||
local_variables_table.clear();
|
||||
for (map<int, expr_t>::const_iterator it = orig_local_variables_table.begin();
|
||||
it != orig_local_variables_table.end(); it++)
|
||||
dynamic_model.AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)),
|
||||
it->second->cloneDynamicReindex(dynamic_model, orig_symbol_table));
|
||||
|
||||
vector<BinaryOpNode *>eqbak = equations;
|
||||
equations.clear();
|
||||
for (size_t i = 0; i < eqbak.size(); i++)
|
||||
dynamic_model.addEquation(eqbak[i]->cloneDynamicReindex(dynamic_model, orig_symbol_table), equations_lineno[i]);
|
||||
}
|
||||
|
||||
void
|
||||
DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
|
||||
{
|
||||
|
|
|
@ -235,15 +235,6 @@ public:
|
|||
/*! It assumes that the dynamic model given in argument has just been allocated */
|
||||
void cloneDynamic(DynamicModel &dynamic_model) const;
|
||||
|
||||
//! reindex equations after change in symbol_table
|
||||
void reindexEquations(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table);
|
||||
|
||||
//! reindex trend_symbol_map after change in symbol_table
|
||||
void reindexTrendSymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table);
|
||||
|
||||
//! reindex nonstationary_symbol_map after change in symbol_table
|
||||
void reindexNonstationarySymbolsMap(DynamicModel &dynamic_model, SymbolTable &orig_symbol_table);
|
||||
|
||||
//! reset DataTree vars
|
||||
void resetDataTree();
|
||||
|
||||
|
|
|
@ -314,7 +314,7 @@ ModFile::transformPass(bool nostrict)
|
|||
SymbolTable orig_symbol_table = symbol_table;
|
||||
symbol_table.rmExo(unusedExo);
|
||||
dynamic_model.resetDataTree();
|
||||
dynamic_model.reindexEquations(dynamic_model, orig_symbol_table);
|
||||
dynamic_model.reindex(orig_symbol_table);
|
||||
vector<Statement *> orig_statements = statements;
|
||||
statements.clear();
|
||||
for (vector<Statement *>::iterator it = orig_statements.begin(); it != orig_statements.end(); it++)
|
||||
|
|
64
ModelTree.cc
64
ModelTree.cc
|
@ -1413,6 +1413,70 @@ ModelTree::addAuxEquation(expr_t eq)
|
|||
aux_equations.push_back(beq);
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::reindex(SymbolTable &orig_symbol_table)
|
||||
{
|
||||
reindexEquations(orig_symbol_table);
|
||||
reindexTrendSymbolsMap(orig_symbol_table);
|
||||
reindexNonstationarySymbolsMap(orig_symbol_table);
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::reindexEquations(SymbolTable &orig_symbol_table)
|
||||
{
|
||||
map<int, expr_t> orig_local_variables_table = local_variables_table;
|
||||
local_variables_table.clear();
|
||||
for (map<int, expr_t>::const_iterator it = orig_local_variables_table.begin();
|
||||
it != orig_local_variables_table.end(); it++)
|
||||
AddLocalVariable(symbol_table.getID(orig_symbol_table.getName(it->first)),
|
||||
it->second->cloneDynamicReindex(*this, orig_symbol_table));
|
||||
|
||||
vector<BinaryOpNode *>eqbak = equations;
|
||||
equations.clear();
|
||||
for (size_t i = 0; i < eqbak.size(); i++)
|
||||
addEquation(eqbak[i]->cloneDynamicReindex(*this, orig_symbol_table), equations_lineno[i]);
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::reindexTrendSymbolsMap(SymbolTable &orig_symbol_table)
|
||||
{
|
||||
map<int, expr_t> orig_trend_symbols_map = trend_symbols_map;
|
||||
trend_symbols_map.clear();
|
||||
for (map<int, expr_t>::const_iterator it = orig_trend_symbols_map.begin();
|
||||
it != orig_trend_symbols_map.end(); it++)
|
||||
try
|
||||
{
|
||||
vector<int> symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first)));
|
||||
addTrendVariables(symb_id, it->second->cloneDynamicReindex(*this, orig_symbol_table));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
cerr << "Error: unused exo in trend symbols." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table)
|
||||
{
|
||||
nonstationary_symbols_map_t orig_nonstationary_symbols_map = nonstationary_symbols_map;
|
||||
nonstationary_symbols_map.clear();
|
||||
for (nonstationary_symbols_map_t::const_iterator it = orig_nonstationary_symbols_map.begin();
|
||||
it != orig_nonstationary_symbols_map.end(); it++)
|
||||
try
|
||||
{
|
||||
vector<int> symb_id (1, symbol_table.getID(orig_symbol_table.getName(it->first)));
|
||||
addNonstationaryVariables(symb_id,
|
||||
it->second.first,
|
||||
it->second.second->cloneDynamicReindex(*this, orig_symbol_table));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
cerr << "Error: unused exo in nonstationary symbols." << endl;
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
ModelTree::addTrendVariables(vector<int> trend_vars, expr_t growth_factor) throw (TrendException)
|
||||
{
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (C) 2003-2014 Dynare Team
|
||||
* Copyright (C) 2003-2015 Dynare Team
|
||||
*
|
||||
* This file is part of Dynare.
|
||||
*
|
||||
|
@ -303,6 +303,13 @@ public:
|
|||
void addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags);
|
||||
//! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations
|
||||
void addAuxEquation(expr_t eq);
|
||||
void reindex(SymbolTable &orig_symbol_table);
|
||||
//! reindex equations after change in symbol_table
|
||||
void reindexEquations(SymbolTable &orig_symbol_table);
|
||||
//! reindex trend_symbol_map after change in symbol_table
|
||||
void reindexTrendSymbolsMap(SymbolTable &orig_symbol_table);
|
||||
//! reindex nonstationary_symbol_map after change in symbol_table
|
||||
void reindexNonstationarySymbolsMap(SymbolTable &orig_symbol_table);
|
||||
//! Returns the number of equations in the model
|
||||
int equation_number() const;
|
||||
//! Adds a trend variable with its growth factor
|
||||
|
|
Loading…
Reference in New Issue