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-bf33cf982152
time-shift
sebastien 2006-12-18 11:29:10 +00:00
parent 927da0e42a
commit 0f9ed33f7d
17 changed files with 162 additions and 312 deletions

View File

@ -17,9 +17,9 @@ using namespace std;
#include "NumericalConstants.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),
variable_table(symbol_table_arg, mod_param_arg),
variable_table(symbol_table_arg),
NoOpCode(-1), NullID(NULL)
{
offset = 1;

View File

@ -38,7 +38,6 @@ COMMON_OBJ=\
ComputingTasks.o\
DynareMain.o\
Expression.o\
ModelParameters.o\
ModelTree.o\
NumericalConstants.o\
NumericalInitialization.o\

View File

@ -1,8 +1,7 @@
#include "ModFile.hh"
#include "Interface.hh"
ModFile::ModFile() : symbol_table(model_parameters),
model_tree(symbol_table, model_parameters, num_constants),
ModFile::ModFile() : model_tree(symbol_table, num_constants),
linear(false)
{
}

View File

@ -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
}

View File

@ -18,7 +18,6 @@ using namespace std;
#include "DynareBison.hh"
#include "NumericalConstants.hh"
#include "ModelTree.hh"
#include "ModelParameters.hh"
#include "Interface.hh"
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,
ModelParameters &mod_param_arg,
const NumericalConstants &num_constants_arg) :
DataTree(symbol_table_arg, mod_param_arg),
mod_param(mod_param_arg),
DataTree(symbol_table_arg),
num_constants(num_constants_arg),
computeJacobian(false),
computeJacobianExo(false),
@ -144,7 +141,7 @@ ModelTree::writeStaticCFile(const string &static_basename)
mStaticModelFile << " if (nlhs >= 1)\n";
mStaticModelFile << " {\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 << " residual = mxGetPr(plhs[0]);\n";
mStaticModelFile << " }\n\n";
@ -152,7 +149,7 @@ ModelTree::writeStaticCFile(const string &static_basename)
mStaticModelFile << " if (nlhs >= 2)\n";
mStaticModelFile << " {\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 << " g1 = mxGetPr(plhs[1]);\n";
mStaticModelFile << " }\n\n";
@ -219,7 +216,7 @@ ModelTree::writeDynamicCFile(const string &dynamic_basename)
mDynamicModelFile << " if (nlhs >= 1)\n";
mDynamicModelFile << " {\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 << " residual = mxGetPr(plhs[0]);\n";
mDynamicModelFile << " }\n\n";
@ -228,9 +225,9 @@ ModelTree::writeDynamicCFile(const string &dynamic_basename)
mDynamicModelFile << " {\n";
mDynamicModelFile << " /* Set the output pointer to the output matrix g1. */\n";
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)
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 << " g1 = mxGetPr(plhs[1]);\n";
mDynamicModelFile << " }\n\n";
@ -238,7 +235,7 @@ ModelTree::writeDynamicCFile(const string &dynamic_basename)
mDynamicModelFile << " if (nlhs >= 3)\n";
mDynamicModelFile << " {\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 << " g2 = mxGetPr(plhs[2]);\n";
mDynamicModelFile << " }\n\n";
@ -524,7 +521,7 @@ void ModelTree::derive(int iOrder)
// Loop on variables of derivation, skipping symmetric elements
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++ )
{
t1 = EqualTokenIDs[i]->getDerivativeAddress(var, *this);
@ -532,10 +529,10 @@ void ModelTree::derive(int iOrder)
mDerivativeIndex[0].push_back(DerivativeIndex(t1, i-starti, var));
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);
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));
}
}
@ -642,9 +639,6 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
ostringstream jacobian_tmp_output;
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
// Not to be printed as a temp expression
fill(ZeroEqZero->reference_count.begin(),
@ -662,7 +656,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
model_output << " = ";
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 << getExpression((*tree_it)->id1, eStaticEquations, lEquationNBR) << ";" << endl;
@ -730,7 +724,7 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
StaticOutput << "global M_ \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 << "Model equations\n\t";
StaticOutput << interfaces::comment() + "\n\n";
@ -740,8 +734,8 @@ ModelTree::writeStaticModel(ostream &StaticOutput)
StaticOutput << "end\n";
StaticOutput << "if nargout >= 2,\n";
StaticOutput << " g1 = " <<
"zeros(" << mod_param.eq_nbr << ", " <<
mod_param.endo_nbr << ");\n" ;
"zeros(" << eq_nbr << ", " <<
symbol_table.endo_nbr << ");\n" ;
StaticOutput << "\n\t"+interfaces::comment()+"\n\t"+interfaces::comment();
StaticOutput << "Jacobian matrix\n\t";
StaticOutput << interfaces::comment() + "\n\n";
@ -815,7 +809,7 @@ ModelTree::writeDynamicModel(ostream &DynamicOutput)
model_output << " = ";
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 << getExpression(((*tree_it)->id1), eDynamicEquations, lEquationNBR) << ";" << endl;
@ -930,10 +924,10 @@ ModelTree::writeDynamicModel(ostream &DynamicOutput)
}
cout << "done \n";
}
int nrows = mod_param.eq_nbr;
int nvars = mod_param.var_endo_nbr;
int nrows = eq_nbr;
int nvars = variable_table.var_endo_nbr;
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)
{
@ -1145,7 +1139,7 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
}
else if (type == eExogenousDet)
{
idx += mod_param.exo_nbr;
idx += symbol_table.exo_nbr;
argument << "x" << lpar << idx << rpar;
}
}
@ -1187,7 +1181,7 @@ inline string ModelTree::getArgument(NodeID id, Type type, EquationType iEquatio
}
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);
if (offset == 1)
{
@ -1232,11 +1226,11 @@ ModelTree::writeOutput(ostream &output) const
*/
output << "M_.lead_lag_incidence = [";
// 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";
// 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
string name = symbol_table.getNameByID(eEndogenous, endoID);
@ -1252,35 +1246,35 @@ ModelTree::writeOutput(ostream &output) const
output << "]';\n";
// Writing initialization for some other variables
output << "M_.exo_names_orig_ord = [1:" << mod_param.exo_nbr << "];\n";
output << "M_.maximum_lag = " << mod_param.max_lag << ";\n";
output << "M_.maximum_lead = " << mod_param.max_lead << ";\n";
if (mod_param.endo_nbr)
output << "M_.exo_names_orig_ord = [1:" << symbol_table.exo_nbr << "];\n";
output << "M_.maximum_lag = " << variable_table.max_lag << ";\n";
output << "M_.maximum_lead = " << variable_table.max_lead << ";\n";
if (symbol_table.endo_nbr)
{
output << "M_.maximum_endo_lag = " << mod_param.max_endo_lag << ";\n";
output << "M_.maximum_endo_lead = " << mod_param.max_endo_lead << ";\n";
output << "oo_.steady_state = zeros(" << mod_param.endo_nbr << ", 1);\n";
output << "M_.maximum_endo_lag = " << variable_table.max_endo_lag << ";\n";
output << "M_.maximum_endo_lead = " << variable_table.max_endo_lead << ";\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_lead = " << mod_param.max_exo_lead << ";\n";
output << "oo_.exo_steady_state = zeros(" << mod_param.exo_nbr << ", 1);\n";
output << "M_.maximum_exo_lag = " << variable_table.max_exo_lag << ";\n";
output << "M_.maximum_exo_lead = " << variable_table.max_exo_lead << ";\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_lead = " << mod_param.max_exo_det_lead << ";\n";
output << "oo_.exo_det_steady_state = zeros(" << mod_param.exo_det_nbr << ", 1);\n";
output << "M_.maximum_exo_det_lag = " << variable_table.max_exo_det_lag << ";\n";
output << "M_.maximum_exo_det_lead = " << variable_table.max_exo_det_lead << ";\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_lead = " << mod_param.max_recur_lead << ";\n";
output << "oo_.recur_steady_state = zeros(" << mod_param.recur_nbr << ", 1);\n";
output << "M_.maximum_recur_lag = " << variable_table.max_recur_lag << ";\n";
output << "M_.maximum_recur_lead = " << variable_table.max_recur_lead << ";\n";
output << "oo_.recur_steady_state = zeros(" << symbol_table.recur_nbr << ", 1);\n";
}
if (mod_param.parameter_nbr)
output << "M_.params = zeros(" << mod_param.parameter_nbr << ", 1);\n";
if (symbol_table.parameter_nbr)
output << "M_.params = zeros(" << symbol_table.parameter_nbr << ", 1);\n";
}
inline int ModelTree::optimize(NodeID node)
@ -1318,7 +1312,7 @@ void
ModelTree::checkPass() const
{
// 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;
exit(-1);
@ -1328,7 +1322,7 @@ ModelTree::checkPass() const
void
ModelTree::computingPass()
{
cout << mod_param.eq_nbr << " equation(s) found \n";
cout << eq_nbr << " equation(s) found \n";
// Sorting variable table
variable_table.Sort();

View File

@ -47,10 +47,8 @@ InitOrEndValStatement::writeInitValues(ostream &output) const
}
InitValStatement::InitValStatement(const init_values_type &init_values_arg,
const SymbolTable &symbol_table_arg,
const ModelParameters &mod_param_arg) :
InitOrEndValStatement(init_values_arg, symbol_table_arg),
mod_param(mod_param_arg)
const SymbolTable &symbol_table_arg) :
InitOrEndValStatement(init_values_arg, symbol_table_arg)
{
}
@ -62,8 +60,8 @@ InitValStatement::writeOutput(ostream &output) const
// Writing initval block to set initial values for variables
output << "options_.initval_file = 0;\nendval_=0;\n";
if (mod_param.recur_nbr > 0)
output << "recurs_ = zeros(" << mod_param.recur_nbr << ", 1);\n";
if (symbol_table.recur_nbr > 0)
output << "recurs_ = zeros(" << symbol_table.recur_nbr << ", 1);\n";
writeInitValues(output);

