Commit f120c49d authored by sebastien's avatar sebastien
Browse files

v4 preprocessor: removed unused bits of code


git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1811 ac1d8469-bf42-47a9-8791-bf33cf982152
parent e6a060d6
......@@ -42,14 +42,6 @@ BlockTriangular::BlockTriangular(const SymbolTable &symbol_table_arg) :
periods = 0;
}
//------------------------------------------------------------------------------
BlockTriangular::~BlockTriangular()
{
// Empty
}
//------------------------------------------------------------------------------
//For a lead or a lag build the Incidence Matrix structures
List_IM*
......@@ -121,23 +113,6 @@ BlockTriangular::Get_IM(int lead_lag)
return (Cur_IM);
}
bool*
BlockTriangular::bGet_IM(int lead_lag)
{
List_IM* Cur_IM;
Cur_IM = First_IM;
while ((Cur_IM != NULL) && (Cur_IM->lead_lag != lead_lag))
{
Cur_IM = Cur_IM->pNext;
}
if((Cur_IM->lead_lag != lead_lag) || (Cur_IM==NULL))
{
cout << "the incidence matrix with lag " << lead_lag << " does not exist !!";
exit(-1);
}
return (Cur_IM->IM);
}
bool*
BlockTriangular::bGet_IM(int lead_lag) const
{
......@@ -325,64 +300,6 @@ BlockTriangular::Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n
}
void
BlockTriangular::getMax_Lead_Lag(int var, int equ, int *lead, int *lag)
{
List_IM* Cur_IM;
Cur_IM = First_IM->pNext;
(*lead) = (*lag) = 0;
while(Cur_IM)
{
if(Cur_IM->IM[equ*endo_nbr + var])
{
if(Cur_IM->lead_lag > 0)
{
if ((*lead) < Cur_IM->lead_lag)
*lead = Cur_IM->lead_lag;
}
else
{
if ((*lag) < abs(Cur_IM->lead_lag))
*lag = abs(Cur_IM->lead_lag);
}
}
Cur_IM = Cur_IM->pNext;
}
}
void
BlockTriangular::getMax_Lead_Lag_B(int size, int* Equation, int *Variable, int *lead, int *lag)
{
List_IM* Cur_IM;
int i, j;
Cur_IM = First_IM->pNext;
(*lead) = (*lag) = 0;
while(Cur_IM)
{
for(i = 0;i < size;i++)
{
for(j = 0;j < size;j++)
{
if(Cur_IM->IM[Equation[i]*endo_nbr + Variable[j]])
{
if(Cur_IM->lead_lag > 0)
{
if ((*lead) < Cur_IM->lead_lag)
*lead = Cur_IM->lead_lag;
}
else
{
if ((*lag) < abs(Cur_IM->lead_lag))
*lag = abs(Cur_IM->lead_lag);
}
}
}
}
Cur_IM = Cur_IM->pNext;
}
}
void
BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int type, Model_Block * ModelBlock)
{
......@@ -746,12 +663,6 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock)
free(ModelBlock);
}
string
BlockTriangular::getnamebyID(Type type, int id)
{
return symbol_table.getNameByID(type,id);
}
//------------------------------------------------------------------------------
// Normalize each equation of the model (endgenous_i = f_i(endogenous_1, ..., endogenous_n) - in order to apply strong connex components search algorithm -
// and find the optimal blocks triangular decomposition
......@@ -895,249 +806,6 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
return 0;
}
//------------------------------------------------------------------------------
// Normalize each equation of the model (endgenous_i = f_i(endogenous_1, ..., endogenous_n) - in order to apply strong connex components search algorithm -
// and find the optimal blocks triangular decomposition
bool
BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock, int n, int* prologue, int* epilogue, simple* Index_Var_IM, simple* Index_Equ_IM, bool Do_Normalization, bool mixing, bool* IM_0)
{
int i, j, Nb_TotalBlocks, Nb_RecursBlocks;
int count_Block, count_Equ;
block_result_t* res;
List_IM * p_First_IM, *p_Cur_IM, *Cur_IM;
Equation_set* Equation_gr = (Equation_set*) malloc(sizeof(Equation_set));
p_First_IM = (List_IM*)malloc(sizeof(*p_First_IM));
p_Cur_IM = p_First_IM;
Cur_IM = First_IM;
i = endo_nbr * endo_nbr;
while(Cur_IM)
{
p_Cur_IM->lead_lag = Cur_IM->lead_lag;
p_Cur_IM->IM = (bool*)malloc(i * sizeof(bool));
memcpy ( p_Cur_IM->IM, Cur_IM->IM, i);
Cur_IM = Cur_IM->pNext;
if(Cur_IM)
{
p_Cur_IM->pNext = (List_IM*)malloc(sizeof(*p_Cur_IM));
p_Cur_IM = p_Cur_IM->pNext;
}
else
p_Cur_IM->pNext = NULL;
}
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM);
if(bt_verbose)
{
cout << "prologue : " << *prologue << " epilogue : " << *epilogue << "\n";
Print_SIM(IM, n);
for(i = 0;i < n;i++)
cout << "Index_Var_IM[" << i << "]=" << Index_Var_IM[i].index << " Index_Equ_IM[" << i << "]=" << Index_Equ_IM[i].index << "\n";
}
if(Do_Normalization)
{
cout << "Normalizing the model ...\n";
if(mixing)
{
bool* SIM0;
SIM0 = (bool*)malloc(n * n * sizeof(bool));
for(i = 0;i < n*n;i++)
SIM0[i] = IM_0[i];
for(i = 0;i < n;i++)
for(j = 0;j < n;j++)
IM_0[i*n + j] = SIM0[Index_Equ_IM[i].index * n + Index_Var_IM[j].index];
free(SIM0);
normalization.Normalize(n, *prologue, *epilogue, IM_0, Index_Equ_IM, Equation_gr, 1, IM);
}
else
normalization.Normalize(n, *prologue, *epilogue, IM, Index_Equ_IM, Equation_gr, 0, 0);
}
else
normalization.Gr_to_IM_basic(n, *prologue, *epilogue, IM, Equation_gr, false);
cout << "Finding the optimal block decomposition of the model ...\n";
if(bt_verbose)
blocks.Print_Equation_gr(Equation_gr);
res = blocks.sc(Equation_gr);
if(bt_verbose)
blocks.block_result_print(res);
if ((*prologue) || (*epilogue))
j = 1;
else
j = 0;
for(i = 0;i < res->n_sets;i++)
if ((res->sets_f[i] - res->sets_s[i] + 1) > j)
j = res->sets_f[i] - res->sets_s[i] + 1;
Nb_RecursBlocks = *prologue + *epilogue;
Nb_TotalBlocks = res->n_sets + Nb_RecursBlocks;
cout << Nb_TotalBlocks << " block(s) found:\n";
cout << " " << Nb_RecursBlocks << " recursive block(s) and " << res->n_sets << " simultaneous block(s). \n";
cout << " the largest simultaneous block has " << j << " equation(s). \n";
ModelBlock->Size = Nb_TotalBlocks;
ModelBlock->Periods = periods;
ModelBlock->in_Block_Equ = (int*)malloc(n * sizeof(int));
ModelBlock->in_Block_Var = (int*)malloc(n * sizeof(int));
ModelBlock->in_Equ_of_Block = (int*)malloc(n * sizeof(int));
ModelBlock->in_Var_of_Block = (int*)malloc(n * sizeof(int));
ModelBlock->Block_List = (Block*)malloc(sizeof(ModelBlock->Block_List[0]) * Nb_TotalBlocks);
blocks.block_result_to_IM(res, IM, *prologue, endo_nbr, Index_Equ_IM, Index_Var_IM);
Free_IM(p_First_IM);
count_Equ = count_Block = 0;
if (*prologue)
Allocate_Block(*prologue, &count_Equ, &count_Block, PROLOGUE, ModelBlock);
for(j = 0;j < res->n_sets;j++)
{
if(res->sets_f[res->ordered[j]] == res->sets_s[res->ordered[j]])
Allocate_Block(res->sets_f[res->ordered[j]] - res->sets_s[res->ordered[j]] + 1, &count_Equ, &count_Block, PROLOGUE, ModelBlock);
else
Allocate_Block(res->sets_f[res->ordered[j]] - res->sets_s[res->ordered[j]] + 1, &count_Equ, &count_Block, SIMULTANS, ModelBlock);
}
if (*epilogue)
Allocate_Block(*epilogue, &count_Equ, &count_Block, EPILOGUE, ModelBlock);
return 0;
}
//------------------------------------------------------------------------------
// For the contemparenous simultaneities
// normalize each equation of the model
// and find the optimal block triangular decomposition
void
BlockTriangular::Normalize_and_BlockDecompose_0()
{
int i;
List_IM* Cur_IM;
#ifdef DEBUG
cout << "Normalize_and_BlockDecompose_0 \n";
#endif
Index_Equ_IM = (simple*)malloc(endo_nbr * sizeof(*Index_Equ_IM));
for(i = 0;i < endo_nbr;i++)
{
Index_Equ_IM[i].index = i;
Index_Equ_IM[i].available = 1;
}
Index_Var_IM = (simple*)malloc(endo_nbr * sizeof(*Index_Var_IM));
for(i = 0;i < endo_nbr;i++)
{
Index_Var_IM[i].index = i;
Index_Var_IM[i].available = 1;
}
Cur_IM = Get_IM(0);
Normalize_and_BlockDecompose(Cur_IM->IM, ModelBlock, endo_nbr, &prologue, &epilogue, Index_Var_IM, Index_Equ_IM, 1, 0, NULL);
}
//------------------------------------------------------------------------------
// normalize each equation of the statitic model
// and find the optimal block triangular decomposition
void
BlockTriangular::Normalize_and_BlockDecompose_Inside_Earth()
{
bool *SIM, *SIM1;
int i, j, blk, Size, Nb_blk, k, k1, k2, n0, n, k1_block;
int prologue, epilogue;
bool OK;
simple *Index_Equ_IM, *Index_Var_IM;
Model_Block *ModelBlock_Earth;
//First create a the incidence matrix of each stack block
n0 = endo_nbr;
for(blk = 0;blk < ModelBlock->Size;blk++)
{
if(ModelBlock->Block_List[blk].Type == SIMULTANS)
{
Size = (n = ModelBlock->Block_List[blk].Size) * (Nb_blk = (max(ModelBlock->Block_List[blk].Max_Lag, ModelBlock->Block_List[blk].Max_Lead)) + 1);
SIM = (bool*)malloc(Size * Size * sizeof(*SIM));
memset (SIM, 0, Size*Size*sizeof(*SIM));
k1_block = n * n * Nb_blk;
for(k1 = 0;k1 < Nb_blk;k1++)
{
for(k2 = 0;k2 < Nb_blk;k2++)
{
k = k2 - k1;
OK = 1;
if(k < 0)
if( -k > ModelBlock->Block_List[blk].Max_Lag)
OK = 0;
if(k > 0)
if(k > ModelBlock->Block_List[blk].Max_Lead)
OK = 0;
if(OK)
{
SIM1 = Get_IM(k)->IM;
for(i = 0;i < n;i++)
for(j = 0;j < n;j++)
SIM[i*Size + k1*k1_block + j + k2*n] = SIM1[ModelBlock->Block_List[blk].Equation[i] * n0 + ModelBlock->Block_List[blk].Variable[j]];
}
}
}
if(bt_verbose)
cout << "incidence matrix for the static model (unsorted) \n";
Index_Equ_IM = (simple*)malloc(Size * sizeof(*Index_Equ_IM));
for(i = 0;i < Size;i++)
{
Index_Equ_IM[i].index = i;
Index_Equ_IM[i].available = 1;
}
Index_Var_IM = (simple*)malloc(Size * sizeof(*Index_Var_IM));
for(i = 0;i < Size;i++)
{
Index_Var_IM[i].index = i;
Index_Var_IM[i].available = 1;
}
ModelBlock_Earth = (Model_Block*)malloc(sizeof(Model_Block));
Normalize_and_BlockDecompose(SIM, ModelBlock_Earth, Size, &prologue, &epilogue, Index_Var_IM, Index_Equ_IM, 0, 0, NULL);
}
}
}
//------------------------------------------------------------------------------
// normalize each equation of the statitic model
// and find the optimal block triangular decomposition
void
BlockTriangular::Normalize_and_BlockDecompose_Static_Model()
{
bool* SIM;
List_IM* Cur_IM;
int i;
//First create a static model incidence matrix
SIM = (bool*)malloc(endo_nbr * endo_nbr * sizeof(*SIM));
for(i = 0;i < endo_nbr*endo_nbr;i++)
{
SIM[i] = 0;
Cur_IM = First_IM;
while(Cur_IM)
{
SIM[i] = (SIM[i]) || (Cur_IM->IM[i]);
Cur_IM = Cur_IM->pNext;
}
}
if(bt_verbose)
{
cout << "incidence matrix for the static model (unsorted) \n";
Print_SIM(SIM, endo_nbr);
}
Index_Equ_IM = (simple*)malloc(endo_nbr * sizeof(*Index_Equ_IM));
for(i = 0;i < endo_nbr;i++)
{
Index_Equ_IM[i].index = i;
Index_Equ_IM[i].available = 1;
}
Index_Var_IM = (simple*)malloc(endo_nbr * sizeof(*Index_Var_IM));
for(i = 0;i < endo_nbr;i++)
{
Index_Var_IM[i].index = i;
Index_Var_IM[i].available = 1;
}
if(ModelBlock != NULL)
Free_Block(ModelBlock);
ModelBlock = (Model_Block*)malloc(sizeof(*ModelBlock));
Normalize_and_BlockDecompose(SIM, ModelBlock, endo_nbr, &prologue, &epilogue, Index_Var_IM, Index_Equ_IM, 1, 0, NULL);
}
//------------------------------------------------------------------------------
// normalize each equation of the dynamic model
// and find the optimal block triangular decomposition of the static model
......
......@@ -33,11 +33,6 @@ Blocks::Blocks()
//Empty
}
Blocks::~Blocks()
{
//Empty
}
int n_sc_set=0;
void
......@@ -291,44 +286,6 @@ Blocks::block_result_to_IM(block_result_t *r,bool* IM,int prologue, int n,simple
free(SIM);
}
Equation_set*
Blocks::Equation_gr_IM( int n , bool* IM)
{
Equation_set *g;
Equation_vertex *vertices;
Edge *edge_ptr;
int i,j;
g = (Equation_set*)malloc(sizeof(Equation_set));
vertices = g->Number = (Equation_vertex*)malloc(n*sizeof(Equation_vertex));
g->size = n;
for(i = 0; i < n; i++)
{
vertices[i].First_Edge = NULL;
for(j=0; j<n;j++)
{
if (IM[j*n+i])
{
if (vertices[i].First_Edge==NULL)
{
vertices[i].First_Edge=(Edge*)malloc(sizeof(Edge));
edge_ptr=vertices[i].First_Edge;
edge_ptr->Vertex_Index=j;
edge_ptr->next= NULL;
}
else
{
edge_ptr=(Edge*)malloc(sizeof(Edge));
edge_ptr->Vertex_Index=j;
edge_ptr->next= NULL;
}
}
}
}
return g;
}
void
Blocks::Print_Equation_gr(Equation_set* Equation)
{
......
......@@ -30,16 +30,9 @@ using namespace std;
Normalization::Normalization(const SymbolTable &symbol_table_arg) :
symbol_table(symbol_table_arg)
symbol_table(symbol_table_arg), fp_verbose(false)
{
//Empty
fp_verbose=false;
};
Normalization::~Normalization()
{
//Empty
};
}
void
Normalization::IM_to_Gr(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation, Variable_set *Variable )
......@@ -484,32 +477,6 @@ Normalization::Free_All(int n, Equation_set* Equation, Variable_set* Variable)
Free_Other(Variable);
}
void
Normalization::ErrorHandling(int n, bool* IM, simple* Index_Equ_IM)
{
int i, j, k, k1, k2;
for(i = 0;i < n;i++)
{
k = 0;
for(j = 0;j < n;j++)
k += (int)IM[j * n + Index_Equ_IM[i].index];
if(k == 0)
cout << " the variable " << getnamebyID(eEndogenous, Index_Equ_IM[i].index) << " does not appear in any equation \n";
for(j = i + 1;j < n;j++)
{
k1 = k2 = 0;
for(k = 0;k < n;k++)
{
k1 = k1 + (int)(IM[Index_Equ_IM[i].index * n + k] != IM[Index_Equ_IM[j].index * n + k]);
k2 = k2 + (int)IM[Index_Equ_IM[i].index * n + k];
}
if ((k1 == 0)&(k2 == 1))
cout << " the variable " << getnamebyID(eEndogenous, Index_Equ_IM[i].index) << " is the only endogenous variable in equations " << Index_Equ_IM[i].index + 1 << " and " << Index_Equ_IM[j].index + 1 << "\n";
}
}
}
void
Normalization::Set_fp_verbose(bool ok)
{
......
This diff is collapsed.
......@@ -43,38 +43,7 @@ SymbolicGaussElimination::SymbolicGaussElimination()
}
#ifdef SIMPLIFY
void
SymbolicGaussElimination::list_table_u(int pos)
{
int i;
t_table_u *table_u;
table_u = First_table_u->pNext;
i = 0;
while(table_u)
{
if((table_u->type > 7) || (table_u->type < 1))
{
cout << "Error : table_u->type=" << int(table_u->type) << " i=" << i << " pos=" << pos << "\n";
system("pause");
exit( -1);
}
i++;
table_u = table_u->pNext;
}
}
//==================================================================================
void
SymbolicGaussElimination::print_free_u_list()
{
int i;
cout << "nb_free_u_list : " << nb_free_u_list << " \n";
cout << "-----------------------------------------------\n";
for(i = 0;i < nb_free_u_list;i++)
cout << i << " " << free_u_list[i] << "\n";
}
//==================================================================================
void
SymbolicGaussElimination::set_free_u_list(int index)
{
......@@ -223,99 +192,6 @@ SymbolicGaussElimination::write_to_file_table_y( t_table_y *save_table_y, t_tabl
}
}
void
SymbolicGaussElimination::write_to_file_table_u(t_table_u *save_table_u, t_table_u *save_i_table_u, int nb_save_table_u)
{
t_table_u *table_u;
SaveCode.write(reinterpret_cast<char *>(&nb_save_table_u), sizeof(nb_save_table_u));
#ifdef PRINT_OUT
cout << "**nb_save_table_u=" << nb_save_table_u << "\n";
#endif
#ifdef PRINT_OUT
cout << "**save_table_u=" << save_table_u << "\n";
#endif
while(save_table_u)
{
#ifdef PRINT_OUT
cout << "**save_table_u->type=" << int(save_table_u->type) << "\n";
#endif
switch (save_table_u->type)
{
case 3:
case 7:
SaveCode.write(reinterpret_cast<char *>(&save_table_u->type), sizeof(save_table_u->type));
SaveCode.write(reinterpret_cast<char *>(&save_table_u->index), sizeof(save_table_u->index));
SaveCode.write(reinterpret_cast<char *>(&save_table_u->op1), sizeof(save_table_u->op1));
#ifdef PRINT_OUT
if(save_table_u->type == 3)
cout << "+u[" << save_table_u->index << "]=1/(1-u[" << save_table_u->op1 << "])\n";
else
cout << "+u[" << save_table_u->index << "]*=u[" << save_table_u->op1 << "]\n";
#endif /**PRINT_OUT**/
break;
case 1:
case 2:
case 6:
SaveCode.write(reinterpret_cast<char *>(&save_table_u->type), sizeof(save_table_u->type));
SaveCode.write(reinterpret_cast<char *>(&save_table_u->index), sizeof(save_table_u->index));
SaveCode.write(reinterpret_cast<char *>(&save_table_u->op1), sizeof(save_table_u->op1));
SaveCode.write(reinterpret_cast<char *>(&save_table_u->op2), sizeof(save_table_u->op2));
#ifdef PRINT_OUT
if(save_table_u->type == 1)
cout << "+u[" << save_table_u->index << "]=" << "u[" << save_table_u->op1 << "]*u[" << save_table_u->op2 << "]\n";
else if(save_table_u->type == 2)
cout << "+u[" << save_table_u->index << "]+=u[" << save_table_u->op1 << "]*u[" << save_table_u->op2 << "]\n";
else
cout << "+u[" << save_table_u->index << "]=1/(1-u[" << save_table_u->op1 << "]*u[" << save_table_u->op2 << "])\n";
#endif /**PRINT_OUT**/
break;
case 5:
SaveCode.write(reinterpret_cast<char *>(&save_table_u->type), sizeof(save_table_u->type));
SaveCode.write(reinterpret_cast<char *>(&save_table_u->index), sizeof(save_table_u->index));
#ifdef PRINT_OUT
cout << "+push(u[" << save_table_u->index << "])\n";
#endif /**PRINT_OUT**/
break;
}
table_u = save_table_u->pNext;
free(save_table_u);
save_table_u = table_u;
}
#ifdef PRINT_OUT
cout << "save_i_table_u=" << save_i_table_u << "\n";
#endif
while(save_i_table_u)
{
switch (save_i_table_u->type)
{
case 3:
case 7:
SaveCode.write(reinterpret_cast<char *>(&save_i_table_u->type), sizeof(save_i_table_u->type));
SaveCode.write(reinterpret_cast<char *>(&save_i_table_u->index), sizeof(save_i_table_u->index));
SaveCode.write(reinterpret_cast<char *>(&save_i_table_u->op1), sizeof(save_i_table_u->op1));
break;
case 1: