- Bugs corrections in deterministic simulation with sparse option
- Check allowed with sparse option - New command "MODEL_INFO" providing informations about the block structure of the model - Memory leak corrections git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1993 ac1d8469-bf42-47a9-8791-bf33cf982152issue#70
parent
43c5fd18e6
commit
0e9ab2ebf4
|
@ -88,17 +88,22 @@ BlockTriangular::init_incidence_matrix(int nb_endo)
|
|||
|
||||
|
||||
void
|
||||
BlockTriangular::Free_IM(List_IM* First_IM)
|
||||
BlockTriangular::Free_IM(List_IM* First_IM) const
|
||||
{
|
||||
#ifdef DEBUG
|
||||
cout << "Free_IM\n";
|
||||
#endif
|
||||
List_IM *Cur_IM, *SFirst_IM;
|
||||
Cur_IM = SFirst_IM = First_IM;
|
||||
while(Cur_IM)
|
||||
{
|
||||
First_IM = Cur_IM->pNext;
|
||||
free(Cur_IM->IM);
|
||||
delete Cur_IM;
|
||||
Cur_IM = First_IM;
|
||||
}
|
||||
free(SFirst_IM);
|
||||
//free(SFirst_IM);
|
||||
//delete SFirst_IM;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -223,7 +228,7 @@ BlockTriangular::swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Inde
|
|||
SIM[pos2*n + j] = tmp_b;
|
||||
}
|
||||
}
|
||||
/* ...and variables (colomn)*/
|
||||
/* ...and variables (column)*/
|
||||
if(pos1 != pos3)
|
||||
{
|
||||
tmp_i = Index_Var_IM[pos1].index;
|
||||
|
@ -241,7 +246,7 @@ BlockTriangular::swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Inde
|
|||
//------------------------------------------------------------------------------
|
||||
// Find the prologue and the epilogue of the model
|
||||
void
|
||||
BlockTriangular::Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM)
|
||||
BlockTriangular::Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM, bool* IM0)
|
||||
{
|
||||
bool modifie = 1;
|
||||
int i, j, k, l = 0;
|
||||
|
@ -261,7 +266,7 @@ BlockTriangular::Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n
|
|||
l = j;
|
||||
}
|
||||
}
|
||||
if ((k == 1) /* && (l==i)*/)
|
||||
if ((k == 1) && IM0[Index_Equ_IM[i].index*n + Index_Var_IM[l].index])
|
||||
{
|
||||
modifie = 1;
|
||||
swap_IM_c(IM, *prologue, i, l, Index_Var_IM, Index_Equ_IM, n);
|
||||
|
@ -273,6 +278,8 @@ BlockTriangular::Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n
|
|||
}
|
||||
*epilogue = 0;
|
||||
modifie = 1;
|
||||
/*print_SIM(IM,n);
|
||||
print_SIM(IM*/
|
||||
while(modifie)
|
||||
{
|
||||
modifie = 0;
|
||||
|
@ -287,7 +294,7 @@ BlockTriangular::Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n
|
|||
l = j;
|
||||
}
|
||||
}
|
||||
if ((k == 1) /* && (l==i)*/)
|
||||
if ((k == 1) && IM0[Index_Equ_IM[l].index*n + Index_Var_IM[i].index])
|
||||
{
|
||||
modifie = 1;
|
||||
swap_IM_c(IM, n - (1 + *epilogue), l, i, Index_Var_IM, Index_Equ_IM, n);
|
||||
|
@ -330,10 +337,10 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int
|
|||
while(Cur_IM)
|
||||
{
|
||||
k = Cur_IM->lead_lag;
|
||||
i_1 = Index_Var_IM[*count_Equ].index * endo_nbr;
|
||||
i_1 = Index_Equ_IM[*count_Equ].index * endo_nbr;
|
||||
if(k > 0)
|
||||
{
|
||||
if(Cur_IM->IM[i_1 + Index_Equ_IM[ /*j*/*count_Equ].index])
|
||||
if(Cur_IM->IM[i_1 + Index_Var_IM[ /*j*/*count_Equ].index])
|
||||
{
|
||||
nb_lead_lag_endo++;
|
||||
tmp_size[Model_Max_Lag + k]++;
|
||||
|
@ -348,7 +355,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int
|
|||
else
|
||||
{
|
||||
k = -k;
|
||||
if(Cur_IM->IM[i_1 + Index_Equ_IM[ /*j*/*count_Equ].index])
|
||||
if(Cur_IM->IM[i_1 + Index_Var_IM[ /*j*/*count_Equ].index])
|
||||
{
|
||||
tmp_size[Model_Max_Lag - k]++;
|
||||
nb_lead_lag_endo++;
|
||||
|
@ -374,39 +381,45 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int
|
|||
ModelBlock->in_Block_Var[Index_Var_IM[*count_Equ].index] = *count_Block;
|
||||
ModelBlock->in_Equ_of_Block[Index_Equ_IM[*count_Equ].index] = ModelBlock->in_Var_of_Block[Index_Var_IM[*count_Equ].index] = 0;
|
||||
Index_Equ_IM[*count_Equ].block = *count_Block;
|
||||
cout << "Lead=" << Lead << " Lag=" << Lag << "\n";
|
||||
if ((Lead > 0) && (Lag > 0))
|
||||
ModelBlock->Block_List[*count_Block].Simulation_Type = SOLVE_TWO_BOUNDARIES_SIMPLE;
|
||||
else if((Lead > 0) && (Lag == 0))
|
||||
ModelBlock->Block_List[*count_Block].Simulation_Type = SOLVE_BACKWARD_SIMPLE;
|
||||
else
|
||||
ModelBlock->Block_List[*count_Block].Simulation_Type = SOLVE_FOREWARD_SIMPLE;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag = (IM_compact*)malloc((Lead + Lag + 1) * sizeof(IM_compact));
|
||||
ModelBlock->Block_List[*count_Block].Nb_Lead_Lag_Endo = nb_lead_lag_endo;
|
||||
if(nb_lead_lag_endo)
|
||||
{
|
||||
ModelBlock->Block_List[*count_Block].Simulation_Type = SOLVE_TWO_BOUNDARIES_SIMPLE;
|
||||
cout << "alloc ModelBlock->Block_List[" << *count_Block << "].IM_lead_lag = (" << (Lead + Lag + 1) * sizeof(IM_compact) << ")\n";
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag = (IM_compact*)malloc((Lead + Lag + 1) * sizeof(IM_compact));
|
||||
ModelBlock->Block_List[*count_Block].Nb_Lead_Lag_Endo = nb_lead_lag_endo;
|
||||
ModelBlock->Block_List[*count_Block].variable_dyn_index = (int*)malloc(nb_lead_lag_endo * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].variable_dyn_leadlag = (int*)malloc(nb_lead_lag_endo * sizeof(int));
|
||||
ls = l = 1;
|
||||
i1 = 0;
|
||||
for(i = 0;i < Lead + Lag + 1;i++)
|
||||
}
|
||||
ls = l = 1;
|
||||
i1 = 0;
|
||||
for(int li = 0;li < Lead + Lag + 1;li++)
|
||||
{
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].size = tmp_size[Model_Max_Lag - Lag + li];
|
||||
if(tmp_size[Model_Max_Lag - Lag + li])
|
||||
{
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].size = tmp_size[Model_Max_Lag - Lag + i];
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].nb_endo = tmp_size[Model_Max_Lag - Lag + i];
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].u = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].us = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Var = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Equ = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Var_Index = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Equ_Index = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Var_dyn_Index = (int*)malloc(tmp_size[Model_Max_Lag - Lag + i] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].u_init = l;
|
||||
IM = bGet_IM(i - Lag);
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].nb_endo = tmp_size[Model_Max_Lag - Lag + li];
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].u = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].us = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Var = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Equ = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Var_Index = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Equ_Index = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Var_dyn_Index = (int*)malloc(tmp_size[Model_Max_Lag - Lag + li] * sizeof(int));
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].u_init = l;
|
||||
IM = bGet_IM(li - Lag);
|
||||
if(IM == NULL)
|
||||
{
|
||||
cout << "Error IM(" << i - Lag << ") doesn't exist\n";
|
||||
cout << "Error IM(" << li - Lag << ") doesn't exist\n";
|
||||
exit( -1);
|
||||
}
|
||||
if(IM[Index_Var_IM[*count_Equ].index + Index_Equ_IM[*count_Equ].index*endo_nbr])
|
||||
if(IM[Index_Var_IM[*count_Equ].index + Index_Equ_IM[*count_Equ].index*endo_nbr] && nb_lead_lag_endo)
|
||||
{
|
||||
ModelBlock->Block_List[*count_Block].variable_dyn_index[i1] = Index_Var_IM[*count_Equ].index;
|
||||
ModelBlock->Block_List[*count_Block].variable_dyn_leadlag[i1] = i - Lag;
|
||||
ModelBlock->Block_List[*count_Block].variable_dyn_leadlag[i1] = li - Lag;
|
||||
tmp_var[0] = i1;
|
||||
i1++;
|
||||
}
|
||||
|
@ -414,31 +427,28 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int
|
|||
i_1 = Index_Equ_IM[*count_Equ].index * endo_nbr;
|
||||
if(IM[Index_Var_IM[*count_Equ].index + i_1])
|
||||
{
|
||||
if(i == Lag)
|
||||
if(li == Lag)
|
||||
{
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].us[m] = ls;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].us[m] = ls;
|
||||
ls++;
|
||||
}
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].u[m] = l;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Equ[m] = 0;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Var[m] = 0;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Equ_Index[m] = Index_Equ_IM[*count_Equ].index;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Var_Index[m] = Index_Var_IM[*count_Equ].index;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].Var_dyn_Index[m] = ModelBlock->Block_List[*count_Block].variable_dyn_index[tmp_var[0]];
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].u[m] = l;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Equ[m] = 0;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Var[m] = 0;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Equ_Index[m] = Index_Equ_IM[*count_Equ].index;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Var_Index[m] = Index_Var_IM[*count_Equ].index;
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].Var_dyn_Index[m] = ModelBlock->Block_List[*count_Block].variable_dyn_index[tmp_var[0]];
|
||||
l++;
|
||||
m++;
|
||||
}
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[i].u_finish = l - 1;
|
||||
}
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag[li].u_finish = l - 1;
|
||||
}
|
||||
}
|
||||
else if((Lead > 0) && (Lag == 0))
|
||||
ModelBlock->Block_List[*count_Block].Simulation_Type = SOLVE_BACKWARD_SIMPLE;
|
||||
else
|
||||
ModelBlock->Block_List[*count_Block].Simulation_Type = SOLVE_FOREWARD_SIMPLE;
|
||||
(*count_Equ)++;
|
||||
(*count_Block)++;
|
||||
free(tmp_size);
|
||||
free(tmp_endo);
|
||||
free(tmp_var);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
@ -535,7 +545,6 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int
|
|||
}
|
||||
ModelBlock->Block_List[*count_Block].Max_Lag = Lag;
|
||||
ModelBlock->Block_List[*count_Block].Max_Lead = Lead;
|
||||
cout << "alloc ModelBlock->Block_List[" << *count_Block << "].IM_lead_lag = (" << (Lead + Lag + 1) * sizeof(IM_compact) << ")\n";
|
||||
ModelBlock->Block_List[*count_Block].IM_lead_lag = (IM_compact*)malloc((Lead + Lag + 1) * sizeof(IM_compact));
|
||||
ls = l = size;
|
||||
i1 = 0;
|
||||
|
@ -621,7 +630,7 @@ BlockTriangular::Allocate_Block(int size, int *count_Equ, int *count_Block, int
|
|||
|
||||
|
||||
void
|
||||
BlockTriangular::Free_Block(Model_Block* ModelBlock)
|
||||
BlockTriangular::Free_Block(Model_Block* ModelBlock) const
|
||||
{
|
||||
int blk, i;
|
||||
#ifdef DEBUG
|
||||
|
@ -637,12 +646,33 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock)
|
|||
free(ModelBlock->Block_List[blk].Equation);
|
||||
free(ModelBlock->Block_List[blk].Variable);
|
||||
free(ModelBlock->Block_List[blk].Variable_Sorted);
|
||||
free(ModelBlock->Block_List[blk].Own_Derivative);
|
||||
if(ModelBlock->Block_List[blk].Nb_Lead_Lag_Endo)
|
||||
{
|
||||
free(ModelBlock->Block_List[blk].variable_dyn_index);
|
||||
free(ModelBlock->Block_List[blk].variable_dyn_leadlag);
|
||||
}
|
||||
for(i = 0;i < ModelBlock->Block_List[blk].Max_Lag + ModelBlock->Block_List[blk].Max_Lead + 1;i++)
|
||||
{
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].u);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].us);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_Index);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ_Index);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_dyn_Index);
|
||||
}
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag);
|
||||
delete(ModelBlock->Block_List[blk].Temporary_terms);
|
||||
}
|
||||
else
|
||||
{
|
||||
free(ModelBlock->Block_List[blk].Equation);
|
||||
free(ModelBlock->Block_List[blk].Variable);
|
||||
free(ModelBlock->Block_List[blk].Variable_Sorted);
|
||||
free(ModelBlock->Block_List[blk].Own_Derivative);
|
||||
free(ModelBlock->Block_List[blk].variable_dyn_index);
|
||||
free(ModelBlock->Block_List[blk].variable_dyn_leadlag);
|
||||
for(i = 0;i < ModelBlock->Block_List[blk].Max_Lag + ModelBlock->Block_List[blk].Max_Lead + 1;i++)
|
||||
{
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].u);
|
||||
|
@ -651,8 +681,10 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock)
|
|||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Equ_Index);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_Index);
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag[i].Var_dyn_Index);
|
||||
}
|
||||
free(ModelBlock->Block_List[blk].IM_lead_lag);
|
||||
delete(ModelBlock->Block_List[blk].Temporary_terms);
|
||||
}
|
||||
}
|
||||
free(ModelBlock->in_Block_Equ);
|
||||
|
@ -661,6 +693,8 @@ BlockTriangular::Free_Block(Model_Block* ModelBlock)
|
|||
free(ModelBlock->in_Var_of_Block);
|
||||
free(ModelBlock->Block_List);
|
||||
free(ModelBlock);
|
||||
free(Index_Equ_IM);
|
||||
free(Index_Var_IM);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
|
@ -672,10 +706,10 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
|
|||
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;
|
||||
//List_IM * p_First_IM, *p_Cur_IM, *Cur_IM;
|
||||
Equation_set* Equation_gr = (Equation_set*) malloc(sizeof(Equation_set));
|
||||
bool* SIM0, *SIM00;
|
||||
p_First_IM = (List_IM*)malloc(sizeof(*p_First_IM));
|
||||
/*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;
|
||||
|
@ -692,82 +726,110 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
|
|||
}
|
||||
else
|
||||
p_Cur_IM->pNext = NULL;
|
||||
}
|
||||
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM);
|
||||
}*/
|
||||
SIM0 = (bool*)malloc(n * n * sizeof(bool));
|
||||
//cout << "Allocate SIM0=" << SIM0 << " size=" << n * n * sizeof(bool) << "\n";
|
||||
memcpy(SIM0,IM_0,n*n*sizeof(bool));
|
||||
Prologue_Epilogue(IM, prologue, epilogue, n, Index_Var_IM, Index_Equ_IM, SIM0);
|
||||
//cout << "free SIM0=" << SIM0 << "\n";
|
||||
free(SIM0);
|
||||
if(bt_verbose)
|
||||
{
|
||||
cout << "prologue : " << *prologue << " epilogue : " << *epilogue << "\n";
|
||||
cout << "IM_0\n";
|
||||
Print_SIM(IM_0, n);
|
||||
cout << "IM\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)
|
||||
if(*prologue+*epilogue<n)
|
||||
{
|
||||
cout << "Normalizing the model ...\n";
|
||||
if(mixing)
|
||||
if(Do_Normalization)
|
||||
{
|
||||
double* max_val=(double*)malloc(n*sizeof(double));
|
||||
memset(max_val,0,n*sizeof(double));
|
||||
for( map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++ )
|
||||
cout << "Normalizing the model ...\n";
|
||||
if(mixing)
|
||||
{
|
||||
if(fabs(iter->second)>max_val[iter->first.first])
|
||||
max_val[iter->first.first]=fabs(iter->second);
|
||||
}
|
||||
for( map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++ )
|
||||
iter->second/=max_val[iter->first.first];
|
||||
free(max_val);
|
||||
bool OK=false;
|
||||
double bi=0.99999999;
|
||||
int suppressed=0;
|
||||
while(!OK && bi>1e-14)
|
||||
{
|
||||
int suppress=0;
|
||||
SIM0 = (bool*)malloc(n * n * sizeof(bool));
|
||||
memset(SIM0,0,n*n*sizeof(bool));
|
||||
SIM00 = (bool*)malloc(n * n * sizeof(bool));
|
||||
memset(SIM00,0,n*n*sizeof(bool));
|
||||
double* max_val=(double*)malloc(n*sizeof(double));
|
||||
//cout << "n=" << n << "\n";
|
||||
memset(max_val,0,n*sizeof(double));
|
||||
for( map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++ )
|
||||
{
|
||||
if(fabs(iter->second)>bi)
|
||||
{
|
||||
SIM0[iter->first.first*n+iter->first.second]=1;
|
||||
if(!IM_0[iter->first.first*n+iter->first.second])
|
||||
{
|
||||
//cout << "iter->first.first=" << iter->first.first << "\n";
|
||||
if(fabs(iter->second)>max_val[iter->first.first])
|
||||
max_val[iter->first.first]=fabs(iter->second);
|
||||
}
|
||||
for( map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++ )
|
||||
iter->second/=max_val[iter->first.first];
|
||||
free(max_val);
|
||||
bool OK=false;
|
||||
double bi=0.99999999;
|
||||
int suppressed=0;
|
||||
while(!OK && bi>1e-14)
|
||||
{
|
||||
int suppress=0;
|
||||
SIM0 = (bool*)malloc(n * n * sizeof(bool));
|
||||
//cout << "Allocate SIM0=" << SIM0 << " size=" << n * n * sizeof(bool) << "\n";
|
||||
memset(SIM0,0,n*n*sizeof(bool));
|
||||
SIM00 = (bool*)malloc(n * n * sizeof(bool));
|
||||
//cout << "Allocate SIM00=" << SIM00 << " size=" << n * n * sizeof(bool) << "\n";
|
||||
memset(SIM00,0,n*n*sizeof(bool));
|
||||
//cout << "n*n=" << n*n << "\n";
|
||||
for( map< pair< int, int >, double >::iterator iter = j_m.begin(); iter != j_m.end(); iter++ )
|
||||
{
|
||||
if(fabs(iter->second)>bi)
|
||||
{
|
||||
//cout << "iter->first.first*n+iter->first.second=" << iter->first.first*n+iter->first.second << "\n";
|
||||
SIM0[iter->first.first*n+iter->first.second]=1;
|
||||
if(!IM_0[iter->first.first*n+iter->first.second])
|
||||
{
|
||||
cout << "Error nothing at IM_0[" << iter->first.first << ", " << iter->first.second << "]=" << IM_0[iter->first.first*n+iter->first.second] << "\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
suppress++;
|
||||
}
|
||||
//cout << "n*n=" << n*n << "\n";
|
||||
for(i = 0;i < n;i++)
|
||||
for(j = 0;j < n;j++)
|
||||
{
|
||||
cout << "Error nothing at IM_0[" << iter->first.first << ", " << iter->first.second << "]=" << IM_0[iter->first.first*n+iter->first.second] << "\n";
|
||||
//cout << "Index_Equ_IM[i].index * n + Index_Var_IM[j].index=" << Index_Equ_IM[i].index * n + Index_Var_IM[j].index << "\n";
|
||||
SIM00[i*n + j] = SIM0[Index_Equ_IM[i].index * n + Index_Var_IM[j].index];
|
||||
}
|
||||
}
|
||||
else
|
||||
suppress++;
|
||||
}
|
||||
for(i = 0;i < n;i++)
|
||||
for(j = 0;j < n;j++)
|
||||
SIM00[i*n + j] = SIM0[Index_Equ_IM[i].index * n + Index_Var_IM[j].index];
|
||||
free(SIM0);
|
||||
if(suppress!=suppressed)
|
||||
OK=normalization.Normalize(n, *prologue, *epilogue, SIM00, Index_Equ_IM, Equation_gr, 1, IM);
|
||||
suppressed=suppress;
|
||||
//cout << "free SIM0=" << SIM0 << "\n";
|
||||
free(SIM0);
|
||||
if(suppress!=suppressed)
|
||||
{
|
||||
OK=normalization.Normalize(n, *prologue, *epilogue, SIM00, Index_Equ_IM, Equation_gr, 1, IM);
|
||||
if(!OK)
|
||||
normalization.Free_Equation(n-*prologue-*epilogue,Equation_gr);
|
||||
}
|
||||
suppressed=suppress;
|
||||
if(!OK)
|
||||
bi/=1.07;
|
||||
if(bi>1e-14)
|
||||
free(SIM00);
|
||||
}
|
||||
if(!OK)
|
||||
bi/=1.07;
|
||||
if(bi>1e-14)
|
||||
free(SIM00);
|
||||
}
|
||||
if(!OK)
|
||||
{
|
||||
normalization.Set_fp_verbose(true);
|
||||
OK=normalization.Normalize(n, *prologue, *epilogue, SIM00, Index_Equ_IM, Equation_gr, 1, IM);
|
||||
cout << "Error\n";
|
||||
exit(-1);
|
||||
{
|
||||
normalization.Set_fp_verbose(true);
|
||||
OK=normalization.Normalize(n, *prologue, *epilogue, SIM00, Index_Equ_IM, Equation_gr, 1, IM);
|
||||
cout << "Error\n";
|
||||
exit(-1);
|
||||
}
|
||||
}
|
||||
else
|
||||
normalization.Normalize(n, *prologue, *epilogue, IM, Index_Equ_IM, Equation_gr, 0, 0);
|
||||
}
|
||||
else
|
||||
normalization.Normalize(n, *prologue, *epilogue, IM, Index_Equ_IM, Equation_gr, 0, 0);
|
||||
normalization.Gr_to_IM_basic(n, *prologue, *epilogue, IM, Equation_gr, false);
|
||||
}
|
||||
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);
|
||||
normalization.Free_Equation(n-*prologue-*epilogue,Equation_gr);
|
||||
free(Equation_gr);
|
||||
if(bt_verbose)
|
||||
blocks.block_result_print(res);
|
||||
if ((*prologue) || (*epilogue))
|
||||
|
@ -775,8 +837,10 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
|
|||
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;
|
||||
{
|
||||
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";
|
||||
|
@ -790,8 +854,9 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
|
|||
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);
|
||||
//Free_IM(p_First_IM);
|
||||
count_Equ = count_Block = 0;
|
||||
//Print_IM(endo_nbr);
|
||||
if (*prologue)
|
||||
Allocate_Block(*prologue, &count_Equ, &count_Block, PROLOGUE, ModelBlock);
|
||||
for(j = 0;j < res->n_sets;j++)
|
||||
|
@ -803,6 +868,7 @@ BlockTriangular::Normalize_and_BlockDecompose(bool* IM, Model_Block* ModelBlock,
|
|||
}
|
||||
if (*epilogue)
|
||||
Allocate_Block(*epilogue, &count_Equ, &count_Block, EPILOGUE, ModelBlock);
|
||||
blocks.block_result_free(res);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -852,6 +918,8 @@ BlockTriangular::Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_
|
|||
for(i = 0;i < endo_nbr*endo_nbr;i++)
|
||||
SIM_0[i] = Cur_IM->IM[i];
|
||||
Normalize_and_BlockDecompose(SIM, ModelBlock, endo_nbr, &prologue, &epilogue, Index_Var_IM, Index_Equ_IM, 1, 1, SIM_0, j_m);
|
||||
free(SIM_0);
|
||||
free(SIM);
|
||||
if(bt_verbose)
|
||||
for(i = 0;i < endo_nbr;i++)
|
||||
cout << "Block=" << Index_Equ_IM[i].block << " Equ=" << Index_Equ_IM[i].index << " Var= " << Index_Var_IM[i].index << " " << symbol_table.getNameByID(eEndogenous, Index_Var_IM[i].index) << "\n";
|
||||
|
|
|
@ -68,6 +68,23 @@ CheckStatement::checkPass(ModFileStructure &mod_file_struct)
|
|||
mod_file_struct.check_present = true;
|
||||
}
|
||||
|
||||
Model_InfoStatement::Model_InfoStatement(const OptionsList &options_list_arg) :
|
||||
options_list(options_list_arg)
|
||||
{
|
||||
}
|
||||
|
||||
void Model_InfoStatement::checkPass(ModFileStructure &mod_file_struct)
|
||||
{
|
||||
//mod_file_struct.model_info_present = true;
|
||||
}
|
||||
|
||||
void Model_InfoStatement::writeOutput(ostream &output, const string &basename) const
|
||||
{
|
||||
options_list.writeOutput(output);
|
||||
output << "model_info();\n";
|
||||
}
|
||||
|
||||
|
||||
SimulStatement::SimulStatement(const OptionsList &options_list_arg) :
|
||||
options_list(options_list_arg)
|
||||
{
|
||||
|
|
|
@ -183,6 +183,7 @@ statement : declaration
|
|||
| dynatype
|
||||
| dynasave
|
||||
| model_comparison
|
||||
| model_info
|
||||
| planner_objective
|
||||
| ramsey_policy
|
||||
| bvar_density
|
||||
|
@ -612,6 +613,10 @@ check_options_list : check_options_list COMMA check_options
|
|||
|
||||
check_options : o_solve_algo;
|
||||
|
||||
model_info : MODEL_INFO ';'
|
||||
{ driver.model_info(); }
|
||||
;
|
||||
|
||||
simul : SIMUL ';'
|
||||
{ driver.simulate(); }
|
||||
| SIMUL '(' simul_options_list ')' ';'
|
||||
|
|
|
@ -104,6 +104,7 @@ int sigma_e = 0;
|
|||
<INITIAL>periods {BEGIN DYNARE_STATEMENT; return token::PERIODS;}
|
||||
<INITIAL>cutoff {BEGIN DYNARE_STATEMENT; return token::CUTOFF;}
|
||||
<INITIAL>markowitz {BEGIN DYNARE_STATEMENT; return token::MARKOWITZ;}
|
||||
<INITIAL>model_info {BEGIN DYNARE_STATEMENT; return token::MODEL_INFO;}
|
||||
<INITIAL>estimation {BEGIN DYNARE_STATEMENT; return token::ESTIMATION;}
|
||||
<INITIAL>prior_analysis {BEGIN DYNARE_STATEMENT; return token::PRIOR_ANALYSIS;}
|
||||
<INITIAL>posterior_analysis {BEGIN DYNARE_STATEMENT; return token::POSTERIOR_ANALYSIS;}
|
||||
|
|
|
@ -86,6 +86,7 @@ main(int argc, char** argv)
|
|||
}
|
||||
|
||||
// Do the rest
|
||||
|
||||
main2(macro_output, basename, debug, clear_all);
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -28,10 +28,10 @@ void
|
|||
main2(stringstream &in, string &basename, bool debug, bool clear_all)
|
||||
{
|
||||
ParsingDriver p;
|
||||
|
||||
//cout << "OK\n";
|
||||
// Do parsing and construct internal representation of mod file
|
||||
ModFile *mod_file = p.parse(in, debug);
|
||||
|
||||
//cout << "OK1\n";
|
||||
// Run checking pass
|
||||
mod_file->checkPass();
|
||||
|
||||
|
|
|
@ -150,6 +150,7 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all) const
|
|||
<< "warning warning_old_state" << endl;
|
||||
mOutputFile << "logname_ = '" << basename << ".log';" << endl;
|
||||
mOutputFile << "diary " << basename << ".log" << endl;
|
||||
mOutputFile << "options_.model_mode = " << model_tree.mode << ";\n";
|
||||
|
||||
|
||||
if (model_tree.equation_number() > 0)
|
||||
|
|
|
@ -207,6 +207,9 @@ Blocks::sc(Equation_set *g)
|
|||
void
|
||||
Blocks::block_result_free(block_result_t *r)
|
||||
{
|
||||
#ifdef DEBUG
|
||||
cout << "block_result_free\n";
|
||||
#endif
|
||||
free(r->vertices);
|
||||
free(r->sets_s);
|
||||
free(r->sets_f);
|
||||
|
|
|
@ -283,9 +283,23 @@ void
|
|||
Normalization::Gr_to_IM_basic(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation, bool transpose)
|
||||
{
|
||||
int i, j, edges, n;
|
||||
Edge *e1;
|
||||
Edge *e1, *e2;
|
||||
n = n0 - prologue - epilogue;
|
||||
Equation->size = n;
|
||||
if(Equation->Number)
|
||||
{
|
||||
for(i = 0;i < n;i++)
|
||||
{
|
||||
e1 = Equation->Number[i].First_Edge;
|
||||
while(e1 != NULL)
|
||||
{
|
||||
e2 = e1->next;
|
||||
free(e1);
|
||||
e1 = e2;
|
||||
}
|
||||
}
|
||||
free(Equation->Number);
|
||||
}
|
||||
Equation->Number = (Equation_vertex*)malloc(n * sizeof(Equation_vertex));
|
||||
edges = 0;
|
||||
if(transpose)
|
||||
|
@ -382,8 +396,12 @@ Normalization::Gr_to_IM(int n0, int prologue, int epilogue, bool* IM, simple* In
|
|||
}
|
||||
free(SIM);
|
||||
free(Index_Equ_IM_tmp);
|
||||
//cout << "mixing=" << mixing << "\n";
|
||||
if(mixing)
|
||||
Gr_to_IM_basic(n0, prologue, epilogue, IM, Equation, true);
|
||||
{
|
||||
//Free_Equation(n,Equation);
|
||||
Gr_to_IM_basic(n0, prologue, epilogue, IM, Equation, true);
|
||||
}
|
||||
else
|
||||
{
|
||||
// In this step we :
|
||||
|
@ -453,17 +471,21 @@ Normalization::Free_Equation(int n, Equation_set* Equation)
|
|||
while(e1 != NULL)
|
||||
{
|
||||
e2 = e1->next;
|
||||
free(e1);
|
||||
e1 = e2;
|
||||
}
|
||||
}
|
||||
free(Equation->Number);
|
||||
free(Equation);
|
||||
//free(Equation);
|
||||
}
|
||||
|
||||
void
|
||||
Normalization::Free_Other(Variable_set* Variable)
|
||||
{
|
||||
//free unused space
|
||||
#ifdef DEBUG
|
||||
cout << "Free_Other\n";
|
||||
#endif
|
||||
free(Local_Heap);
|
||||
free(Variable->Number);
|
||||
free(Variable);
|
||||
|
@ -526,6 +548,7 @@ Normalization::Normalize(int n, int prologue, int epilogue, bool* IM, simple* In
|
|||
}
|
||||
}
|
||||
Free_Other(Variable);
|
||||
//Free_All(n,Equation,Variable);
|
||||
#ifdef DEBUG
|
||||
cout << "end of Normalize\n";
|
||||
#endif
|
||||
|
|
972
ModelTree.cc
972
ModelTree.cc
File diff suppressed because it is too large
Load Diff
|
@ -729,6 +729,15 @@ ParsingDriver::simul()
|
|||
options_list.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParsingDriver::model_info()
|
||||
{
|
||||
mod_file->addStatement(new Model_InfoStatement(options_list));
|
||||
options_list.clear();
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
ParsingDriver::check()
|
||||
{
|
||||
|
|
|
@ -57,14 +57,14 @@ public:
|
|||
void unfill_IM(int equation, int variable_endo, int lead_lag);
|
||||
void init_incidence_matrix(int nb_endo);
|
||||
void Print_IM(int n) const;
|
||||
void Free_IM(List_IM* First_IM);
|
||||
void Free_IM(List_IM* First_IM) const;
|
||||
void Print_SIM(bool* IM, int n) const;
|
||||
void Normalize_and_BlockDecompose_Static_0_Model(const jacob_map &j_m);
|
||||
bool 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 , jacob_map j_m);
|
||||
void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM);
|
||||
void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM, bool* IM0);
|
||||
void swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Index_Var_IM, simple* Index_Equ_IM, int n);
|
||||
void Allocate_Block(int size, int *count_Equ, int *count_Block, int type, Model_Block * ModelBlock);
|
||||
void Free_Block(Model_Block* ModelBlock);
|
||||
void Free_Block(Model_Block* ModelBlock) const;
|
||||
List_IM *First_IM ;
|
||||
List_IM *Last_IM ;
|
||||
simple *Index_Equ_IM;
|
||||
|
|
|
@ -76,6 +76,16 @@ public:
|
|||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class Model_InfoStatement : public Statement
|
||||
{
|
||||
private:
|
||||
const OptionsList options_list;
|
||||
public:
|
||||
Model_InfoStatement(const OptionsList &options_list_arg);
|
||||
virtual void checkPass(ModFileStructure &mod_file_struct);
|
||||
virtual void writeOutput(ostream &output, const string &basename) const;
|
||||
};
|
||||
|
||||
class StochSimulStatement : public Statement
|
||||
{
|
||||
private:
|
||||
|
|
|
@ -73,6 +73,7 @@ public:
|
|||
void Gr_to_IM_basic(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation,bool transpose);
|
||||
const SymbolTable &symbol_table;
|
||||
void Set_fp_verbose(bool ok);
|
||||
void Free_Equation(int n, Equation_set* Equation);
|
||||
private:
|
||||
void IM_to_Gr(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation, Variable_set *Variable );
|
||||
void Inits(Equation_set *Equation);
|
||||
|
@ -83,7 +84,6 @@ private:
|
|||
int MeasureMatching(Equation_set *Equation);
|
||||
void OutputMatching(Equation_set* Equation);
|
||||
void Gr_to_IM(int n0, int prologue, int epilogue, bool* IM, simple* Index_Var_IM, Equation_set *Equation,bool mixing, bool* IM_s);
|
||||
void Free_Equation(int n, Equation_set* Equation);
|
||||
void Free_Other(Variable_set* Variable);
|
||||
void Free_All(int n, Equation_set* Equation, Variable_set* Variable);
|
||||
int eq, eex;
|
||||
|
|
|
@ -46,6 +46,7 @@ using namespace std;
|
|||
# undef yyFlexLexer
|
||||
#endif
|
||||
|
||||
|
||||
//! The lexer class
|
||||
/*! Actually it was necessary to subclass the DynareFlexLexer class generated by Flex,
|
||||
since the prototype for DynareFlexLexer::yylex() was not convenient.
|
||||
|
@ -53,7 +54,7 @@ using namespace std;
|
|||
class DynareFlex : public DynareFlexLexer
|
||||
{
|
||||
public:
|
||||
DynareFlex(istream* in = 0, ostream* out = 0);
|
||||
DynareFlex(std::istream* in = 0, ostream* out = 0);
|
||||
|
||||
//! The main lexing function
|
||||
Dynare::parser::token_type lex(Dynare::parser::semantic_type *yylval,
|
||||
|
@ -145,7 +146,7 @@ public:
|
|||
|
||||
//! Starts parsing, and constructs the MOD file representation
|
||||
/*! The returned pointer should be deleted after use */
|
||||
ModFile *parse(istream &in, bool debug);
|
||||
ModFile *parse(std::istream &in, bool debug);
|
||||
|
||||
//! Reference to the lexer
|
||||
class DynareFlex *lexer;
|
||||
|
@ -282,6 +283,8 @@ public:
|
|||
void simul();
|
||||
//! Writes check command
|
||||
void check();
|
||||
//! Writes model_info command
|
||||
void model_info();
|
||||
//! Writes estimated params command
|
||||
void estimated_params();
|
||||
//! Writes estimated params init command
|
||||
|
|
|
@ -53,12 +53,12 @@ private:
|
|||
class ScanContext
|
||||
{
|
||||
public:
|
||||
istream *input;
|
||||
std::istream *input;
|
||||
struct yy_buffer_state *buffer;
|
||||
const Macro::parser::location_type yylloc;
|
||||
const string for_body;
|
||||
const Macro::parser::location_type for_body_loc;
|
||||
ScanContext(istream *input_arg, struct yy_buffer_state *buffer_arg,
|
||||
ScanContext(std::istream *input_arg, struct yy_buffer_state *buffer_arg,
|
||||
Macro::parser::location_type &yylloc_arg, const string &for_body_arg,
|
||||
Macro::parser::location_type &for_body_loc_arg) :
|
||||
input(input_arg), buffer(buffer_arg), yylloc(yylloc_arg), for_body(for_body_arg),
|
||||
|
@ -70,7 +70,7 @@ private:
|
|||
|
||||
//! Input stream used for initialization of current scanning context
|
||||
/*! Kept for deletion at end of current scanning buffer */
|
||||
istream *input;
|
||||
std::istream *input;
|
||||
|
||||
//! If current context is the body of a loop, contains the string of the loop body. Empty otherwise.
|
||||
string for_body;
|
||||
|
@ -125,7 +125,7 @@ private:
|
|||
and initialise a new scanning context with the loop body */
|
||||
bool iter_loop(MacroDriver &driver, Macro::parser::location_type *yylloc);
|
||||
public:
|
||||
MacroFlex(istream* in = 0, ostream* out = 0);
|
||||
MacroFlex(std::istream* in = 0, ostream* out = 0);
|
||||
|
||||
//! The main lexing function
|
||||
Macro::parser::token_type lex(Macro::parser::semantic_type *yylval,
|
||||
|
|
Loading…
Reference in New Issue