Commit 4005d25f authored by sebastien's avatar sebastien
Browse files

trunk preprocessor:

* reorganized symbol table so that internally symbols have a unique integer ID (as a result, sparse code is temporarily in a broken state)
* rewritten from scratch ModFile::evalAllExpressions()
* {load,save}_params_and_steady_state moved to NumericalInitialization.{cc,hh}
* fixed bug related to endval block


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2441 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 7107df44
......@@ -125,7 +125,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
first_count_equ = *count_Equ;
tmp_var = (int*)malloc(size * sizeof(int));
tmp_endo = (int*)malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
tmp_other_endo = (int*)malloc(symbol_table.endo_nbr * sizeof(int));
tmp_other_endo = (int*)malloc(symbol_table.endo_nbr() * sizeof(int));
tmp_size = (int*)malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
//cout << "tmp_size = (int*)malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1= " << incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1 << ") * sizeof(int))\n";
tmp_size_other_endo = (int*)malloc((incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1) * sizeof(int));
......@@ -134,13 +134,13 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
memset(tmp_size_other_endo, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
memset(tmp_size, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
memset(tmp_endo, 0, (incidencematrix.Model_Max_Lead + incidencematrix.Model_Max_Lag + 1)*sizeof(int));
memset(tmp_other_endo, 0, symbol_table.endo_nbr*sizeof(int));
memset(tmp_other_endo, 0, symbol_table.endo_nbr()*sizeof(int));
nb_lead_lag_endo = 0;
Lag_Endo = Lead_Endo = Lag_Other_Endo = Lead_Other_Endo = Lag_Exo = Lead_Exo = 0;
//Variable by variable looking for all leads and lags its occurence in each equation of the block
tmp_variable_evaluated = (bool*)malloc(symbol_table.endo_nbr*sizeof(bool));
memset(tmp_variable_evaluated, 0, symbol_table.endo_nbr*sizeof(bool));
tmp_variable_evaluated = (bool*)malloc(symbol_table.endo_nbr()*sizeof(bool));
memset(tmp_variable_evaluated, 0, symbol_table.endo_nbr()*sizeof(bool));
for (i = 0;i < size;i++)
{
ModelBlock->Block_List[count_Block].Temporary_Terms_in_Equation[i]=new temporary_terms_type ();
......@@ -158,7 +158,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
{
for (j = 0;j < size;j++)
{
if (Cur_IM[i_1 + Index_Equ_IM[first_count_equ + j].index*symbol_table.endo_nbr])
if (Cur_IM[i_1 + Index_Equ_IM[first_count_equ + j].index*symbol_table.endo_nbr()])
{
tmp_variable_evaluated[i_1] = true;
tmp_size[incidencematrix.Model_Max_Lag_Endo + k]++;
......@@ -177,7 +177,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
{
for (j = 0;j < size;j++)
{
if (Cur_IM[i_1 + Index_Equ_IM[first_count_equ + j].index*symbol_table.endo_nbr])
if (Cur_IM[i_1 + Index_Equ_IM[first_count_equ + j].index*symbol_table.endo_nbr()])
{
tmp_variable_evaluated[i_1] = true;
tmp_size[incidencematrix.Model_Max_Lag_Endo + k]++;
......@@ -208,8 +208,8 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
Cur_IM = incidencematrix.Get_IM(k, eEndogenous);
if (Cur_IM)
{
i_1 = Index_Equ_IM[first_count_equ+i].index * symbol_table.endo_nbr;
for (j = 0;j < symbol_table.endo_nbr;j++)
i_1 = Index_Equ_IM[first_count_equ+i].index * symbol_table.endo_nbr();
for (j = 0;j < symbol_table.endo_nbr();j++)
if (Cur_IM[i_1 + j])
{
if (!tmp_variable_evaluated[j])
......@@ -234,8 +234,8 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
ModelBlock->Block_List[count_Block].Other_Endogenous = (int*)malloc(tmp_nb_other_endo * sizeof(int));
tmp_exo = (int*)malloc(symbol_table.exo_nbr * sizeof(int));
memset(tmp_exo, 0, symbol_table.exo_nbr * sizeof(int));
tmp_exo = (int*)malloc(symbol_table.exo_nbr() * sizeof(int));
memset(tmp_exo, 0, symbol_table.exo_nbr() * sizeof(int));
tmp_nb_exo = 0;
for (i = 0;i < size;i++)
{
......@@ -244,8 +244,8 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
Cur_IM = incidencematrix.Get_IM(k, eExogenous);
if (Cur_IM)
{
i_1 = Index_Equ_IM[first_count_equ+i].index * symbol_table.exo_nbr;
for (j=0;j<symbol_table.exo_nbr;j++)
i_1 = Index_Equ_IM[first_count_equ+i].index * symbol_table.exo_nbr();
for (j=0;j<symbol_table.exo_nbr();j++)
if (Cur_IM[i_1 + j])
{
if (!tmp_exo[j])
......@@ -271,7 +271,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
ModelBlock->Block_List[count_Block].nb_exo = tmp_nb_exo;
ModelBlock->Block_List[count_Block].Exogenous = (int*)malloc(tmp_nb_exo * sizeof(int));
k = 0;
for (j=0;j<symbol_table.exo_nbr;j++)
for (j=0;j<symbol_table.exo_nbr();j++)
if (tmp_exo[j])
{
ModelBlock->Block_List[count_Block].Exogenous[k] = j;
......@@ -325,7 +325,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
else
ModelBlock->Block_List[count_Block].IM_lead_lag[i].size_exo = 0;
ModelBlock->Block_List[count_Block].IM_lead_lag[i].u_init = l;
memset(tmp_variable_evaluated, 0, symbol_table.endo_nbr*sizeof(bool));
memset(tmp_variable_evaluated, 0, symbol_table.endo_nbr()*sizeof(bool));
IM = incidencematrix.Get_IM(i - Lag, eEndogenous);
if (IM)
{
......@@ -334,7 +334,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
i_1 = Index_Var_IM[j].index;
m = 0;
for (k = first_count_equ;k < size + first_count_equ;k++)
if (IM[i_1 + Index_Equ_IM[k].index*symbol_table.endo_nbr])
if (IM[i_1 + Index_Equ_IM[k].index*symbol_table.endo_nbr()])
m++;
if (m > 0)
{
......@@ -345,7 +345,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
m = 0;
for (j = first_count_equ;j < size + first_count_equ;j++)
{
i_1 = Index_Equ_IM[j].index * symbol_table.endo_nbr;
i_1 = Index_Equ_IM[j].index * symbol_table.endo_nbr();
for (k = first_count_equ;k < size + first_count_equ;k++)
if (IM[Index_Var_IM[k].index + i_1])
{
......@@ -369,8 +369,8 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
m = 0;
for (j = first_count_equ;j < size + first_count_equ;j++)
{
i_1 = Index_Equ_IM[j].index * symbol_table.endo_nbr;
for (k = 0;k < symbol_table.endo_nbr;k++)
i_1 = Index_Equ_IM[j].index * symbol_table.endo_nbr();
for (k = 0;k < symbol_table.endo_nbr();k++)
if ((!tmp_variable_evaluated[Index_Var_IM[k].index]) && IM[Index_Var_IM[k].index + i_1])
{
ModelBlock->Block_List[count_Block].IM_lead_lag[i].u_other_endo[m] = l;
......@@ -390,7 +390,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int count_Block, Block
m = 0;
for (j = first_count_equ;j < size + first_count_equ;j++)
{
i_1 = Index_Equ_IM[j].index * symbol_table.exo_nbr;
i_1 = Index_Equ_IM[j].index * symbol_table.exo_nbr();
for (k = 0; k<tmp_nb_exo; k++)
{
if (IM[ModelBlock->Block_List[count_Block].Exogenous[k]+i_1])
......@@ -505,7 +505,7 @@ BlockTriangular::Reduce_Blocks_and_type_determination(int prologue, int epilogue
{
for (int j = 0;j < Blck_Size;j++)
{
if (Cur_IM[i_1 + Index_Equ_IM[first_count_equ + j].index*symbol_table.endo_nbr])
if (Cur_IM[i_1 + Index_Equ_IM[first_count_equ + j].index*symbol_table.endo_nbr()])
{
if (k > Lead)
Lead = k;
......@@ -709,7 +709,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
free(Equation_gr);
blocks.block_result_to_IM(res, IM, *prologue, symbol_table.endo_nbr, Index_Equ_IM, Index_Var_IM);
blocks.block_result_to_IM(res, IM, *prologue, symbol_table.endo_nbr(), Index_Equ_IM, Index_Var_IM);
t_type Type = Reduce_Blocks_and_type_determination(*prologue, *epilogue, res, equations);
......@@ -773,15 +773,15 @@ BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_
bool* Cur_IM;
int i, k, size;
//First create a static model incidence matrix
size = symbol_table.endo_nbr * symbol_table.endo_nbr * sizeof(*SIM);
size = symbol_table.endo_nbr() * symbol_table.endo_nbr() * sizeof(*SIM);
SIM = (bool*)malloc(size);
for (i = 0; i< symbol_table.endo_nbr * symbol_table.endo_nbr; i++) SIM[i] = 0;
for (i = 0; i< symbol_table.endo_nbr() * symbol_table.endo_nbr(); i++) SIM[i] = 0;
for (k = -incidencematrix.Model_Max_Lag_Endo; k<=incidencematrix.Model_Max_Lead_Endo; k++)
{
Cur_IM = incidencematrix.Get_IM(k, eEndogenous);
if (Cur_IM)
{
for (i = 0;i < symbol_table.endo_nbr*symbol_table.endo_nbr;i++)
for (i = 0;i < symbol_table.endo_nbr()*symbol_table.endo_nbr();i++)
{
SIM[i] = (SIM[i]) || (Cur_IM[i]);
}
......@@ -792,13 +792,13 @@ BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_
cout << "incidence matrix for the static model (unsorted) \n";
incidencematrix.Print_SIM(SIM, eEndogenous);
}
Index_Equ_IM = (simple*)malloc(symbol_table.endo_nbr * sizeof(*Index_Equ_IM));
for (i = 0;i < symbol_table.endo_nbr;i++)
Index_Equ_IM = (simple*)malloc(symbol_table.endo_nbr() * sizeof(*Index_Equ_IM));
for (i = 0;i < symbol_table.endo_nbr();i++)
{
Index_Equ_IM[i].index = i;
}
Index_Var_IM = (simple*)malloc(symbol_table.endo_nbr * sizeof(*Index_Var_IM));
for (i = 0;i < symbol_table.endo_nbr;i++)
Index_Var_IM = (simple*)malloc(symbol_table.endo_nbr() * sizeof(*Index_Var_IM));
for (i = 0;i < symbol_table.endo_nbr();i++)
{
Index_Var_IM[i].index = i;
}
......@@ -806,10 +806,10 @@ BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_
Free_Block(ModelBlock);
ModelBlock = (Model_Block*)malloc(sizeof(*ModelBlock));
Cur_IM = incidencematrix.Get_IM(0, eEndogenous);
SIM_0 = (bool*)malloc(symbol_table.endo_nbr * symbol_table.endo_nbr * sizeof(*SIM_0));
for (i = 0;i < symbol_table.endo_nbr*symbol_table.endo_nbr;i++)
SIM_0 = (bool*)malloc(symbol_table.endo_nbr() * symbol_table.endo_nbr() * sizeof(*SIM_0));
for (i = 0;i < symbol_table.endo_nbr()*symbol_table.endo_nbr();i++)
SIM_0[i] = Cur_IM[i];
Normalize_and_BlockDecompose(SIM, ModelBlock, symbol_table.endo_nbr, &prologue, &epilogue, Index_Var_IM, Index_Equ_IM, 1, 1, SIM_0, j_m, equations);
Normalize_and_BlockDecompose(SIM, ModelBlock, symbol_table.endo_nbr(), &prologue, &epilogue, Index_Var_IM, Index_Equ_IM, 1, 1, SIM_0, j_m, equations);
free(SIM_0);
free(SIM);
}
......@@ -423,7 +423,7 @@ EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) c
for(it = estim_params_list.begin(); it != estim_params_list.end(); it++)
{
int symb_id = symbol_table.getID(it->name) + 1;
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1;
SymbolType symb_type = symbol_table.getType(it->name);
switch(it->type)
......@@ -444,7 +444,7 @@ EstimatedParamsStatement::writeOutput(ostream &output, const string &basename) c
output << "estim_params_.corrx = [estim_params_.corrx; ";
else if (symb_type == eEndogenous)
output << "estim_params_.corrn = [estim_params_.corrn; ";
output << symb_id << " " << symbol_table.getID(it->name2)+1;
output << symb_id << " " << symbol_table.getTypeSpecificID(it->name2)+1;
break;
}
output << ", ";
......@@ -482,7 +482,7 @@ EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basenam
for(it = estim_params_list.begin(); it != estim_params_list.end(); it++)
{
int symb_id = symbol_table.getID(it->name) + 1;
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1;
SymbolType symb_type = symbol_table.getType(it->name);
if (it->type < 3)
......@@ -513,14 +513,14 @@ EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basenam
{
if (symb_type == eExogenous)
{
output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getID(it->name2)+1 << ");" << endl;
output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ");" << endl;
output << "estim_params_.corrx(tmp1,3) = ";
it->init_val->writeOutput(output);
output << ";" << endl;
}
else if (symb_type == eEndogenous)
{
output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getID(it->name2)+1 << ";" << endl;
output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ";" << endl;
output << "estim_params_.corrn(tmp1,3) = ";
it->init_val->writeOutput(output);
output << ";" << endl;
......@@ -543,7 +543,7 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
for(it = estim_params_list.begin(); it != estim_params_list.end(); it++)
{
int symb_id = symbol_table.getID(it->name) + 1;
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1;
SymbolType symb_type = symbol_table.getType(it->name);
if (it->type < 3)
......@@ -589,7 +589,7 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
{
if (symb_type == eExogenous)
{
output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getID(it->name2)+1 << ");" << endl;
output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << ")) & (estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ");" << endl;
output << "estim_params_.corrx(tmp1,4) = ";
it->low_bound->writeOutput(output);
......@@ -601,7 +601,7 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
}
else if (symb_type == eEndogenous)
{
output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getID(it->name2)+1 << ";" << endl;
output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << ")) & (estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ";" << endl;
output << "estim_params_.corrn(tmp1,4) = ";
it->low_bound->writeOutput(output);
......@@ -678,7 +678,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
const string &weight = it->second.first;
const NodeID expression = it->second.second;
int id = symbol_table.getID(name) + 1;
int id = symbol_table.getTypeSpecificID(name) + 1;
if (symbol_table.getType(name) == eEndogenous)
{
output << "calib_var_index{1} = [calib_var_index{1};" << id << "," << id << "];\n";
......@@ -706,8 +706,8 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
const string &weight = it->second.first;
const NodeID expression = it->second.second;
int id1 = symbol_table.getID(name1) + 1;
int id2 = symbol_table.getID(name2) + 1;
int id1 = symbol_table.getTypeSpecificID(name1) + 1;
int id2 = symbol_table.getTypeSpecificID(name2) + 1;
if (symbol_table.getType(name1) == eEndogenous)
{
output << "calib_var_index{1} = [calib_var_index{1};" << id1 << "," << id2 << "];\n";
......@@ -737,7 +737,7 @@ CalibVarStatement::writeOutput(ostream &output, const string &basename) const
const string &weight = it->second.first;
const NodeID expression = it->second.second;
int id = symbol_table.getID(name) + 1;
int id = symbol_table.getTypeSpecificID(name) + 1;
if (iar > max_iar)
{
......@@ -837,7 +837,7 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
{
const string &name = it->first;
const NodeID value = it->second;
int id = symbol_table.getID(name) + 1;
int id = symbol_table.getTypeSpecificID(name) + 1;
output << "optim_weights_(" << id << "," << id << ") = ";
value->writeOutput(output);
output << ";" << endl;
......@@ -850,8 +850,8 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename) cons
const string &name1 = it->first.first;
const string &name2 = it->first.second;
const NodeID value = it->second;
int id1 = symbol_table.getID(name1) + 1;
int id2 = symbol_table.getID(name2) + 1;
int id1 = symbol_table.getTypeSpecificID(name1) + 1;
int id2 = symbol_table.getTypeSpecificID(name2) + 1;
output << "optim_weights_(" << id1 << "," << id2 << ") = ";
value->writeOutput(output);
output << ";" << endl;
......@@ -889,37 +889,6 @@ DynaTypeStatement::writeOutput(ostream &output, const string &basename) const
<< "',var_list_);" << endl;
}
SaveParamsAndSteadyStateStatement::SaveParamsAndSteadyStateStatement(const string &filename_arg) :
filename(filename_arg)
{
}
void
SaveParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const
{
output << "save_params_and_steady_state('" << filename << "');" << endl;
}
LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const string &filename_arg) :
filename(filename_arg)
{
}
void
LoadParamsAndSteadyStateStatement::checkPass(ModFileStructure &mod_file_struct)
{
mod_file_struct.load_params_and_steady_state_present = true;
mod_file_struct.load_params_and_steady_state_filename = filename;
}
void
LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename) const
{
output << "load_params_and_steady_state('" << filename << "');" << endl;
}
ModelComparisonStatement::ModelComparisonStatement(const filename_list_type &filename_list_arg,
const OptionsList &options_list_arg) :
filename_list(filename_list_arg),
......
......@@ -60,13 +60,12 @@ NodeID
DataTree::AddVariable(const string &name, int lag)
{
int symb_id = symbol_table.getID(name);
SymbolType type = symbol_table.getType(name);
variable_node_map_type::iterator it = variable_node_map.find(make_pair(make_pair(symb_id, type), lag));
variable_node_map_type::iterator it = variable_node_map.find(make_pair(symb_id, lag));
if (it != variable_node_map.end())
return it->second;
else
return new VariableNode(*this, symb_id, type, lag);
return new VariableNode(*this, symb_id, lag);
}
NodeID
......@@ -423,3 +422,22 @@ DataTree::AddUnknownFunction(const string &function_name, const vector<NodeID> &
return new UnknownFunctionNode(*this, id, arguments);
}
void
DataTree::fillEvalContext(eval_context_type &eval_context) const
{
for(map<int, NodeID>::const_iterator it = local_variables_table.begin();
it != local_variables_table.end(); it++)
{
try
{
const NodeID expression = it->second;
double val = expression->eval(eval_context);
eval_context[it->first] = val;
}
catch(ExprNode::EvalException &e)
{
// Do nothing
}
}
}
......@@ -170,20 +170,20 @@ NumConstNode::collectExogenous(set<pair<int, int> > &result) const
}
VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, SymbolType type_arg, int lag_arg) :
VariableNode::VariableNode(DataTree &datatree_arg, int symb_id_arg, int lag_arg) :
ExprNode(datatree_arg),
symb_id(symb_id_arg),
type(type_arg),
type(datatree.symbol_table.getType(symb_id_arg)),
lag(lag_arg)
{
// Add myself to the variable map
datatree.variable_node_map[make_pair(make_pair(symb_id, type), lag)] = this;
datatree.variable_node_map[make_pair(symb_id, lag)] = this;
// Add myself to the variable table if necessary and initialize var_id
if (type == eEndogenous
|| type == eExogenousDet
|| type == eExogenous)
var_id = datatree.variable_table.addVariable(type, symb_id, lag);
var_id = datatree.variable_table.addVariable(symb_id, lag);
else
var_id = -1;
......@@ -277,13 +277,14 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
}
int i;
int tsid = datatree.symbol_table.getTypeSpecificID(symb_id);
switch(type)
{
case eParameter:
if (output_type == oMatlabOutsideModel)
output << "M_.params" << "(" << symb_id + 1 << ")";
output << "M_.params" << "(" << tsid + 1 << ")";
else
output << "params" << LPAR(output_type) << symb_id + OFFSET(output_type) << RPAR(output_type);
output << "params" << LPAR(output_type) << tsid + OFFSET(output_type) << RPAR(output_type);
break;
case eModelLocalVariable:
......@@ -295,7 +296,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
output << ")";
}
else
output << datatree.symbol_table.getNameByID(type, symb_id);
output << datatree.symbol_table.getName(symb_id);
break;
case eEndogenous:
......@@ -309,19 +310,19 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
case oMatlabStaticModel:
case oMatlabStaticModelSparse:
case oCStaticModel:
i = symb_id + OFFSET(output_type);
i = tsid + OFFSET(output_type);
output << "y" << LPAR(output_type) << i << RPAR(output_type);
break;
case oCDynamicModelSparseDLL:
if (lag > 0)
output << "y" << LPAR(output_type) << "(it_+" << lag << ")*y_size+" << symb_id << RPAR(output_type);
output << "y" << LPAR(output_type) << "(it_+" << lag << ")*y_size+" << tsid << RPAR(output_type);
else if (lag < 0)
output << "y" << LPAR(output_type) << "(it_" << lag << ")*y_size+" << symb_id << RPAR(output_type);
output << "y" << LPAR(output_type) << "(it_" << lag << ")*y_size+" << tsid << RPAR(output_type);
else
output << "y" << LPAR(output_type) << "Per_y_+" << symb_id << RPAR(output_type);
output << "y" << LPAR(output_type) << "Per_y_+" << tsid << RPAR(output_type);
break;
case oMatlabDynamicModelSparse:
i = symb_id + OFFSET(output_type);
i = tsid + OFFSET(output_type);
if (lag > 0)
output << "y" << LPAR(output_type) << "it_+" << lag << ", " << i << RPAR(output_type);
else if (lag < 0)
......@@ -330,13 +331,13 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
output << "y" << LPAR(output_type) << "it_, " << i << RPAR(output_type);
break;
case oMatlabOutsideModel:
output << "oo_.steady_state" << "(" << symb_id + 1 << ")";
output << "oo_.steady_state" << "(" << tsid + 1 << ")";
break;
}
break;
case eExogenous:
i = symb_id + OFFSET(output_type);
i = tsid + OFFSET(output_type);
switch(output_type)
{
case oMatlabDynamicModel:
......@@ -374,7 +375,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
break;
case eExogenousDet:
i = symb_id + datatree.symbol_table.exo_nbr + OFFSET(output_type);
i = tsid + datatree.symbol_table.exo_nbr() + OFFSET(output_type);
switch(output_type)
{
case oMatlabDynamicModel:
......@@ -406,7 +407,7 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
cerr << "VariableNode::writeOutput: lag != 0 for exogenous determistic variable outside model scope!" << endl;
exit(EXIT_FAILURE);
}
output << "oo_.exo_det_steady_state" << "(" << symb_id + 1 << ")";
output << "oo_.exo_det_steady_state" << "(" << tsid + 1 << ")";
break;
}
break;
......@@ -420,11 +421,9 @@ VariableNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
double
VariableNode::eval(const eval_context_type &eval_context) const throw (EvalException)
{
eval_context_type::const_iterator it = eval_context.find(make_pair(symb_id, type));
eval_context_type::const_iterator it = eval_context.find(symb_id);
if (it == eval_context.end())
{
throw EvalException();
}
throw EvalException();
return it->second;
}
......@@ -464,7 +463,7 @@ VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
break;
case eExogenousDet:
i = symb_id + datatree.symbol_table.exo_nbr + OFFSET(output_type);
i = symb_id + datatree.symbol_table.exo_nbr() + OFFSET(output_type);
CompileCode.write(reinterpret_cast<char *>(&i), sizeof(i));
lagl=lag;
CompileCode.write(reinterpret_cast<char *>(&lagl), sizeof(lagl));
......@@ -1726,7 +1725,7 @@ UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
void UnknownFunctionNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_type &temporary_terms) const
{
output << datatree.symbol_table.getNameByID(eUnknownFunction, symb_id) << "(";
output << datatree.symbol_table.getName(symb_id) << "(";
for(vector<NodeID>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
{
......
/*
* Copyright (C) 2007-2008 Dynare Team
* Copyright (C) 2007-2009 Dynare Team
*
* This file is part of Dynare.
*
......@@ -38,9 +38,9 @@ IncidenceMatrix::Build_IM(int lead_lag, SymbolType type)
bool *IM;
if(type==eEndogenous)
{
size = symbol_table.endo_nbr * symbol_table.endo_nbr * sizeof(IM[0]);
size = symbol_table.endo_nbr() * symbol_table.endo_nbr() * sizeof(IM[0]);
List_IM[lead_lag] = IM = (bool*)malloc(size);
for(int i = 0; i< symbol_table.endo_nbr * symbol_table.endo_nbr; i++) IM[i] = 0;
for(int i = 0; i< symbol_table.endo_nbr() * symbol_table.endo_nbr(); i++) IM[i] = 0;
if(lead_lag > 0)
{
if(lead_lag > Model_Max_Lead_Endo)
......@@ -62,9 +62,9 @@ IncidenceMatrix::Build_IM(int lead_lag, SymbolType type)
}
else
{ //eExogenous
size = symbol_table.endo_nbr * symbol_table.exo_nbr * sizeof(IM[0]);
size = symbol_table.endo_nbr() * symbol_table.exo_nbr() * sizeof(IM[0]);
List_IM_X[lead_lag] = IM = (bool*)malloc(size);
for(int i = 0; i< symbol_table.endo_nbr * symbol_table.exo_nbr; i++) IM[i] = 0;
for(int i = 0; i< symbol_table.endo_nbr() * symbol_table.exo_nbr(); i++) IM[i] = 0;
if(lead_lag > 0)
{
if(lead_lag > Model_Max_Lead_Exo)
......@@ -130,17 +130,17 @@ IncidenceMatrix::fill_IM(int equation, int variable, int lead_lag, SymbolType ty
{
bool* Cur_IM;
Cur_IM = Get_IM(lead_lag, type);
if(equation >= symbol_table.endo_nbr)
if(equation >= symbol_table.endo_nbr())
{
cout << "Error : The model has more equations (at least " << equation + 1 << ") than declared endogenous variables (" << symbol_table.endo_nbr << ")\n";
cout << "Error : The model has more equations (at least " << equation + 1 << ") than declared endogenous variables (" << symbol_table.endo_nbr() << ")\n";
exit(EXIT_FAILURE);
}
if (!Cur_IM)
Cur_IM = Build_IM(lead_lag, type);
if(type==eEndogenous)
Cur_IM[equation*symbol_table.endo_nbr + variable] = 1;
Cur_IM[equation*symbol_table.endo_nbr() + variable] = 1;
else
Cur_IM[equation*symbol_table.exo_nbr + variable] = 1;
Cur_IM[equation*symbol_table.exo_nbr() + variable] = 1;
}
//------------------------------------------------------------------------------
......@@ -153,9 +153,9 @@ IncidenceMatrix::unfill_IM(int equation, int variable, int lead_lag, SymbolType
if (!Cur_IM)
Cur_IM = Build_IM(lead_lag, type);
if(type==eEndogenous)
Cur_IM[equation*symbol_table.endo_nbr + variable] = 0;
Cur_IM[equation*symbol_table.endo_nbr() + variable] = 0;
else
Cur_IM[equation*symbol_table.exo_nbr + variable] = 0;
Cur_IM[equation*symbol_table.exo_nbr() + variable] = 0;
}