Commit 29309771 authored by Houtan Bastani's avatar Houtan Bastani
Browse files

preprocessor: store max lead/lag info, write to output

parent 096e9e5d
......@@ -44,6 +44,10 @@ DynamicModel::DynamicModel(SymbolTable &symbol_table_arg,
max_endo_lag(0), max_endo_lead(0),
max_exo_lag(0), max_exo_lead(0),
max_exo_det_lag(0), max_exo_det_lead(0),
max_lag_orig(0), max_lead_orig(0),
max_endo_lag_orig(0), max_endo_lead_orig(0),
max_exo_lag_orig(0), max_exo_lead_orig(0),
max_exo_det_lag_orig(0), max_exo_det_lead_orig(0),
dynJacobianColsNbr(0),
global_temporary_terms(true)
{
......@@ -2563,7 +2567,15 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
outstruct = "oo_.";
}
output << modstruct << "lead_lag_incidence = [";
output << modstruct << "max_endo_lag_orig = " << max_endo_lag_orig << ";" << endl
<< modstruct << "max_endo_lead_orig = " << max_endo_lead_orig << ";" << endl
<< modstruct << "max_exo_lag_orig = " << max_exo_lag_orig << ";" << endl
<< modstruct << "max_exo_lead_orig = " << max_exo_lead_orig << ";" << endl
<< modstruct << "max_exo_det_lag_orig = " << max_exo_det_lag_orig << ";" << endl
<< modstruct << "max_exo_det_lead_orig = " << max_exo_det_lead_orig << ";" << endl
<< modstruct << "max_lag_orig = " << max_lag_orig << ";" << endl
<< modstruct << "max_lead_orig = " << max_lead_orig << ";" << endl
<< modstruct << "lead_lag_incidence = [";
// Loop on endogenous variables
int nstatic = 0,
nfwrd = 0,
......@@ -3740,6 +3752,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
for (size_t i = 0; i < static_only_equations.size(); i++)
dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model),
static_only_equations_lineno[i]);
dynamic_model.setLeadsLagsOrig();
}
void
......@@ -3912,6 +3926,55 @@ DynamicModel::findUnusedExogenous()
return unusedExo;
}
void
DynamicModel::setLeadsLagsOrig()
{
set<pair<int, int> > dynvars;
for (int i = 0; i < (int) equations.size(); i++)
{
equations[i]->collectDynamicVariables(eEndogenous, dynvars);
equations[i]->collectDynamicVariables(eExogenous, dynvars);
equations[i]->collectDynamicVariables(eExogenousDet, dynvars);
}
for (set<pair<int, int> >::const_iterator it = dynvars.begin();
it != dynvars.end(); it++)
{
int lag = it->second;
SymbolType type = symbol_table.getType(it->first);
if (max_lead_orig < lag)
max_lead_orig= lag;
else if (-max_lag_orig > lag)
max_lag_orig = -lag;
switch (type)
{
case eEndogenous:
if (max_endo_lead_orig < lag)
max_endo_lead_orig = lag;
else if (-max_endo_lag_orig > lag)
max_endo_lag_orig = -lag;
break;
case eExogenous:
if (max_exo_lead_orig < lag)
max_exo_lead_orig = lag;
else if (-max_exo_lag_orig > lag)
max_exo_lag_orig = -lag;
break;
case eExogenousDet:
if (max_exo_det_lead_orig < lag)
max_exo_det_lead_orig = lag;
else if (-max_exo_det_lag_orig > lag)
max_exo_det_lag_orig = -lag;
break;
default:
break;
}
}
}
void
DynamicModel::computeDerivIDs()
{
......
......@@ -61,6 +61,14 @@ private:
//! Maximum lag and lead over deterministic exogenous variables (positive values)
/*! Set by computeDerivIDs() */
int max_exo_det_lag, max_exo_det_lead;
//! Maximum lag and lead over all types of variables (positive values) of original model
int max_lag_orig, max_lead_orig;
//! Maximum lag and lead over endogenous variables (positive values) of original model
int max_endo_lag_orig, max_endo_lead_orig;
//! Maximum lag and lead over exogenous variables (positive values) of original model
int max_exo_lag_orig, max_exo_lead_orig;
//! Maximum lag and lead over deterministic exogenous variables (positive values) of original model
int max_exo_det_lag_orig, max_exo_det_lead_orig;
//! Cross reference information
map<int, ExprNode::EquationInfo> xrefs;
......@@ -277,6 +285,9 @@ public:
//! Find exogenous variables not used in model
set<int> findUnusedExogenous();
//! Set the max leads/lags of the original model
void setLeadsLagsOrig();
//! Copies a dynamic model (only the equations)
/*! It assumes that the dynamic model given in argument has just been allocated */
void cloneDynamic(DynamicModel &dynamic_model) const;
......
......@@ -335,6 +335,7 @@ void
ModFile::transformPass(bool nostrict, bool compute_xrefs)
{
// Save the original model (must be done before any model transformations by preprocessor)
dynamic_model.setLeadsLagsOrig();
dynamic_model.cloneDynamic(original_model);
if (nostrict)
......
Supports Markdown
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