View File

@ -278,8 +278,7 @@ ParsingDriver::use_dll()
void
ParsingDriver::end_initval()
{
mod_file->addStatement(new InitValStatement(init_values, mod_file->symbol_table,
mod_file->model_parameters));
mod_file->addStatement(new InitValStatement(init_values, mod_file->symbol_table));
init_values.clear();
}
@ -909,7 +908,7 @@ NodeID
ParsingDriver::add_model_equal(NodeID arg1, NodeID arg2)
{
NodeID id = mod_file->model_tree.AddEqual(arg1, arg2);
mod_file->model_parameters.eq_nbr++;
mod_file->model_tree.eq_nbr++;
return id;
}

View File

@ -8,7 +8,6 @@
using namespace std;
//------------------------------------------------------------------------------
#include "Shocks.hh"
#include "ModelParameters.hh"
#include "Interface.hh"
AbstractShocksStatement::AbstractShocksStatement(bool mshocks_arg,

View File

@ -12,17 +12,13 @@
#include "Interface.hh"
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);
tex_name_table.resize(20);
}
SymbolTable::~SymbolTable()
{
// Empty
}
int SymbolTable::AddSymbol(string name,Type type, string tex_name)
{
symboltable[name].type = type;
@ -33,23 +29,23 @@ int SymbolTable::AddSymbol(string name,Type type, string tex_name)
switch (type)
{
case eExogenous:
symboltable[name].id = mod_param.exo_nbr;
return mod_param.exo_nbr++;
symboltable[name].id = exo_nbr;
return exo_nbr++;
case eExogenousDet:
symboltable[name].id = mod_param.exo_det_nbr;
return mod_param.exo_det_nbr++;
symboltable[name].id = exo_det_nbr;
return exo_det_nbr++;
case eEndogenous:
symboltable[name].id = mod_param.endo_nbr;
return mod_param.endo_nbr++;
symboltable[name].id = endo_nbr;
return endo_nbr++;
case eParameter:
symboltable[name].id = mod_param.parameter_nbr;
return mod_param.parameter_nbr++;
symboltable[name].id = parameter_nbr;
return parameter_nbr++;
case eRecursiveVariable:
symboltable[name].id = mod_param.recur_nbr;
return mod_param.recur_nbr++;
symboltable[name].id = recur_nbr;
return recur_nbr++;
case eLocalParameter:
symboltable[name].id = mod_param.local_parameter_nbr;
return mod_param.local_parameter_nbr++;
symboltable[name].id = local_parameter_nbr;
return local_parameter_nbr++;
default:
// should never happen
return -1;
@ -103,151 +99,65 @@ Reference SymbolTable::isReferenced(const std::string &name) const
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
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_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_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_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_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_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_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_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_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_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_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_nbr = " << mod_param.exo_nbr << ";\n";
output << "M_.Sigma_e = zeros(" << mod_param.exo_nbr
<< ", " << mod_param.exo_nbr << ");\n";
output << "M_.endo_nbr = " << mod_param.endo_nbr << ";\n";
output << "M_.recur_nbr = " << mod_param.recur_nbr << ";\n";
output << "M_.param_nbr = " << mod_param.parameter_nbr << ";\n";
output << "M_.exo_det_nbr = " << exo_det_nbr << ";\n";
output << "M_.exo_nbr = " << exo_nbr << ";\n";
output << "M_.Sigma_e = zeros(" << exo_nbr
<< ", " << exo_nbr << ");\n";
output << "M_.endo_nbr = " << endo_nbr << ";\n";
output << "M_.recur_nbr = " << recur_nbr << ";\n";
output << "M_.param_nbr = " << parameter_nbr << ";\n";
}

View File

@ -3,10 +3,14 @@
#include "VariableTable.hh"
VariableTable::VariableTable(const SymbolTable &symbol_table_arg,
ModelParameters &mod_param_arg) :
VariableTable::VariableTable(const SymbolTable &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
Type type = getType(lVariableID);
if (type == eEndogenous)
mod_param.var_endo_nbr++;
var_endo_nbr++;
if (type == eExogenous)
mod_param.var_exo_nbr++;
var_exo_nbr++;
if (type == eExogenousDet)
mod_param.var_exo_det_nbr++;
var_exo_det_nbr++;
// Setting maximum and minimum lags
if (mod_param.max_lead < iLag)
mod_param.max_lead = iLag;
else if (-mod_param.max_lag > iLag)
mod_param.max_lag = -iLag;
if (max_lead < iLag)
max_lead = iLag;
else if (-max_lag > iLag)
max_lag = -iLag;
switch(type)
{
case eEndogenous:
if (mod_param.max_endo_lead < iLag)
mod_param.max_endo_lead = iLag;
else if (-mod_param.max_endo_lag > iLag)
mod_param.max_endo_lag = -iLag;
if (max_endo_lead < iLag)
max_endo_lead = iLag;
else if (-max_endo_lag > iLag)
max_endo_lag = -iLag;
break;
case eExogenous:
if (mod_param.max_exo_lead < iLag)
mod_param.max_exo_lead = iLag;
else if (-mod_param.max_exo_lag > iLag)
mod_param.max_exo_lag = -iLag;
if (max_exo_lead < iLag)
max_exo_lead = iLag;
else if (-max_exo_lag > iLag)
max_exo_lag = -iLag;
break;
case eExogenousDet:
if (mod_param.max_exo_det_lead < iLag)
mod_param.max_exo_det_lead = iLag;
else if (-mod_param.max_exo_det_lag > iLag)
mod_param.max_exo_det_lag = -iLag;
if (max_exo_det_lead < iLag)
max_exo_det_lead = iLag;
else if (-max_exo_det_lag > iLag)
max_exo_det_lag = -iLag;
break;
case eRecursiveVariable:
if (mod_param.max_recur_lead < iLag)
mod_param.max_recur_lead = iLag;
else if (-mod_param.max_recur_lag > iLag)
mod_param.max_recur_lag = -iLag;
if (max_recur_lead < iLag)
max_recur_lead = iLag;
else if (-max_recur_lag > iLag)
max_recur_lag = -iLag;
break;
default:
;

View File

@ -123,7 +123,7 @@ public :
inline NodeID AddAssign(NodeID iArg1, NodeID iArg2);
public :
/*! Constructor */
DataTree(SymbolTable &symbol_table_arg, ModelParameters &mod_param_arg);
DataTree(SymbolTable &symbol_table_arg);
/*! Destructor */
~DataTree();
};

View File

@ -5,7 +5,6 @@ using namespace std;
#include <ostream>
#include "ModelParameters.hh"
#include "SymbolTable.hh"
#include "NumericalConstants.hh"
#include "ModelTree.hh"
@ -18,8 +17,6 @@ class ModFile
public:
ModFile();
~ModFile();
//! Model parameters
ModelParameters model_parameters;
//! Symbol table
SymbolTable symbol_table;
//! Numerical constants table

View File

@ -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

View File

@ -37,8 +37,6 @@ private :
int min_cost;
/*! left and right parentheses can be (,[ or ),] */
char lpar, rpar;
//! Reference to model parameters
ModelParameters &mod_param;
//! Reference to numerical constants table
const NumericalConstants &num_constants;
@ -66,7 +64,9 @@ private :
public:
//! 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
void checkPass() const;
//! Whether Jacobian (vs endogenous) should be written

View File

@ -41,12 +41,9 @@ protected:
class InitValStatement : public InitOrEndValStatement
{
private:
const ModelParameters &mod_param;
public:
InitValStatement(const init_values_type &init_values_arg,
const SymbolTable &symbol_table_arg,
const ModelParameters &mod_param_arg);
const SymbolTable &symbol_table_arg);
virtual void writeOutput(ostream &output) const;
};

View File

@ -11,10 +11,9 @@
#include <string>
#include <vector>
#include <ostream>
//------------------------------------------------------------------------------
#include "ModelParameters.hh"
#include "SymbolTableTypes.hh"
//------------------------------------------------------------------------------
/*!
\class SymbolTable
\brief This class keeps track of symbols
@ -22,8 +21,6 @@
class SymbolTable
{
private:
//! A reference to the model parameters
ModelParameters &mod_param;
/*! Adds symbol into symbol table
\param name a string.
\param type a Type struct.
@ -46,9 +43,19 @@ private:
void ResetType(std::string name, Type new_type);
public :
/*! Constructor */
SymbolTable(ModelParameters &mod_param_arg);
/*! Destructor*/
~SymbolTable();
SymbolTable();
//! Number of declared endogenous variables
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 */
void (* error) (const char* m);
/*! Adds a symbol apearing in declaration
@ -78,10 +85,6 @@ public :
inline int getID(const std::string &name) const;
//! Write output of this class
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

View File

@ -16,8 +16,6 @@ class VariableTable
private:
//! A reference to the symbol table
const SymbolTable &symbol_table;
//! A reference to model parameters
ModelParameters &mod_param;
//! Variable key type to acced variable table elements
typedef pair<string, int> varKey;
//! Maps a pair (symbol, lag) to an ID
@ -34,7 +32,33 @@ private:
*/
vector<int> mPrintFormatIndex;
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
/*! Also works if the variable already exists */
int AddVariable(const string &iName, int iLag);