v4 parser: removed ModelParameters class, and moved its components to the relevant places
git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1125 ac1d8469-bf42-47a9-8791-bf33cf982152time-shift
parent
927da0e42a
commit
0f9ed33f7d
|
@ -17,9 +17,9 @@ using namespace std;
|
||||||
#include "NumericalConstants.hh"
|
#include "NumericalConstants.hh"
|
||||||
#include "DataTree.hh"
|
#include "DataTree.hh"
|
||||||
|
|
||||||
DataTree::DataTree(SymbolTable &symbol_table_arg, ModelParameters &mod_param_arg) :
|
DataTree::DataTree(SymbolTable &symbol_table_arg) :
|
||||||
symbol_table(symbol_table_arg),
|
symbol_table(symbol_table_arg),
|
||||||
variable_table(symbol_table_arg, mod_param_arg),
|
variable_table(symbol_table_arg),
|
||||||
NoOpCode(-1), NullID(NULL)
|
NoOpCode(-1), NullID(NULL)
|
||||||
{
|
{
|
||||||
offset = 1;
|
offset = 1;
|
||||||
|
|
|
@ -38,7 +38,6 @@ COMMON_OBJ=\
|
||||||
ComputingTasks.o\
|
ComputingTasks.o\
|
||||||
DynareMain.o\
|
DynareMain.o\
|
||||||
Expression.o\
|
Expression.o\
|
||||||
ModelParameters.o\
|
|
||||||
ModelTree.o\
|
ModelTree.o\
|
||||||
NumericalConstants.o\
|
NumericalConstants.o\
|
||||||
NumericalInitialization.o\
|
NumericalInitialization.o\
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#include "ModFile.hh"
|
#include "ModFile.hh"
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
|
|
||||||
ModFile::ModFile() : symbol_table(model_parameters),
|
ModFile::ModFile() : model_tree(symbol_table, num_constants),
|
||||||
model_tree(symbol_table, model_parameters, num_constants),
|
|
||||||
linear(false)
|
linear(false)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,22 +0,0 @@
|
||||||
/*! \file
|
|
||||||
\version 1.0
|
|
||||||
\date 04/09/2004
|
|
||||||
\par This file implements the ModelParemeters class methodes.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include "ModelParameters.hh"
|
|
||||||
|
|
||||||
ModelParameters::ModelParameters() : eq_nbr(0),
|
|
||||||
exo_nbr(0), var_exo_nbr(0),
|
|
||||||
exo_det_nbr(0), var_exo_det_nbr(0),
|
|
||||||
endo_nbr(0), var_endo_nbr(0),
|
|
||||||
parameter_nbr(0), local_parameter_nbr(0),
|
|
||||||
recur_nbr(0),
|
|
||||||
max_lag(0), max_lead(0),
|
|
||||||
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_recur_lag(0), max_recur_lead(0)
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
|
@ -18,7 +18,6 @@ using namespace std;
|
||||||
#include "DynareBison.hh"
|
#include "DynareBison.hh"
|
||||||
#include "NumericalConstants.hh"
|
#include "NumericalConstants.hh"
|
||||||
#include "ModelTree.hh"
|
#include "ModelTree.hh"
|
||||||
#include "ModelParameters.hh"
|
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
|
|
||||||
inline NodeID MetaToken::getDerivativeAddress(int iVarID, const ModelTree &model_tree) const
|
inline NodeID MetaToken::getDerivativeAddress(int iVarID, const ModelTree &model_tree) const
|
||||||
|
@ -35,10 +34,8 @@ inline NodeID MetaToken::getDerivativeAddress(int iVarID, const ModelTree &model
|
||||||
}
|
}
|
||||||
|
|
||||||
ModelTree::ModelTree(SymbolTable &symbol_table_arg,
|
ModelTree::ModelTree(SymbolTable &symbol_table_arg,
|
||||||
ModelParameters &mod_param_arg,
|
|
||||||
const NumericalConstants &num_constants_arg) :
|
const NumericalConstants &num_constants_arg) :
|
||||||
DataTree(symbol_table_arg, mod_param_arg),
|
DataTree(symbol_table_arg),
|
||||||
mod_param(mod_param_arg),
|
|
||||||
num_constants(num_constants_arg),
|
num_constants(num_constants_arg),
|
||||||
computeJacobian(false),
|
computeJacobian(false),
|
||||||
computeJacobianExo(false),
|
computeJacobianExo(false),
|
||||||
|
@ -144,7 +141,7 @@ ModelTree::writeStaticCFile(const string &static_basename)
|
||||||
mStaticModelFile << " if (nlhs >= 1)\n";
|
mStaticModelFile << " if (nlhs >= 1)\n";
|
||||||
mStaticModelFile << " {\n";
|
mStaticModelFile << " {\n";
|
||||||
mStaticModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
mStaticModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
||||||
mStaticModelFile << " plhs[0] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ",1, mxREAL);\n";
|
mStaticModelFile << " plhs[0] = mxCreateDoubleMatrix(" << eq_nbr << ",1, mxREAL);\n";
|
||||||
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
||||||
mStaticModelFile << " residual = mxGetPr(plhs[0]);\n";
|
mStaticModelFile << " residual = mxGetPr(plhs[0]);\n";
|
||||||
mStaticModelFile << " }\n\n";
|
mStaticModelFile << " }\n\n";
|
||||||
|
@ -152,7 +149,7 @@ ModelTree::writeStaticCFile(const string &static_basename)
|
||||||
mStaticModelFile << " if (nlhs >= 2)\n";
|
mStaticModelFile << " if (nlhs >= 2)\n";
|
||||||
mStaticModelFile << " {\n";
|
mStaticModelFile << " {\n";
|
||||||
mStaticModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
mStaticModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
||||||
mStaticModelFile << " plhs[1] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << mod_param.endo_nbr << ", mxREAL);\n";
|
mStaticModelFile << " plhs[1] = mxCreateDoubleMatrix(" << eq_nbr << ", " << symbol_table.endo_nbr << ", mxREAL);\n";
|
||||||
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
mStaticModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
||||||
mStaticModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
mStaticModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
||||||
mStaticModelFile << " }\n\n";
|
mStaticModelFile << " }\n\n";
|
||||||
|
@ -219,7 +216,7 @@ ModelTree::writeDynamicCFile(const string &dynamic_basename)
|
||||||
mDynamicModelFile << " if (nlhs >= 1)\n";
|
mDynamicModelFile << " if (nlhs >= 1)\n";
|
||||||
mDynamicModelFile << " {\n";
|
mDynamicModelFile << " {\n";
|
||||||
mDynamicModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
mDynamicModelFile << " /* Set the output pointer to the output matrix residual. */\n";
|
||||||
mDynamicModelFile << " plhs[0] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ",1, mxREAL);\n";
|
mDynamicModelFile << " plhs[0] = mxCreateDoubleMatrix(" << eq_nbr << ",1, mxREAL);\n";
|
||||||
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix residual. */\n";
|
||||||
mDynamicModelFile << " residual = mxGetPr(plhs[0]);\n";
|
mDynamicModelFile << " residual = mxGetPr(plhs[0]);\n";
|
||||||
mDynamicModelFile << " }\n\n";
|
mDynamicModelFile << " }\n\n";
|
||||||
|
@ -228,9 +225,9 @@ ModelTree::writeDynamicCFile(const string &dynamic_basename)
|
||||||
mDynamicModelFile << " {\n";
|
mDynamicModelFile << " {\n";
|
||||||
mDynamicModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
mDynamicModelFile << " /* Set the output pointer to the output matrix g1. */\n";
|
||||||
if (computeJacobianExo)
|
if (computeJacobianExo)
|
||||||
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << variable_table.size() << ", mxREAL);\n";
|
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << eq_nbr << ", " << variable_table.size() << ", mxREAL);\n";
|
||||||
else if (computeJacobian)
|
else if (computeJacobian)
|
||||||
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << mod_param.var_endo_nbr << ", mxREAL);\n";
|
mDynamicModelFile << " plhs[1] = mxCreateDoubleMatrix(" << eq_nbr << ", " << variable_table.var_endo_nbr << ", mxREAL);\n";
|
||||||
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
||||||
mDynamicModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
mDynamicModelFile << " g1 = mxGetPr(plhs[1]);\n";
|
||||||
mDynamicModelFile << " }\n\n";
|
mDynamicModelFile << " }\n\n";
|
||||||
|
@ -238,7 +235,7 @@ ModelTree::writeDynamicCFile(const string &dynamic_basename)
|
||||||
mDynamicModelFile << " if (nlhs >= 3)\n";
|
mDynamicModelFile << " if (nlhs >= 3)\n";
|
||||||
mDynamicModelFile << " {\n";
|
mDynamicModelFile << " {\n";
|
||||||
mDynamicModelFile << " /* Set the output pointer to the output matrix g2. */\n";
|
mDynamicModelFile << " /* Set the output pointer to the output matrix g2. */\n";
|
||||||
mDynamicModelFile << " plhs[2] = mxCreateDoubleMatrix(" << mod_param.eq_nbr << ", " << variable_table.size()*variable_table.size() << ", mxREAL);\n";
|
mDynamicModelFile << " plhs[2] = mxCreateDoubleMatrix(" << eq_nbr << ", " << variable_table.size()*variable_table.size() << ", mxREAL);\n";
|
||||||
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
mDynamicModelFile << " /* Create a C pointer to a copy of the output matrix g1. */\n";
|
||||||
mDynamicModelFile << " g2 = mxGetPr(plhs[2]);\n";
|
mDynamicModelFile << " g2 = mxGetPr(plhs[2]);\n";
|
||||||
mDynamicModelFile << " }\n\n";
|
mDynamicModelFile << " }\n\n";
|
||||||
|
@ -524,7 +521,7 @@ void ModelTree::derive(int iOrder)
|
||||||
// Loop on variables of derivation, skipping symmetric elements
|
// Loop on variables of derivation, skipping symmetric elements
|
||||||
for (int var = 0; var < variable_table.size(); var++)
|
for (int var = 0; var < variable_table.size(); var++)
|
||||||
{
|
{
|
||||||
int starti = var*Order*(Order-1)*mod_param.eq_nbr/2;
|
int starti = var*Order*(Order-1)*eq_nbr/2;
|
||||||
for (unsigned int i = starti; i < EqualTokenIDs.size() ; i++ )
|
for (unsigned int i = starti; i < EqualTokenIDs.size() ; i++ )
|
||||||
{
|
{
|
||||||
t1 = EqualTokenIDs[i]->getDerivativeAddress(var, *this);
|
t1 = EqualTokenIDs[i]->getDerivativeAddress(var, *this);
|
||||||
|
@ -532,10 +529,10 @@ void ModelTree::derive(int iOrder)
|
||||||
mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var));
|
mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var));
|
||||||
else if (Order == 2)
|
else if (Order == 2)
|
||||||
{
|
{
|
||||||
int var1 = variable_table.getSortID(i/mod_param.eq_nbr);
|
int var1 = variable_table.getSortID(i/eq_nbr);
|
||||||
int var2 = variable_table.getSortID(var);
|
int var2 = variable_table.getSortID(var);
|
||||||
mDerivativeIndex[1].push_back(DerivativeIndex(t1,
|
mDerivativeIndex[1].push_back(DerivativeIndex(t1,
|
||||||
i-mod_param.eq_nbr*(i/mod_param.eq_nbr),
|
i-eq_nbr*(i/eq_nbr),
|
||||||
var1*variable_table.size()+var2));
|
var1*variable_table.size()+var2));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -642,9 +639,6 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
|
||||||
ostringstream jacobian_tmp_output;
|
ostringstream jacobian_tmp_output;
|
||||||
|
|
||||||
int d = current_order; // Minimum number of times a temparary expression apears in equations
|
int d = current_order; // Minimum number of times a temparary expression apears in equations
|
||||||
int EquationNBR; // Number of model equations
|
|
||||||
|
|
||||||
EquationNBR = mod_param.eq_nbr;
|
|
||||||
// Reference count of token "0=0" is set to 0
|
// Reference count of token "0=0" is set to 0
|
||||||
// Not to be printed as a temp expression
|
// Not to be printed as a temp expression
|
||||||
fill(ZeroEqZero->reference_count.begin(),
|
fill(ZeroEqZero->reference_count.begin(),
|
||||||
|
@ -662,7 +656,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
|
||||||
model_output << " = ";
|
model_output << " = ";
|
||||||
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
||||||
}
|
}
|
||||||
else if (lEquationNBR < mod_param.eq_nbr)
|
else if (lEquationNBR < eq_nbr)
|
||||||
{
|
{
|
||||||
model_output << "lhs =";
|
model_output << "lhs =";
|
||||||
model_output << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR) << ";" << endl;
|
||||||
|
@ -730,7 +724,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
|
||||||
StaticOutput << "global M_ \n";
|
StaticOutput << "global M_ \n";
|
||||||
StaticOutput << "if M_.param_nbr > 0\n params = M_.params;\nend\n";
|
StaticOutput << "if M_.param_nbr > 0\n params = M_.params;\nend\n";
|
||||||
|
|
||||||
StaticOutput << " residual = zeros( " << mod_param.eq_nbr << ", 1);\n";
|
StaticOutput << " residual = zeros( " << eq_nbr << ", 1);\n";
|
||||||
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
||||||
StaticOutput << "Model equations\n\t";
|
StaticOutput << "Model equations\n\t";
|
||||||
StaticOutput << interfaces::comment() + "\n\n";
|
StaticOutput << interfaces::comment() + "\n\n";
|
||||||
|
@ -740,8 +734,8 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
|
||||||
StaticOutput << "end\n";
|
StaticOutput << "end\n";
|
||||||
StaticOutput << "if nargout >= 2,\n";
|
StaticOutput << "if nargout >= 2,\n";
|
||||||
StaticOutput << " g1 = " <<
|
StaticOutput << " g1 = " <<
|
||||||
"zeros(" << mod_param.eq_nbr << ", " <<
|
"zeros(" << eq_nbr << ", " <<
|
||||||
mod_param.endo_nbr << ");\n" ;
|
symbol_table.endo_nbr << ");\n" ;
|
||||||
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
|
||||||
StaticOutput << "Jacobian matrix\n\t";
|
StaticOutput << "Jacobian matrix\n\t";
|
||||||
StaticOutput << interfaces::comment() + "\n\n";
|
StaticOutput << interfaces::comment() + "\n\n";
|
||||||
|
@ -815,7 +809,7 @@ ModelTree::writeDynamicModel(ostream &DynamicOutput)
|
||||||
model_output << " = ";
|
model_output << " = ";
|
||||||
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression((*tree_it)->id2, eStaticEquations, lEquationNBR) << ";" << endl;
|
||||||
}
|
}
|
||||||
else if (lEquationNBR < mod_param.eq_nbr)
|
else if (lEquationNBR < eq_nbr)
|
||||||
{
|
{
|
||||||
model_output << "lhs =";
|
model_output << "lhs =";
|
||||||
model_output << getExpression(((*tree_it)->id1), eDynamicEquations, lEquationNBR) << ";" << endl;
|
model_output << getExpression(((*tree_it)->id1), eDynamicEquations, lEquationNBR) << ";" << endl;
|
||||||
|
@ -930,10 +924,10 @@ ModelTree::writeDynamicModel(ostream &DynamicOutput)
|
||||||
}
|
}
|
||||||
cout << "done \n";
|
cout << "done \n";
|
||||||
}
|
}
|
||||||
int nrows = mod_param.eq_nbr;
|
int nrows = eq_nbr;
|
||||||
int nvars = mod_param.var_endo_nbr;
|
int nvars = variable_table.var_endo_nbr;
|
||||||
if (computeJacobianExo)
|
if (computeJacobianExo)
|
||||||
nvars += mod_param.exo_nbr + mod_param.exo_det_nbr;
|
nvars += symbol_table.exo_nbr + symbol_table.exo_det_nbr;
|
||||||
|
|
||||||
if (offset == 1)
|
if (offset == 1)
|
||||||
{
|
{
|
||||||
|
@ -1145,7 +1139,7 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
}
|
}
|
||||||
else if (type == eExogenousDet)
|
else if (type == eExogenousDet)
|
||||||
{
|
{
|
||||||
idx += mod_param.exo_nbr;
|
idx += symbol_table.exo_nbr;
|
||||||
argument << "x" << lpar << idx << rpar;
|
argument << "x" << lpar << idx << rpar;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1187,7 +1181,7 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
|
||||||
}
|
}
|
||||||
else if (type == eExogenousDet)
|
else if (type == eExogenousDet)
|
||||||
{
|
{
|
||||||
int idx = variable_table.getSymbolID((long int) id) + mod_param.exo_nbr + offset;
|
int idx = variable_table.getSymbolID((long int) id) + symbol_table.exo_nbr + offset;
|
||||||
int lag = variable_table.getLag((long int) id);
|
int lag = variable_table.getLag((long int) id);
|
||||||
if (offset == 1)
|
if (offset == 1)
|
||||||
{
|
{
|
||||||
|
@ -1232,11 +1226,11 @@ ModelTree::writeOutput(ostream &output) const
|
||||||
*/
|
*/
|
||||||
output << "M_.lead_lag_incidence = [";
|
output << "M_.lead_lag_incidence = [";
|
||||||
// Loop on endogenous variables
|
// Loop on endogenous variables
|
||||||
for (int endoID = 0; endoID < mod_param.endo_nbr; endoID++)
|
for (int endoID = 0; endoID < symbol_table.endo_nbr; endoID++)
|
||||||
{
|
{
|
||||||
output << "\n\t";
|
output << "\n\t";
|
||||||
// Loop on periods
|
// Loop on periods
|
||||||
for (int lag = -mod_param.max_endo_lag; lag <= mod_param.max_endo_lead; lag++)
|
for (int lag = -variable_table.max_endo_lag; lag <= variable_table.max_endo_lead; lag++)
|
||||||
{
|
{
|
||||||
// Getting name of symbol
|
// Getting name of symbol
|
||||||
string name = symbol_table.getNameByID(eEndogenous, endoID);
|
string name = symbol_table.getNameByID(eEndogenous, endoID);
|
||||||
|
@ -1252,35 +1246,35 @@ ModelTree::writeOutput(ostream &output) const
|
||||||
output << "]';\n";
|
output << "]';\n";
|
||||||
|
|
||||||
// Writing initialization for some other variables
|
// Writing initialization for some other variables
|
||||||
output << "M_.exo_names_orig_ord = [1:" << mod_param.exo_nbr << "];\n";
|
output << "M_.exo_names_orig_ord = [1:" << symbol_table.exo_nbr << "];\n";
|
||||||
output << "M_.maximum_lag = " << mod_param.max_lag << ";\n";
|
output << "M_.maximum_lag = " << variable_table.max_lag << ";\n";
|
||||||
output << "M_.maximum_lead = " << mod_param.max_lead << ";\n";
|
output << "M_.maximum_lead = " << variable_table.max_lead << ";\n";
|
||||||
if (mod_param.endo_nbr)
|
if (symbol_table.endo_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_endo_lag = " << mod_param.max_endo_lag << ";\n";
|
output << "M_.maximum_endo_lag = " << variable_table.max_endo_lag << ";\n";
|
||||||
output << "M_.maximum_endo_lead = " << mod_param.max_endo_lead << ";\n";
|
output << "M_.maximum_endo_lead = " << variable_table.max_endo_lead << ";\n";
|
||||||
output << "oo_.steady_state = zeros(" << mod_param.endo_nbr << ", 1);\n";
|
output << "oo_.steady_state = zeros(" << symbol_table.endo_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (mod_param.exo_nbr)
|
if (symbol_table.exo_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_exo_lag = " << mod_param.max_exo_lag << ";\n";
|
output << "M_.maximum_exo_lag = " << variable_table.max_exo_lag << ";\n";
|
||||||
output << "M_.maximum_exo_lead = " << mod_param.max_exo_lead << ";\n";
|
output << "M_.maximum_exo_lead = " << variable_table.max_exo_lead << ";\n";
|
||||||
output << "oo_.exo_steady_state = zeros(" << mod_param.exo_nbr << ", 1);\n";
|
output << "oo_.exo_steady_state = zeros(" << symbol_table.exo_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (mod_param.exo_det_nbr)
|
if (symbol_table.exo_det_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_exo_det_lag = " << mod_param.max_exo_det_lag << ";\n";
|
output << "M_.maximum_exo_det_lag = " << variable_table.max_exo_det_lag << ";\n";
|
||||||
output << "M_.maximum_exo_det_lead = " << mod_param.max_exo_det_lead << ";\n";
|
output << "M_.maximum_exo_det_lead = " << variable_table.max_exo_det_lead << ";\n";
|
||||||
output << "oo_.exo_det_steady_state = zeros(" << mod_param.exo_det_nbr << ", 1);\n";
|
output << "oo_.exo_det_steady_state = zeros(" << symbol_table.exo_det_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (mod_param.recur_nbr)
|
if (symbol_table.recur_nbr)
|
||||||
{
|
{
|
||||||
output << "M_.maximum_recur_lag = " << mod_param.max_recur_lag << ";\n";
|
output << "M_.maximum_recur_lag = " << variable_table.max_recur_lag << ";\n";
|
||||||
output << "M_.maximum_recur_lead = " << mod_param.max_recur_lead << ";\n";
|
output << "M_.maximum_recur_lead = " << variable_table.max_recur_lead << ";\n";
|
||||||
output << "oo_.recur_steady_state = zeros(" << mod_param.recur_nbr << ", 1);\n";
|
output << "oo_.recur_steady_state = zeros(" << symbol_table.recur_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
if (mod_param.parameter_nbr)
|
if (symbol_table.parameter_nbr)
|
||||||
output << "M_.params = zeros(" << mod_param.parameter_nbr << ", 1);\n";
|
output << "M_.params = zeros(" << symbol_table.parameter_nbr << ", 1);\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
inline int ModelTree::optimize(NodeID node)
|
inline int ModelTree::optimize(NodeID node)
|
||||||
|
@ -1318,7 +1312,7 @@ void
|
||||||
ModelTree::checkPass() const
|
ModelTree::checkPass() const
|
||||||
{
|
{
|
||||||
// Exit if there is no equation in model file
|
// Exit if there is no equation in model file
|
||||||
if (mod_param.eq_nbr == 0)
|
if (eq_nbr == 0)
|
||||||
{
|
{
|
||||||
cerr << "No equation found in model file" << endl;
|
cerr << "No equation found in model file" << endl;
|
||||||
exit(-1);
|
exit(-1);
|
||||||
|
@ -1328,7 +1322,7 @@ ModelTree::checkPass() const
|
||||||
void
|
void
|
||||||
ModelTree::computingPass()
|
ModelTree::computingPass()
|
||||||
{
|
{
|
||||||
cout << mod_param.eq_nbr << " equation(s) found \n";
|
cout << eq_nbr << " equation(s) found \n";
|
||||||
// Sorting variable table
|
// Sorting variable table
|
||||||
variable_table.Sort();
|
variable_table.Sort();
|
||||||
|
|
||||||
|
|
|
@ -47,10 +47,8 @@ InitOrEndValStatement::writeInitValues(ostream &output) const
|
||||||
}
|
}
|
||||||
|
|
||||||
InitValStatement::InitValStatement(const init_values_type &init_values_arg,
|
InitValStatement::InitValStatement(const init_values_type &init_values_arg,
|
||||||
const SymbolTable &symbol_table_arg,
|
const SymbolTable &symbol_table_arg) :
|
||||||
const ModelParameters &mod_param_arg) :
|
InitOrEndValStatement(init_values_arg, symbol_table_arg)
|
||||||
InitOrEndValStatement(init_values_arg, symbol_table_arg),
|
|
||||||
mod_param(mod_param_arg)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -62,8 +60,8 @@ InitValStatement::writeOutput(ostream &output) const
|
||||||
// Writing initval block to set initial values for variables
|
// Writing initval block to set initial values for variables
|
||||||
output << "options_.initval_file = 0;\nendval_=0;\n";
|
output << "options_.initval_file = 0;\nendval_=0;\n";
|
||||||
|
|
||||||
if (mod_param.recur_nbr > 0)
|
if (symbol_table.recur_nbr > 0)
|
||||||
output << "recurs_ = zeros(" << mod_param.recur_nbr << ", 1);\n";
|
output << "recurs_ = zeros(" << symbol_table.recur_nbr << ", 1);\n";
|
||||||
|
|
||||||
writeInitValues(output);
|
writeInitValues(output);
|
||||||
|
|
||||||
|
|
|
@ -278,8 +278,7 @@ ParsingDriver::use_dll()
|
||||||
void
|
void
|
||||||
ParsingDriver::end_initval()
|
ParsingDriver::end_initval()
|
||||||
{
|
{
|
||||||
mod_file->addStatement(new InitValStatement(init_values, mod_file->symbol_table,
|
mod_file->addStatement(new InitValStatement(init_values, mod_file->symbol_table));
|
||||||
mod_file->model_parameters));
|
|
||||||
init_values.clear();
|
init_values.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -909,7 +908,7 @@ NodeID
|
||||||
ParsingDriver::add_model_equal(NodeID arg1, NodeID arg2)
|
ParsingDriver::add_model_equal(NodeID arg1, NodeID arg2)
|
||||||
{
|
{
|
||||||
NodeID id = mod_file->model_tree.AddEqual(arg1, arg2);
|
NodeID id = mod_file->model_tree.AddEqual(arg1, arg2);
|
||||||
mod_file->model_parameters.eq_nbr++;
|
mod_file->model_tree.eq_nbr++;
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
#include "Shocks.hh"
|
#include "Shocks.hh"
|
||||||
#include "ModelParameters.hh"
|
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
|
|
||||||
AbstractShocksStatement::AbstractShocksStatement(bool mshocks_arg,
|
AbstractShocksStatement::AbstractShocksStatement(bool mshocks_arg,
|
||||||
|
|
|
@ -12,17 +12,13 @@
|
||||||
#include "Interface.hh"
|
#include "Interface.hh"
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
SymbolTable::SymbolTable(ModelParameters &mod_param_arg) : mod_param(mod_param_arg)
|
SymbolTable::SymbolTable() : endo_nbr(0), exo_nbr(0), exo_det_nbr(0), parameter_nbr(0),
|
||||||
|
local_parameter_nbr(0), recur_nbr(0)
|
||||||
{
|
{
|
||||||
name_table.resize(20);
|
name_table.resize(20);
|
||||||
tex_name_table.resize(20);
|
tex_name_table.resize(20);
|
||||||
}
|
}
|
||||||
|
|
||||||
SymbolTable::~SymbolTable()
|
|
||||||
{
|
|
||||||
// Empty
|
|
||||||
}
|
|
||||||
|
|
||||||
int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
||||||
{
|
{
|
||||||
symboltable[name].type = type;
|
symboltable[name].type = type;
|
||||||
|
@ -33,23 +29,23 @@ int SymbolTable::AddSymbol(string name,Type type, string tex_name)
|
||||||
switch (type)
|
switch (type)
|
||||||
{
|
{
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
symboltable[name].id = mod_param.exo_nbr;
|
symboltable[name].id = exo_nbr;
|
||||||
return mod_param.exo_nbr++;
|
return exo_nbr++;
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
symboltable[name].id = mod_param.exo_det_nbr;
|
symboltable[name].id = exo_det_nbr;
|
||||||
return mod_param.exo_det_nbr++;
|
return exo_det_nbr++;
|
||||||
case eEndogenous:
|
case eEndogenous:
|
||||||
symboltable[name].id = mod_param.endo_nbr;
|
symboltable[name].id = endo_nbr;
|
||||||
return mod_param.endo_nbr++;
|
return endo_nbr++;
|
||||||
case eParameter:
|
case eParameter:
|
||||||
symboltable[name].id = mod_param.parameter_nbr;
|
symboltable[name].id = parameter_nbr;
|
||||||
return mod_param.parameter_nbr++;
|
return parameter_nbr++;
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
symboltable[name].id = mod_param.recur_nbr;
|
symboltable[name].id = recur_nbr;
|
||||||
return mod_param.recur_nbr++;
|
return recur_nbr++;
|
||||||
case eLocalParameter:
|
case eLocalParameter:
|
||||||
symboltable[name].id = mod_param.local_parameter_nbr;
|
symboltable[name].id = local_parameter_nbr;
|
||||||
return mod_param.local_parameter_nbr++;
|
return local_parameter_nbr++;
|
||||||
default:
|
default:
|
||||||
// should never happen
|
// should never happen
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -103,151 +99,65 @@ Reference SymbolTable::isReferenced(const std::string &name) const
|
||||||
return iter->second.referenced;
|
return iter->second.referenced;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0 // Commented out on 27/11/2006, SV
|
|
||||||
|
|
||||||
void SymbolTable::clean()
|
|
||||||
{
|
|
||||||
string unused;
|
|
||||||
bool warning = false;
|
|
||||||
vector<Type> types(3);
|
|
||||||
vector<int> nb_type(3);
|
|
||||||
|
|
||||||
types[0] = eEndogenous;
|
|
||||||
types[1] = eExogenous;
|
|
||||||
types[2] = eExogenousDet;
|
|
||||||
|
|
||||||
nb_type[0] = mod_param.endo_nbr;
|
|
||||||
nb_type[1] = mod_param.exo_nbr;
|
|
||||||
nb_type[2] = mod_param.exo_det_nbr;
|
|
||||||
|
|
||||||
// Removing unused variables
|
|
||||||
for (int t = 0; t < 3; t++)
|
|
||||||
{
|
|
||||||
// Checking if all variables are used
|
|
||||||
for (int s1 = 0; s1 < nb_type[t]; s1++)
|
|
||||||
{
|
|
||||||
string name = getNameByID(types[t],s1);
|
|
||||||
string tex_name = getTexNameByID(types[t],s1);
|
|
||||||
if (isReferenced(name) == eNotReferenced)
|
|
||||||
{
|
|
||||||
symboltable.erase(name);
|
|
||||||
vector<string>::iterator it;
|
|
||||||
it = find(name_table[types[t]].begin(), name_table[types[t]].end(), name);
|
|
||||||
name_table[types[t]].erase(it);
|
|
||||||
it = find(tex_name_table[types[t]].begin(), tex_name_table[types[t]].end(), tex_name);
|
|
||||||
tex_name_table[types[t]].erase(it);
|
|
||||||
nb_type[t]--;
|
|
||||||
unused += "fprintf(1,'%-30s";
|
|
||||||
switch(types[t])
|
|
||||||
{
|
|
||||||
case eEndogenous : unused += "Endogenous variable\\n','";break;
|
|
||||||
case eExogenous : unused += "Exogenous variable\\n','";break;
|
|
||||||
case eExogenousDet : unused += "Exogenous deterministic variable\\n','";break;
|
|
||||||
default : ;
|
|
||||||
}
|
|
||||||
unused += name;
|
|
||||||
unused += "');\n";
|
|
||||||
warning = true;
|
|
||||||
for (int s2 = s1; s2 < nb_type[t]; s2++)
|
|
||||||
{
|
|
||||||
name = getNameByID(types[t],s2);
|
|
||||||
// Decrementing symbol table ids in ST
|
|
||||||
symboltable[name].id--;
|
|
||||||
}
|
|
||||||
s1--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
mod_param.endo_nbr = nb_type[0];
|
|
||||||
mod_param.exo_nbr = nb_type[1];
|
|
||||||
mod_param.exo_det_nbr = nb_type[2];
|
|
||||||
/*
|
|
||||||
// Checking if unused parameters
|
|
||||||
for (int s1 = 0; s1 < ModelParameters::parameter_nbr; s1++)
|
|
||||||
{
|
|
||||||
string name = getNameByID(eParameter,s1);
|
|
||||||
if (isReferenced(name) == eNotReferenced)
|
|
||||||
{
|
|
||||||
unused += "fprintf(1,'%-30sParameter\\n','";
|
|
||||||
unused += name;
|
|
||||||
unused += "');\n";
|
|
||||||
|
|
||||||
warning = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
if (warning)
|
|
||||||
{
|
|
||||||
output << "fprintf(1,'Warning : symbol(s) :\\n');\n";
|
|
||||||
output << unused;
|
|
||||||
output << "fprintf(1,'are declared but not used in the model equations. ');\n";
|
|
||||||
output << "reply = input('Continue? [y]\\\\n ','s');\n";
|
|
||||||
output << "if isempty(reply), reply='y'; end;\n";
|
|
||||||
output << "if strcmpi(reply(1),'n'),\n return;\nend\n";
|
|
||||||
}
|
|
||||||
//PrintSymbolTable();
|
|
||||||
}
|
|
||||||
#endif // Comment
|
|
||||||
|
|
||||||
void
|
void
|
||||||
SymbolTable::writeOutput(ostream &output)
|
SymbolTable::writeOutput(ostream &output)
|
||||||
{
|
{
|
||||||
if (mod_param.exo_nbr > 0)
|
if (exo_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.exo_names = '" << getNameByID(eExogenous, 0) << "';\n";
|
output << "M_.exo_names = '" << getNameByID(eExogenous, 0) << "';\n";
|
||||||
output << "M_.exo_names_tex = '" << getTexNameByID(eExogenous, 0) << "';\n";
|
output << "M_.exo_names_tex = '" << getTexNameByID(eExogenous, 0) << "';\n";
|
||||||
for (int id = 1; id < mod_param.exo_nbr; id++)
|
for (int id = 1; id < exo_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.exo_names = " + interfaces::strvcat("M_.exo_names","'"+getNameByID(eExogenous, id)+"'") + ";\n";
|
output << "M_.exo_names = " + interfaces::strvcat("M_.exo_names","'"+getNameByID(eExogenous, id)+"'") + ";\n";
|
||||||
output << "M_.exo_names_tex = " + interfaces::strvcat("M_.exo_names_tex","'"+getTexNameByID(eExogenous, id)+"'") + ";\n";
|
output << "M_.exo_names_tex = " + interfaces::strvcat("M_.exo_names_tex","'"+getTexNameByID(eExogenous, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mod_param.exo_det_nbr > 0)
|
if (exo_det_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "lgxdet_ = '" << getNameByID(eExogenousDet, 0) << "';\n";
|
output << "lgxdet_ = '" << getNameByID(eExogenousDet, 0) << "';\n";
|
||||||
output << "lgxdet_tex_ = '" << getTexNameByID(eExogenousDet, 0) << "';\n";
|
output << "lgxdet_tex_ = '" << getTexNameByID(eExogenousDet, 0) << "';\n";
|
||||||
for (int id = 1; id < mod_param.exo_det_nbr; id++)
|
for (int id = 1; id < exo_det_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "lgxdet_ = " + interfaces::strvcat("lgxdet_","'"+getNameByID(eExogenousDet, id)+"'") + ";\n";
|
output << "lgxdet_ = " + interfaces::strvcat("lgxdet_","'"+getNameByID(eExogenousDet, id)+"'") + ";\n";
|
||||||
output << "lgxdet_tex_ = " + interfaces::strvcat("lgxdet_tex_","'"+getTexNameByID(eExogenousDet, id)+"'") + ";\n";
|
output << "lgxdet_tex_ = " + interfaces::strvcat("lgxdet_tex_","'"+getTexNameByID(eExogenousDet, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mod_param.endo_nbr > 0)
|
if (endo_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.endo_names = '" << getNameByID(eEndogenous, 0) << "';\n";
|
output << "M_.endo_names = '" << getNameByID(eEndogenous, 0) << "';\n";
|
||||||
output << "M_.endo_names_tex = '" << getTexNameByID(eEndogenous, 0) << "';\n";
|
output << "M_.endo_names_tex = '" << getTexNameByID(eEndogenous, 0) << "';\n";
|
||||||
for (int id = 1; id < mod_param.endo_nbr; id++)
|
for (int id = 1; id < endo_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.endo_names = " + interfaces::strvcat("M_.endo_names","'"+getNameByID(eEndogenous, id)+"'") + ";\n";
|
output << "M_.endo_names = " + interfaces::strvcat("M_.endo_names","'"+getNameByID(eEndogenous, id)+"'") + ";\n";
|
||||||
output << "M_.endo_names_tex = " + interfaces::strvcat("M_.endo_names_tex","'"+getTexNameByID(eEndogenous, id)+"'") + ";\n";
|
output << "M_.endo_names_tex = " + interfaces::strvcat("M_.endo_names_tex","'"+getTexNameByID(eEndogenous, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mod_param.recur_nbr > 0)
|
if (recur_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.recur_names = '" << getNameByID(eRecursiveVariable, 0) << "';\n";
|
output << "M_.recur_names = '" << getNameByID(eRecursiveVariable, 0) << "';\n";
|
||||||
output << "M_.recur_names_tex = '" << getTexNameByID(eRecursiveVariable, 0) << "';\n";
|
output << "M_.recur_names_tex = '" << getTexNameByID(eRecursiveVariable, 0) << "';\n";
|
||||||
for (int id = 1; id < mod_param.recur_nbr; id++)
|
for (int id = 1; id < recur_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.recur_names = " + interfaces::strvcat("M_.recur_names","'"+getNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
output << "M_.recur_names = " + interfaces::strvcat("M_.recur_names","'"+getNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
||||||
output << "M_.recur_names_tex = " + interfaces::strvcat("M_.recur_names_tex","'"+getTexNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
output << "M_.recur_names_tex = " + interfaces::strvcat("M_.recur_names_tex","'"+getTexNameByID(eRecursiveVariable, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mod_param.parameter_nbr > 0)
|
if (parameter_nbr > 0)
|
||||||
{
|
{
|
||||||
output << "M_.param_names = '" << getNameByID(eParameter, 0) << "';\n";
|
output << "M_.param_names = '" << getNameByID(eParameter, 0) << "';\n";
|
||||||
output << "M_.param_names_tex = '" << getTexNameByID(eParameter, 0) << "';\n";
|
output << "M_.param_names_tex = '" << getTexNameByID(eParameter, 0) << "';\n";
|
||||||
for (int id = 1; id < mod_param.parameter_nbr; id++)
|
for (int id = 1; id < parameter_nbr; id++)
|
||||||
{
|
{
|
||||||
output << "M_.param_names = " + interfaces::strvcat("M_.param_names","'"+getNameByID(eParameter, id)+"'") + ";\n";
|
output << "M_.param_names = " + interfaces::strvcat("M_.param_names","'"+getNameByID(eParameter, id)+"'") + ";\n";
|
||||||
output << "M_.param_names_tex = " + interfaces::strvcat("M_.param_names_tex","'"+getTexNameByID(eParameter, id)+"'") + ";\n";
|
output << "M_.param_names_tex = " + interfaces::strvcat("M_.param_names_tex","'"+getTexNameByID(eParameter, id)+"'") + ";\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
output << "M_.exo_det_nbr = " << mod_param.exo_det_nbr << ";\n";
|
output << "M_.exo_det_nbr = " << exo_det_nbr << ";\n";
|
||||||
output << "M_.exo_nbr = " << mod_param.exo_nbr << ";\n";
|
output << "M_.exo_nbr = " << exo_nbr << ";\n";
|
||||||
output << "M_.Sigma_e = zeros(" << mod_param.exo_nbr
|
output << "M_.Sigma_e = zeros(" << exo_nbr
|
||||||
<< ", " << mod_param.exo_nbr << ");\n";
|
<< ", " << exo_nbr << ");\n";
|
||||||
output << "M_.endo_nbr = " << mod_param.endo_nbr << ";\n";
|
output << "M_.endo_nbr = " << endo_nbr << ";\n";
|
||||||
output << "M_.recur_nbr = " << mod_param.recur_nbr << ";\n";
|
output << "M_.recur_nbr = " << recur_nbr << ";\n";
|
||||||
output << "M_.param_nbr = " << mod_param.parameter_nbr << ";\n";
|
output << "M_.param_nbr = " << parameter_nbr << ";\n";
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,14 @@
|
||||||
|
|
||||||
#include "VariableTable.hh"
|
#include "VariableTable.hh"
|
||||||
|
|
||||||
VariableTable::VariableTable(const SymbolTable &symbol_table_arg,
|
VariableTable::VariableTable(const SymbolTable &symbol_table_arg) :
|
||||||
ModelParameters &mod_param_arg) :
|
|
||||||
symbol_table(symbol_table_arg),
|
symbol_table(symbol_table_arg),
|
||||||
mod_param(mod_param_arg)
|
var_endo_nbr(0), var_exo_nbr(0), var_exo_det_nbr(0),
|
||||||
|
max_lag(0), max_lead(0),
|
||||||
|
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_recur_lag(0), max_recur_lead(0)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,43 +38,43 @@ VariableTable::AddVariable(const string &iName, int iLag)
|
||||||
// Setting dynamic variables numbers
|
// Setting dynamic variables numbers
|
||||||
Type type = getType(lVariableID);
|
Type type = getType(lVariableID);
|
||||||
if (type == eEndogenous)
|
if (type == eEndogenous)
|
||||||
mod_param.var_endo_nbr++;
|
var_endo_nbr++;
|
||||||
if (type == eExogenous)
|
if (type == eExogenous)
|
||||||
mod_param.var_exo_nbr++;
|
var_exo_nbr++;
|
||||||
if (type == eExogenousDet)
|
if (type == eExogenousDet)
|
||||||
mod_param.var_exo_det_nbr++;
|
var_exo_det_nbr++;
|
||||||
|
|
||||||
// Setting maximum and minimum lags
|
// Setting maximum and minimum lags
|
||||||
if (mod_param.max_lead < iLag)
|
if (max_lead < iLag)
|
||||||
mod_param.max_lead = iLag;
|
max_lead = iLag;
|
||||||
else if (-mod_param.max_lag > iLag)
|
else if (-max_lag > iLag)
|
||||||
mod_param.max_lag = -iLag;
|
max_lag = -iLag;
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case eEndogenous:
|
case eEndogenous:
|
||||||
if (mod_param.max_endo_lead < iLag)
|
if (max_endo_lead < iLag)
|
||||||
mod_param.max_endo_lead = iLag;
|
max_endo_lead = iLag;
|
||||||
else if (-mod_param.max_endo_lag > iLag)
|
else if (-max_endo_lag > iLag)
|
||||||
mod_param.max_endo_lag = -iLag;
|
max_endo_lag = -iLag;
|
||||||
break;
|
break;
|
||||||
case eExogenous:
|
case eExogenous:
|
||||||
if (mod_param.max_exo_lead < iLag)
|
if (max_exo_lead < iLag)
|
||||||
mod_param.max_exo_lead = iLag;
|
max_exo_lead = iLag;
|
||||||
else if (-mod_param.max_exo_lag > iLag)
|
else if (-max_exo_lag > iLag)
|
||||||
mod_param.max_exo_lag = -iLag;
|
max_exo_lag = -iLag;
|
||||||
break;
|
break;
|
||||||
case eExogenousDet:
|
case eExogenousDet:
|
||||||
if (mod_param.max_exo_det_lead < iLag)
|
if (max_exo_det_lead < iLag)
|
||||||
mod_param.max_exo_det_lead = iLag;
|
max_exo_det_lead = iLag;
|
||||||
else if (-mod_param.max_exo_det_lag > iLag)
|
else if (-max_exo_det_lag > iLag)
|
||||||
mod_param.max_exo_det_lag = -iLag;
|
max_exo_det_lag = -iLag;
|
||||||
break;
|
break;
|
||||||
case eRecursiveVariable:
|
case eRecursiveVariable:
|
||||||
if (mod_param.max_recur_lead < iLag)
|
if (max_recur_lead < iLag)
|
||||||
mod_param.max_recur_lead = iLag;
|
max_recur_lead = iLag;
|
||||||
else if (-mod_param.max_recur_lag > iLag)
|
else if (-max_recur_lag > iLag)
|
||||||
mod_param.max_recur_lag = -iLag;
|
max_recur_lag = -iLag;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
;
|
;
|
||||||
|
|
|
@ -123,7 +123,7 @@ public :
|
||||||
inline NodeID AddAssign(NodeID iArg1, NodeID iArg2);
|
inline NodeID AddAssign(NodeID iArg1, NodeID iArg2);
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
DataTree(SymbolTable &symbol_table_arg, ModelParameters &mod_param_arg);
|
DataTree(SymbolTable &symbol_table_arg);
|
||||||
/*! Destructor */
|
/*! Destructor */
|
||||||
~DataTree();
|
~DataTree();
|
||||||
};
|
};
|
||||||
|
|
|
@ -5,7 +5,6 @@ using namespace std;
|
||||||
|
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
|
|
||||||
#include "ModelParameters.hh"
|
|
||||||
#include "SymbolTable.hh"
|
#include "SymbolTable.hh"
|
||||||
#include "NumericalConstants.hh"
|
#include "NumericalConstants.hh"
|
||||||
#include "ModelTree.hh"
|
#include "ModelTree.hh"
|
||||||
|
@ -18,8 +17,6 @@ class ModFile
|
||||||
public:
|
public:
|
||||||
ModFile();
|
ModFile();
|
||||||
~ModFile();
|
~ModFile();
|
||||||
//! Model parameters
|
|
||||||
ModelParameters model_parameters;
|
|
||||||
//! Symbol table
|
//! Symbol table
|
||||||
SymbolTable symbol_table;
|
SymbolTable symbol_table;
|
||||||
//! Numerical constants table
|
//! Numerical constants table
|
||||||
|
|
|
@ -1,51 +0,0 @@
|
||||||
#ifndef _MODELPARAMETERS_HH
|
|
||||||
#define _MODELPARAMETERS_HH
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/*! \file
|
|
||||||
\version 1.0
|
|
||||||
\date 04/13/2004
|
|
||||||
\par This file defines the ModelParameters class.
|
|
||||||
*/
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/*!
|
|
||||||
\class ModelParameters
|
|
||||||
\brief Stors model parameters
|
|
||||||
*/
|
|
||||||
class ModelParameters
|
|
||||||
{
|
|
||||||
public :
|
|
||||||
//! Constructor
|
|
||||||
ModelParameters();
|
|
||||||
/*! Number of equations*/
|
|
||||||
int eq_nbr;
|
|
||||||
/*! Number of declared Exogenous variables */
|
|
||||||
int exo_nbr;
|
|
||||||
/*! Number of Exogenous variables that apear in model equations*/
|
|
||||||
int var_exo_nbr;
|
|
||||||
/*! Number of deterministic Exogenous variables */
|
|
||||||
int exo_det_nbr;
|
|
||||||
int var_exo_det_nbr;
|
|
||||||
/*! Number of declared Endogenous variables */
|
|
||||||
int endo_nbr;
|
|
||||||
/*! Number of Endogenous variables that apear in model equations*/
|
|
||||||
int var_endo_nbr;
|
|
||||||
/*! Number of parameters */
|
|
||||||
int parameter_nbr;
|
|
||||||
/*! Number of local parameters */
|
|
||||||
int local_parameter_nbr;
|
|
||||||
/*! Number of recursive variables */
|
|
||||||
int recur_nbr;
|
|
||||||
|
|
||||||
int max_lag;
|
|
||||||
int max_lead;
|
|
||||||
int max_endo_lag;
|
|
||||||
int max_endo_lead;
|
|
||||||
int max_exo_lag;
|
|
||||||
int max_exo_lead;
|
|
||||||
int max_exo_det_lag;
|
|
||||||
int max_exo_det_lead;
|
|
||||||
int max_recur_lag;
|
|
||||||
int max_recur_lead;
|
|
||||||
};
|
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#endif
|
|
|
@ -37,8 +37,6 @@ private :
|
||||||
int min_cost;
|
int min_cost;
|
||||||
/*! left and right parentheses can be (,[ or ),] */
|
/*! left and right parentheses can be (,[ or ),] */
|
||||||
char lpar, rpar;
|
char lpar, rpar;
|
||||||
//! Reference to model parameters
|
|
||||||
ModelParameters &mod_param;
|
|
||||||
//! Reference to numerical constants table
|
//! Reference to numerical constants table
|
||||||
const NumericalConstants &num_constants;
|
const NumericalConstants &num_constants;
|
||||||
|
|
||||||
|
@ -66,7 +64,9 @@ private :
|
||||||
|
|
||||||
public:
|
public:
|
||||||
//! Constructor
|
//! Constructor
|
||||||
ModelTree(SymbolTable &symbol_table_arg, ModelParameters &mod_param_arg, const NumericalConstants &num_constants);
|
ModelTree(SymbolTable &symbol_table_arg, const NumericalConstants &num_constants);
|
||||||
|
//! Number of equations contained in this model tree
|
||||||
|
int eq_nbr;
|
||||||
//! Do some checking
|
//! Do some checking
|
||||||
void checkPass() const;
|
void checkPass() const;
|
||||||
//! Whether Jacobian (vs endogenous) should be written
|
//! Whether Jacobian (vs endogenous) should be written
|
||||||
|
|
|
@ -41,12 +41,9 @@ protected:
|
||||||
|
|
||||||
class InitValStatement : public InitOrEndValStatement
|
class InitValStatement : public InitOrEndValStatement
|
||||||
{
|
{
|
||||||
private:
|
|
||||||
const ModelParameters &mod_param;
|
|
||||||
public:
|
public:
|
||||||
InitValStatement(const init_values_type &init_values_arg,
|
InitValStatement(const init_values_type &init_values_arg,
|
||||||
const SymbolTable &symbol_table_arg,
|
const SymbolTable &symbol_table_arg);
|
||||||
const ModelParameters &mod_param_arg);
|
|
||||||
virtual void writeOutput(ostream &output) const;
|
virtual void writeOutput(ostream &output) const;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -11,10 +11,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <ostream>
|
#include <ostream>
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
#include "ModelParameters.hh"
|
|
||||||
#include "SymbolTableTypes.hh"
|
#include "SymbolTableTypes.hh"
|
||||||
//------------------------------------------------------------------------------
|
|
||||||
/*!
|
/*!
|
||||||
\class SymbolTable
|
\class SymbolTable
|
||||||
\brief This class keeps track of symbols
|
\brief This class keeps track of symbols
|
||||||
|
@ -22,8 +21,6 @@
|
||||||
class SymbolTable
|
class SymbolTable
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
//! A reference to the model parameters
|
|
||||||
ModelParameters &mod_param;
|
|
||||||
/*! Adds symbol into symbol table
|
/*! Adds symbol into symbol table
|
||||||
\param name a string.
|
\param name a string.
|
||||||
\param type a Type struct.
|
\param type a Type struct.
|
||||||
|
@ -46,9 +43,19 @@ private:
|
||||||
void ResetType(std::string name, Type new_type);
|
void ResetType(std::string name, Type new_type);
|
||||||
public :
|
public :
|
||||||
/*! Constructor */
|
/*! Constructor */
|
||||||
SymbolTable(ModelParameters &mod_param_arg);
|
SymbolTable();
|
||||||
/*! Destructor*/
|
//! Number of declared endogenous variables
|
||||||
~SymbolTable();
|
int endo_nbr;
|
||||||
|
//! Number of declared exogenous variables
|
||||||
|
int exo_nbr;
|
||||||
|
//! Number of declared deterministic exogenous variables
|
||||||
|
int exo_det_nbr;
|
||||||
|
//! Number of declared parameters
|
||||||
|
int parameter_nbr;
|
||||||
|
//! Number of declared local parameters
|
||||||
|
int local_parameter_nbr;
|
||||||
|
//! Number of declared recursive variables
|
||||||
|
int recur_nbr;
|
||||||
/*! Pointer to error function of parser class */
|
/*! Pointer to error function of parser class */
|
||||||
void (* error) (const char* m);
|
void (* error) (const char* m);
|
||||||
/*! Adds a symbol apearing in declaration
|
/*! Adds a symbol apearing in declaration
|
||||||
|
@ -78,10 +85,6 @@ public :
|
||||||
inline int getID(const std::string &name) const;
|
inline int getID(const std::string &name) const;
|
||||||
//! Write output of this class
|
//! Write output of this class
|
||||||
void writeOutput(std::ostream &output);
|
void writeOutput(std::ostream &output);
|
||||||
#if 0 // Commented out on 27/11/2006, SV
|
|
||||||
/*! Checks if symbols are used in model equations, removes unused symbol */
|
|
||||||
void clean();
|
|
||||||
#endif // Comment
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline bool SymbolTable::Exist(const std::string &name) const
|
inline bool SymbolTable::Exist(const std::string &name) const
|
||||||
|
|
|
@ -16,8 +16,6 @@ class VariableTable
|
||||||
private:
|
private:
|
||||||
//! A reference to the symbol table
|
//! A reference to the symbol table
|
||||||
const SymbolTable &symbol_table;
|
const SymbolTable &symbol_table;
|
||||||
//! A reference to model parameters
|
|
||||||
ModelParameters &mod_param;
|
|
||||||
//! Variable key type to acced variable table elements
|
//! Variable key type to acced variable table elements
|
||||||
typedef pair<string, int> varKey;
|
typedef pair<string, int> varKey;
|
||||||
//! Maps a pair (symbol, lag) to an ID
|
//! Maps a pair (symbol, lag) to an ID
|
||||||
|
@ -34,7 +32,33 @@ private:
|
||||||
*/
|
*/
|
||||||
vector<int> mPrintFormatIndex;
|
vector<int> mPrintFormatIndex;
|
||||||
public:
|
public:
|
||||||
VariableTable(const SymbolTable &symbol_table_arg, ModelParameters &mod_param_arg);
|
VariableTable(const SymbolTable &symbol_table_arg);
|
||||||
|
//! Number of dynamic endogenous variables inside the model block
|
||||||
|
int var_endo_nbr;
|
||||||
|
//! Number of dynamic exogenous variables inside the model block
|
||||||
|
int var_exo_nbr;
|
||||||
|
//! Number of dynamic deterministic exogenous variables inside the model block
|
||||||
|
int var_exo_det_nbr;
|
||||||
|
//! Maximum lag over all types of variables (positive value)
|
||||||
|
int max_lag;
|
||||||
|
//! Maximum lead over all types of variables
|
||||||
|
int max_lead;
|
||||||
|
//! Maximum lag over endogenous variables (positive value)
|
||||||
|
int max_endo_lag;
|
||||||
|
//! Maximum lead over endogenous variables
|
||||||
|
int max_endo_lead;
|
||||||
|
//! Maximum lag over exogenous variables (positive value)
|
||||||
|
int max_exo_lag;
|
||||||
|
//! Maximum lead over exogenous variables
|
||||||
|
int max_exo_lead;
|
||||||
|
//! Maximum lag over deterministic exogenous variables (positive value)
|
||||||
|
int max_exo_det_lag;
|
||||||
|
//! Maximum lead over deterministic exogenous variables
|
||||||
|
int max_exo_det_lead;
|
||||||
|
//! Maximum lag over recursive variables (positive value)
|
||||||
|
int max_recur_lag;
|
||||||
|
//! Maximum lead over recursive variables
|
||||||
|
int max_recur_lead;
|
||||||
//! Adds a variable in the table, and returns its (newly allocated) varID
|
//! Adds a variable in the table, and returns its (newly allocated) varID
|
||||||
/*! Also works if the variable already exists */
|
/*! Also works if the variable already exists */
|
||||||
int AddVariable(const string &iName, int iLag);
|
int AddVariable(const string &iName, int iLag);
|
||||||
|
|
Loading…
Reference in New Issue