diff --git a/preprocessor/BlockTriangular.cc b/preprocessor/BlockTriangular.cc index f3c403bb271148c57e372eb0ca40448c75b90c29..bce845494b1a80b95131462eb0405da26b1b30fb 100644 --- a/preprocessor/BlockTriangular.cc +++ b/preprocessor/BlockTriangular.cc @@ -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 diff --git a/preprocessor/ModelBlocks.cc b/preprocessor/ModelBlocks.cc index a5a33494a5539390affa4678b7fca25fb516084d..3c202b4a532f4880f34bc5c5e2e6a6c930c8abe3 100644 --- a/preprocessor/ModelBlocks.cc +++ b/preprocessor/ModelBlocks.cc @@ -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) { diff --git a/preprocessor/ModelNormalization.cc b/preprocessor/ModelNormalization.cc index 040fdf6dd7b863f27f152c93ba227cebe9164814..fbd8cdb05ba8594c1db8a30c5cded222d67f6922 100644 --- a/preprocessor/ModelNormalization.cc +++ b/preprocessor/ModelNormalization.cc @@ -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) { diff --git a/preprocessor/Model_Graph.cc b/preprocessor/Model_Graph.cc index 8103ac9f316f05110e1d144e3564c45f1324b4e3..562f21020e0f8ffad2ccdf270a9e8b82f90418d6 100644 --- a/preprocessor/Model_Graph.cc +++ b/preprocessor/Model_Graph.cc @@ -132,34 +132,6 @@ void Check_Graph(t_model_graph* model_graph) } } - - -void -copy_model_graph(t_model_graph* model_graph, t_model_graph* saved_model_graph, int nb_endo, int y_kmax) -{ - int i, j; - saved_model_graph->nb_vertices = model_graph->nb_vertices; - saved_model_graph->vertex = (t_vertex*)malloc(model_graph->nb_vertices * sizeof(*model_graph->vertex)); - for(i = 0;i < model_graph->nb_vertices;i++) - { - saved_model_graph->vertex[i].index = model_graph->vertex[i].index; - saved_model_graph->vertex[i].nb_in_degree_edges = model_graph->vertex[i].nb_in_degree_edges; - saved_model_graph->vertex[i].in_degree_edge = (t_edge*)malloc((y_kmax + 2) * nb_endo * sizeof(t_edge)); - for(j = 0;j < model_graph->vertex[i].nb_in_degree_edges;j++) - { - saved_model_graph->vertex[i].in_degree_edge[j].index = model_graph->vertex[i].in_degree_edge[j].index; - saved_model_graph->vertex[i].in_degree_edge[j].u_count = model_graph->vertex[i].in_degree_edge[j].u_count; - } - saved_model_graph->vertex[i].nb_out_degree_edges = model_graph->vertex[i].nb_out_degree_edges; - saved_model_graph->vertex[i].out_degree_edge = (t_edge*)malloc((y_kmax + 2) * nb_endo * sizeof(t_edge)); - for(j = 0;j < model_graph->vertex[i].nb_out_degree_edges;j++) - { - saved_model_graph->vertex[i].out_degree_edge[j].index = model_graph->vertex[i].out_degree_edge[j].index; - saved_model_graph->vertex[i].out_degree_edge[j].u_count = model_graph->vertex[i].out_degree_edge[j].u_count; - } - } -} - int ModelBlock_Graph(Model_Block *ModelBlock, int Blck_num, bool dynamic, t_model_graph* model_graph, int nb_endo, int* block_u_count, int *starting_vertex, int *periods, int *nb_table_y, int *mean_var_in_equ) { @@ -504,577 +476,3 @@ ModelBlock_Graph(Model_Block *ModelBlock, int Blck_num, bool dynamic, t_model_gr return (u_count); } } - - - - -void -IM_to_model_graph(List_IM* First_IM, int Time, int endo, int *y_kmin, int *y_kmax, t_model_graph* model_graph, int *nb_endo, int *stacked_time, double** u1, int *u_count -#ifdef VERIF - , Matrix *B, Matrix *D -#endif - ) -{ - int i, j, t, n, k, l=0, k_k_in = 0, m; - t_pList* Endo; - List_IM* Curr_IM; - int nb_IM = 0; - int Max_edge = 0; -#ifdef STACKED - - int k_block = 0; -#endif - - bool OK; - *nb_endo = endo; - Curr_IM = First_IM; - while(Curr_IM) - { - if(Curr_IM->lead_lag > *y_kmax) - *y_kmax = Curr_IM->lead_lag; - if( -Curr_IM->lead_lag > *y_kmin) - *y_kmin = -Curr_IM->lead_lag; - Curr_IM = Curr_IM->pNext; - nb_IM++; - } - Endo = (t_pList*)malloc(endo * sizeof(t_pList)); - for(i = 0;i < endo;i++) - { - Endo[i].Lag_in = (int*)malloc((*y_kmin + *y_kmax + 1) * sizeof(int)); - Endo[i].Lag_out = (int*)malloc((*y_kmin + *y_kmax + 1) * sizeof(int)); - memset(Endo[i].Lag_in, 0, (*y_kmin + *y_kmax + 1)*sizeof(int)); - memset(Endo[i].Lag_out, 0, (*y_kmin + *y_kmax + 1)*sizeof(int)); - Endo[i].CurrNb_in = Endo[i].CurrNb_out = 0; - } - Curr_IM = First_IM; - while(Curr_IM) - { - k = Curr_IM->lead_lag + *y_kmin; - for(i = 0;i < endo;i++) - for(j = 0;j < endo;j++) - if(Curr_IM->IM[i*endo + j]) - { - Endo[i].Lag_in[k]++; - Endo[j].Lag_out[k]++; - } - Curr_IM = Curr_IM->pNext; - } - for(i = 0;i < endo;i++) - { - for(j = 0;j < *y_kmax + *y_kmin + 1;j++) - { - Endo[i].CurrNb_in += Endo[i].Lag_in[j]; - Endo[i].CurrNb_out += Endo[i].Lag_out[j]; - } - if(Endo[i].CurrNb_in + 2 > Max_edge) - Max_edge = Endo[i].CurrNb_in + 2; - if(Endo[i].CurrNb_out + 2 > Max_edge) - Max_edge = Endo[i].CurrNb_out + 2; - } - *stacked_time = Time; - Max_edge = Max_edge * Max_edge; -#ifdef VERIF - - B->resize(Time*endo, Time*endo); - D->resize(Time*endo, 1); - *B = B->zeros(); - *D = D->zeros(); -#endif - - int size_c_in, size_c_out, total_edge = 0; - model_graph->nb_vertices = endo * (*stacked_time) + 1; - model_graph->vertex = (t_vertex*)malloc(model_graph->nb_vertices * sizeof(*model_graph->vertex)); - for(t = 0;t < *stacked_time;t++) - { - if(t > 0) - { - if(t <= *y_kmin) - for(i = 0;i < endo;i++) - Endo[i].CurrNb_in += Endo[i].Lag_in[*y_kmin - t]; - if(t <= *y_kmax) - for(i = 0;i < endo;i++) - Endo[i].CurrNb_out += Endo[i].Lag_out[*y_kmin + t]; - } - if(t >= (*stacked_time - *y_kmax)) - { - for(i = 0;i < endo;i++) - Endo[i].CurrNb_in -= Endo[i].Lag_in[*y_kmin + (*stacked_time - t)]; - } - if(t >= (*stacked_time - *y_kmin)) - { - for(i = 0;i < endo;i++) - Endo[i].CurrNb_out -= Endo[i].Lag_out[*y_kmin - (*stacked_time - t)]; - } - for(j = 0;j < endo;j++) - { - size_c_in = endo * (*y_kmin + *y_kmax + 1) + 2; - size_c_out = endo * (*y_kmin + *y_kmax + 1) + 2; - total_edge += size_c_out - 1; - l = t * endo + j; -#ifdef STACKED - - if(t - *y_kmax - *y_kmin - 2 > 0) - model_graph->vertex[l].index = l + (Time - *y_kmax - *y_kmin - 2) * endo; - else - model_graph->vertex[l].index = l; -#else - - model_graph->vertex[l].index = l; -#endif - - model_graph->vertex[l].in_degree_edge = (t_edge*)malloc(size_c_in * sizeof(t_edge)); - model_graph->vertex[l].out_degree_edge = (t_edge*)malloc(size_c_out * sizeof(t_edge)); - model_graph->vertex[l].nb_in_degree_edges = 0; - model_graph->vertex[l].nb_out_degree_edges = 0; - } - } - total_edge += *stacked_time * endo; - for(i = 0;i < endo;i++) - { - free(Endo[i].Lag_in); - free(Endo[i].Lag_out); - } - free(Endo); - *u1 = (double*)malloc((total_edge) * sizeof(double)); - model_graph->vertex[l + 1].in_degree_edge = (t_edge*)malloc(0 * sizeof(t_edge)); - model_graph->vertex[l + 1].out_degree_edge = (t_edge*)malloc((*stacked_time * endo) * sizeof(t_edge)); - model_graph->vertex[l + 1].index = l + 1; - model_graph->vertex[l + 1].nb_in_degree_edges = 0; - model_graph->vertex[l + 1].nb_out_degree_edges = 0; - for(t = 0;t < *stacked_time;t++) - { - Curr_IM = First_IM; - while(Curr_IM) - { - if(Curr_IM->lead_lag < 0) - { - if(t >= abs(Curr_IM->lead_lag)) - OK = 1; - else - OK = 0; - } - else - { - if(*stacked_time - t > Curr_IM->lead_lag) - OK = 1; - else - OK = 0; - } - if(OK) - { - l = (t + Curr_IM->lead_lag) * endo; - for(j = 0;j < endo;j++) - { - n = t * endo + j; - for(k = 0;k < endo;k++) - { - if(Curr_IM->IM[j*endo + k]) - { - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].index = l + k; - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].u_count = - *u_count; - (*u1)[*u_count] = (double)rand() / RAND_MAX; -#ifdef VERIF - - (*B)[n][l + k] = -(*u1)[*u_count]; -#endif - - (*u_count)++; - model_graph->vertex[n].nb_in_degree_edges++; - } - } - if(Curr_IM->lead_lag == 0) - { - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].index = - endo * (*stacked_time); - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].u_count = - *u_count; - (*u1)[*u_count] = (double)rand() / RAND_MAX; -#ifdef VERIF - - (*D)[n][0] = (*u1)[*u_count]; -#endif - - (*u_count)++; - model_graph->vertex[n].nb_in_degree_edges++; - } - k_k_in += model_graph->vertex[n].nb_in_degree_edges; - } - n = t * endo; - for(j = 0;j < endo;j++) - { - l = (t + Curr_IM->lead_lag) * endo + j; - for(k = 0;k < endo;k++) - { - if(Curr_IM->IM[k*endo + j]) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].index = n + k; - for(m = 0;m < model_graph->vertex[n + k].nb_in_degree_edges;m++) - if(model_graph->vertex[n + k].in_degree_edge[m].index == l) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].u_count = - model_graph->vertex[n + k].in_degree_edge[m].u_count; - } - model_graph->vertex[l].nb_out_degree_edges++; - } - } - } - } - Curr_IM = Curr_IM->pNext; - } - } - l = endo * (*stacked_time); - for(j = 0;j < l;j++) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].index = j; - for(m = 0;m < model_graph->vertex[j].nb_in_degree_edges;m++) - if(model_graph->vertex[j].in_degree_edge[m].index == l) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].u_count = - model_graph->vertex[j].in_degree_edge[m].u_count; - } - model_graph->vertex[l].nb_out_degree_edges++; - } - cout << "mean element by equation : " << (double)(k_k_in) / ((*stacked_time)*endo) << "\n"; -} - - -void -IM_to_model_graph_new(List_IM* First_IM, int Time, int endo, int *y_kmin, int *y_kmax, t_model_graph* model_graph, int * nb_endo, int *stacked_time, double** u1, int* u_count -#ifdef VERIF - , Matrix* B, Matrix* D -#endif - ) -{ - int i, j, t, n, k, l=0, k_k_in = 0, m, u_count_per_period, s_u_count, bi; - t_pList* Endo; - List_IM* Curr_IM; - int nb_IM = 0; - int Max_edge = 0; -#ifdef STACKED - int k_block = 0; -#endif - bool OK; - *nb_endo = endo; - Curr_IM = First_IM; - while(Curr_IM) - { - if(Curr_IM->lead_lag > *y_kmax) - *y_kmax = Curr_IM->lead_lag; - if( -Curr_IM->lead_lag > *y_kmin) - *y_kmin = -Curr_IM->lead_lag; - Curr_IM = Curr_IM->pNext; - nb_IM++; - } - Endo = (t_pList*)malloc(endo * sizeof(t_pList)); - for(i = 0;i < endo;i++) - { - Endo[i].Lag_in = (int*)malloc((*y_kmin + *y_kmax + 1) * sizeof(int)); - Endo[i].Lag_out = (int*)malloc((*y_kmin + *y_kmax + 1) * sizeof(int)); - memset(Endo[i].Lag_in, 0, (*y_kmin + *y_kmax + 1)*sizeof(int)); - memset(Endo[i].Lag_out, 0, (*y_kmin + *y_kmax + 1)*sizeof(int)); - Endo[i].CurrNb_in = Endo[i].CurrNb_out = 0; - } - Curr_IM = First_IM; - while(Curr_IM) - { - k = Curr_IM->lead_lag + *y_kmin; - for(i = 0;i < endo;i++) - for(j = 0;j < endo;j++) - if(Curr_IM->IM[i*endo + j]) - { - Endo[i].Lag_in[k]++; - Endo[j].Lag_out[k]++; - } - Curr_IM = Curr_IM->pNext; - } - for(i = 0;i < endo;i++) - { - for(j = 0;j < *y_kmax + *y_kmin + 1;j++) - { - Endo[i].CurrNb_in += Endo[i].Lag_in[j]; - Endo[i].CurrNb_out += Endo[i].Lag_out[j]; - } - if(Endo[i].CurrNb_in + 2 > Max_edge) - Max_edge = Endo[i].CurrNb_in + 2; - if(Endo[i].CurrNb_out + 2 > Max_edge) - Max_edge = Endo[i].CurrNb_out + 2; - } - *stacked_time = Time; - Max_edge = Max_edge * Max_edge; - cout << "Max_edge=" << Max_edge << "\n"; -#ifdef VERIF - B->resize(Time*endo, Time*endo); - D->resize(Time*endo, 1); - *B = B->zeros(); - *D = D->zeros(); -#endif - int size_c_in, size_c_out, total_edge = 0; - model_graph->nb_vertices = endo * (*stacked_time) + 1; - model_graph->vertex = (t_vertex*)malloc(model_graph->nb_vertices * sizeof(*model_graph->vertex)); - bi = (*y_kmin) + /*6*/20; - for(t = 0;t < *stacked_time;t++) - { - if(t > 0) - { - if(t <= *y_kmin) - for(i = 0;i < endo;i++) - Endo[i].CurrNb_in += Endo[i].Lag_in[*y_kmin - t]; - if(t <= *y_kmax) - for(i = 0;i < endo;i++) - Endo[i].CurrNb_out += Endo[i].Lag_out[*y_kmin + t]; - } - if(t >= (*stacked_time - *y_kmax)) - { - for(i = 0;i < endo;i++) - Endo[i].CurrNb_in -= Endo[i].Lag_in[*y_kmin + (*stacked_time - t)]; - } - if(t >= (*stacked_time - *y_kmin)) - { - for(i = 0;i < endo;i++) - Endo[i].CurrNb_out -= Endo[i].Lag_out[*y_kmin - (*stacked_time - t)]; - } - for(j = 0;j < endo;j++) - { - size_c_in = endo * (*y_kmin + *y_kmax + 1) + 2; - size_c_out = endo * (*y_kmin + *y_kmax + 1) + 2; - total_edge += size_c_out - 1; - l = t * endo + j; -#ifdef STACKED - if(t - *y_kmax - *y_kmin - 2 > 0) - model_graph->vertex[l].index = l + (Time - *y_kmax - *y_kmin - 2) * endo; - else - model_graph->vertex[l].index = l; -#else - model_graph->vertex[l].index = l; -#endif - if((t < bi + 1 ) || (t > *stacked_time - *y_kmax - 5)) - { - model_graph->vertex[l].in_degree_edge = (t_edge*)malloc(size_c_in * sizeof(t_edge)); - model_graph->vertex[l].out_degree_edge = (t_edge*)malloc(size_c_out * sizeof(t_edge)); - } - else - { -#ifdef PRINT_OUT - cout << "nothing allocated for l=" << l << "\n"; -#endif - model_graph->vertex[l].in_degree_edge = (t_edge*)malloc(0 * sizeof(t_edge)); - model_graph->vertex[l].out_degree_edge = (t_edge*)malloc(0 * sizeof(t_edge)); - } - model_graph->vertex[l].nb_in_degree_edges = 0; - model_graph->vertex[l].nb_out_degree_edges = 0; - } - } - total_edge += *stacked_time * endo; - for(i = 0;i < endo;i++) - { - free(Endo[i].Lag_in); - free(Endo[i].Lag_out); - } - free(Endo); - *u1 = (double*)malloc((total_edge) * sizeof(double)); - model_graph->vertex[l + 1].in_degree_edge = (t_edge*)malloc(0 * sizeof(t_edge)); - model_graph->vertex[l + 1].out_degree_edge = (t_edge*)malloc((*stacked_time * endo) * sizeof(t_edge)); - model_graph->vertex[l + 1].index = l + 1; - model_graph->vertex[l + 1].nb_in_degree_edges = 0; - model_graph->vertex[l + 1].nb_out_degree_edges = 0; - s_u_count = *u_count; - for(t = 0;t < *stacked_time;t++) - { - if((t < bi) || (t > *stacked_time - *y_kmax - 4)) - { - u_count_per_period = *u_count; - Curr_IM = First_IM; - while(Curr_IM) - { - if(Curr_IM->lead_lag < 0) - { - if(t >= abs(Curr_IM->lead_lag)) - OK = 1; - else - OK = 0; - } - else - { - if(*stacked_time - t > Curr_IM->lead_lag) - OK = 1; - else - OK = 0; - } - if(OK) - { - l = (t + Curr_IM->lead_lag) * endo; - for(j = 0;j < endo;j++) - { - n = t * endo + j; - for(k = 0;k < endo;k++) - { - if(Curr_IM->IM[j*endo + k]) - { - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].index = l + k; - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].u_count = - *u_count; - (*u1)[*u_count] = (double)rand() / RAND_MAX; -#ifdef VERIF - (*B)[n][l + k] = -(*u1)[*u_count]; -#endif - (*u_count)++; - model_graph->vertex[n].nb_in_degree_edges++; - } - } - if(Curr_IM->lead_lag == 0) - { - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].index = - endo * (*stacked_time); - model_graph->vertex[n].in_degree_edge[model_graph->vertex[n].nb_in_degree_edges].u_count = - *u_count; - (*u1)[*u_count] = (double)rand() / RAND_MAX; -#ifdef VERIF - (*D)[n][0] = (*u1)[*u_count]; -#endif - (*u_count)++; - model_graph->vertex[n].nb_in_degree_edges++; - } - k_k_in += model_graph->vertex[n].nb_in_degree_edges; - } - n = t * endo; - for(j = 0;j < endo;j++) - { - l = (t + Curr_IM->lead_lag) * endo + j; - for(k = 0;k < endo;k++) - { - if(Curr_IM->IM[k*endo + j]) - { - cout << "l=" << l << " (*stacked_time*endo)=" << (*stacked_time*endo) << " model_graph->vertex[l].nb_out_degree_edges= " << model_graph->vertex[l].nb_out_degree_edges << "\n"; - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].index = n + k; - for(m = 0;m < model_graph->vertex[n + k].nb_in_degree_edges;m++) - if(model_graph->vertex[n + k].in_degree_edge[m].index == l) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].u_count = - model_graph->vertex[n + k].in_degree_edge[m].u_count; - } - model_graph->vertex[l].nb_out_degree_edges++; - } - } - } - } - Curr_IM = Curr_IM->pNext; - } - u_count_per_period = *u_count - u_count_per_period; - } - else - { - for(j = 0;j < u_count_per_period;j++) - (*u1)[*u_count + j] = (double)rand() / RAND_MAX; - *u_count += u_count_per_period; - } - } -#ifdef VERIF - *u_count = s_u_count; - for(t = 0;t < *stacked_time;t++) - { - Curr_IM = First_IM; - while(Curr_IM) - { - if(Curr_IM->lead_lag < 0) - { - if(t >= abs(Curr_IM->lead_lag)) - OK = 1; - else - OK = 0; - } - else - { - if(*stacked_time - t > Curr_IM->lead_lag) - OK = 1; - else - OK = 0; - } - if(OK) - { - l = (t + Curr_IM->lead_lag) * endo; - for(j = 0;j < endo;j++) - { - n = t * endo + j; - for(k = 0;k < endo;k++) - { - if(Curr_IM->IM[j*endo + k]) - { - (*B)[n][l + k] = -(*u1)[*u_count]; - (*u_count)++; - } - } - if(Curr_IM->lead_lag == 0) - { - (*D)[n][0] = (*u1)[*u_count]; - (*u_count)++; - } - } - } - Curr_IM = Curr_IM->pNext; - } - } -#endif - l = endo * (*stacked_time); - for(j = 0;j < l;j++) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].index = j; - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].u_count = -1; - for(m = 0;m < model_graph->vertex[j].nb_in_degree_edges;m++) - if(model_graph->vertex[j].in_degree_edge[m].index == l) - { - model_graph->vertex[l].out_degree_edge[model_graph->vertex[l].nb_out_degree_edges].u_count = - model_graph->vertex[j].in_degree_edge[m].u_count; - } - model_graph->vertex[l].nb_out_degree_edges++; - } -} - - -void -reduce_model_graph(t_model_graph* model_graph, int pos) -{ - int i, j, k; - if(pos > 0) - { - for(i = 0;i < pos;i++) - { - free(model_graph->vertex[i].in_degree_edge); - free(model_graph->vertex[i].out_degree_edge); - } - for(i = pos;i < model_graph->nb_vertices;i++) - model_graph->vertex[i - pos] = model_graph->vertex[i]; - model_graph->nb_vertices -= pos; - for(i = 0;i < model_graph->nb_vertices;i++) - { - for(j = 0;j < model_graph->vertex[i].nb_in_degree_edges;j++) - if(model_graph->vertex[i].in_degree_edge[j].index < pos) - { - for(k = j + 1;k < model_graph->vertex[i].nb_in_degree_edges;k++) - { - model_graph->vertex[i].in_degree_edge[k - 1].index = model_graph->vertex[i].in_degree_edge[k].index; - model_graph->vertex[i].in_degree_edge[k - 1].u_count = model_graph->vertex[i].in_degree_edge[k].u_count; - } - j--; - model_graph->vertex[i].nb_in_degree_edges--; - } - else - model_graph->vertex[i].in_degree_edge[j].index -= pos; - for(j = 0;j < model_graph->vertex[i].nb_out_degree_edges;j++) - if(model_graph->vertex[i].out_degree_edge[j].index < pos) - { - for(k = j + 1;k < model_graph->vertex[i].nb_out_degree_edges;k++) - { - model_graph->vertex[i].out_degree_edge[k - 1].index = model_graph->vertex[i].out_degree_edge[k].index; - model_graph->vertex[i].out_degree_edge[k - 1].u_count = model_graph->vertex[i].out_degree_edge[k].u_count; - } - j--; - model_graph->vertex[i].nb_out_degree_edges--; - } - else - model_graph->vertex[i].out_degree_edge[j].index -= pos; - } - } -} - - diff --git a/preprocessor/SymbolGaussElim.cc b/preprocessor/SymbolGaussElim.cc index 2a17fefafc520135e983746bf19a389ac4e19d0c..f9d14ea33e2443d997922a8094af5834e0336fc1 100644 --- a/preprocessor/SymbolGaussElim.cc +++ b/preprocessor/SymbolGaussElim.cc @@ -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: - case 2: - case 6: - 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)); - SaveCode.write(reinterpret_cast<char *>(&save_i_table_u->op2), sizeof(save_i_table_u->op2)); - break; - case 5: - 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)); - break; - } - table_u = save_i_table_u->pNext; - free(save_i_table_u); - save_i_table_u = table_u; - } -#ifdef PRINT_OUT - cout << "nb_save_table_u=" << nb_save_table_u << "\n"; -#endif -} - void SymbolicGaussElimination::write_to_file_table_u_b(t_table_u *save_table_u, t_table_u *last_table_u, int *nb_save_table_u, bool chk) { @@ -1871,12 +1747,6 @@ SymbolicGaussElimination::Gaussian_Elimination(t_model_graph* model_graph free(s_j2); } -void -SymbolicGaussElimination::file_is_open1() -{ - file_open=true; -} - void SymbolicGaussElimination::file_is_open() { diff --git a/preprocessor/include/BlockTriangular.hh b/preprocessor/include/BlockTriangular.hh index c4a68f5f61eb1966860c078795e81322665057ac..323b3666a1f57db41ae58f75374f01bf347b6e6a 100644 --- a/preprocessor/include/BlockTriangular.hh +++ b/preprocessor/include/BlockTriangular.hh @@ -40,52 +40,31 @@ typedef struct List_IM bool* IM; }; - -typedef struct vari -{ - int Size; - int* arc; - int used_arc; - int available; -}; - - typedef map<pair<int ,int >,double> jacob_map; class BlockTriangular { public: BlockTriangular(const SymbolTable &symbol_table_arg); - ~BlockTriangular(); /*! The incidence matrix for each lead and lags */ const SymbolTable &symbol_table; Blocks blocks; Normalization normalization; List_IM* Build_IM(int lead_lag); List_IM* Get_IM(int lead_lag); - bool* bGet_IM(int lead_lag); bool* bGet_IM(int lead_lag) const; - void fill_IM(int equation, int variable_endo, int lead_lag); + void fill_IM(int equation, int variable_endo, int lead_lag); void unfill_IM(int equation, int variable_endo, int lead_lag); - void incidence_matrix() const; void init_incidence_matrix(int nb_endo); void Print_IM(int n) const; void Free_IM(List_IM* First_IM); void Print_SIM(bool* IM, int n) const; - void Normalize_and_BlockDecompose_Static_Model(); 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 ); 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 Normalize_and_BlockDecompose_0(); - void Normalize_and_BlockDecompose_Inside_Earth(); void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM); - void Sort_By_Cols(bool* IM, int d, int f); - void getMax_Lead_Lag(int var, int equ, int *lead, int *lag); - void getMax_Lead_Lag_B(int size, int* Equation, int *Variable, int *lead, int *lag); 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); - string getnamebyID(Type type, int id); List_IM *First_IM ; List_IM *Last_IM ; simple *Index_Equ_IM; @@ -151,42 +130,6 @@ public: break; } }; - inline static std::string BlockSim_d(int type) - { - switch (type) - { - case EVALUATE_FOREWARD: - case EVALUATE_FOREWARD_R: - return ("EVALUATE_FOREWARD "); - break; - case EVALUATE_BACKWARD: - case EVALUATE_BACKWARD_R: - return ("EVALUATE_BACKWARD "); - break; - case SOLVE_FOREWARD_SIMPLE: - return ("SOLVE_FOREWARD_SIMPLE "); - break; - case SOLVE_BACKWARD_SIMPLE: - return ("SOLVE_BACKWARD_SIMPLE "); - break; - case SOLVE_TWO_BOUNDARIES_SIMPLE: - return ("SOLVE_TWO_BOUNDARIES_SIMPLE "); - break; - case SOLVE_FOREWARD_COMPLETE: - return ("SOLVE_FOREWARD_COMPLETE "); - break; - case SOLVE_BACKWARD_COMPLETE: - return ("SOLVE_BACKWARD_COMPLETE "); - break; - case SOLVE_TWO_BOUNDARIES_COMPLETE: - return ("SOLVE_TWO_BOUNDARIES_COMPLETE"); - break; - default: - return ("UNKNOWN "); - break; - } - }; - }; //------------------------------------------------------------------------------ #endif diff --git a/preprocessor/include/ModelBlocks.hh b/preprocessor/include/ModelBlocks.hh index 6e6df343388eacc0a70a16e4c126dc5fd6879d02..c6362814225c5ca4318b515f435b070395ca6e96 100644 --- a/preprocessor/include/ModelBlocks.hh +++ b/preprocessor/include/ModelBlocks.hh @@ -37,12 +37,10 @@ class Blocks { public: Blocks(); - ~Blocks(); void block_depth_search(int v); block_result_t* sc(Equation_set *g); void block_result_free(block_result_t *r); void block_result_print(block_result_t *r); - Equation_set* Equation_gr_IM( int n , bool* IM); void Print_Equation_gr(Equation_set* Equation); void block_result_to_IM(block_result_t *r,bool* IM,int prologue, int n,simple* Index_Equ_IM,simple* Index_Var_IM); Equation_vertex *vertices; diff --git a/preprocessor/include/ModelNormalization.hh b/preprocessor/include/ModelNormalization.hh index 3d60e57b9743cc3fcf4315102f64a75bad03f5a6..e6a1c1ab649e6234503e8ac6ee42993d0de3f036 100644 --- a/preprocessor/include/ModelNormalization.hh +++ b/preprocessor/include/ModelNormalization.hh @@ -33,7 +33,7 @@ typedef struct Equation_vertex { Edge *First_Edge; Edge *Next_Edge; - int matched,index; + int matched; }; typedef struct Equation_set @@ -49,8 +49,6 @@ typedef struct simple bool available; }; -typedef std::string (*t_getNameByID)(Type type, int id); - class Normalization { private: @@ -71,10 +69,8 @@ private: }; public: Normalization(const SymbolTable &symbol_table_arg); - ~Normalization(); bool Normalize(int n, int prologue, int epilogue, bool* IM, simple* Index_Var_IM, Equation_set* Equation,bool mixing, bool* IM_s); void Gr_to_IM_basic(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation,bool transpose); - t_getNameByID getnamebyID; const SymbolTable &symbol_table; void Set_fp_verbose(bool ok); private: @@ -90,7 +86,6 @@ private: 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); - void ErrorHandling(int n, bool* IM, simple* Index_Equ_IM); int eq, eex; int IndexUnmatched; bool fp_verbose; diff --git a/preprocessor/include/Model_Graph.hh b/preprocessor/include/Model_Graph.hh index 31deb36f02cb28800c63aecf118b6683d70ba74b..5a38774d3f3eac5be9f87b10c92d114fd34353bd 100644 --- a/preprocessor/include/Model_Graph.hh +++ b/preprocessor/include/Model_Graph.hh @@ -50,34 +50,8 @@ typedef struct t_model_graph t_vertex* vertex; }; -typedef struct t_pList -{ - int* Lag_in, * Lag_out; - int CurrNb_in, CurrNb_out; -}; - - - - void free_model_graph(t_model_graph* model_graph); void print_Graph(t_model_graph* model_graph); void Check_Graph(t_model_graph* model_graph); -void copy_model_graph(t_model_graph* model_graph, t_model_graph* saved_model_graph, int nb_endo, int y_kmax); int ModelBlock_Graph(Model_Block *ModelBlock, int Blck_num,bool dynamic, t_model_graph* model_graph, int nb_endo, int *block_u_count, int *starting_vertex, int* periods, int *nb_table_y, int *mean_var_in_equ); -void IM_to_model_graph(List_IM* First_IM,int Time, int endo, int* y_kmin, int* y_kmax, t_model_graph* model_graph, int* nb_endo, int *stacked_time, double** u1, int* u_count -#ifdef VERIF - , Matrix *B, Matrix *D -#endif - ); -void IM_to_model_graph_new(List_IM* First_IM,int Time, int endo, int* y_kmin, int* y_kmax, t_model_graph* model_graph, int* nb_endo, int *stacked_time, double** u1, int* u_count -#ifdef VERIF - , Matrix *B, Matrix *D -#endif - ); -void IM_to_model_graph_new_new(List_IM* First_IM,int Time, int endo, int* y_kmin, int* y_kmax, t_model_graph* model_graph, int* nb_endo, int *stacked_time, double** u1, int* u_count -#ifdef VERIF - , Matrix *B, Matrix *D -#endif - ); -void reduce_model_graph(t_model_graph* model_graph,int pos); #endif diff --git a/preprocessor/include/SymbolGaussElim.hh b/preprocessor/include/SymbolGaussElim.hh index c47eabc4d2a2cbf7c2fcf466a276ffa9c1a8b06f..f83a8438e1914072d324239e7427bf1f99aadc00 100644 --- a/preprocessor/include/SymbolGaussElim.hh +++ b/preprocessor/include/SymbolGaussElim.hh @@ -45,8 +45,7 @@ typedef struct t_table_u class SymbolicGaussElimination { public: - int y_kmin, y_kmax, nb_endo, Time, stacked_time, u_count, periods; - double* u1; + int y_kmin, y_kmax, nb_endo, Time, u_count, periods; int *s_i1, *s_i2, *s_j2; bool nstacked, save_direct; int nb_loop_table; @@ -58,14 +57,13 @@ public: int vertex_count; t_table_u* table_u; int nb_table_u; - t_table_u *get_table_u; t_table_u* First_table_u; #endif /**DIRECT_COMPUTE**/ int starting_vertex; - t_table_u *first_u_blck, *second_u_blck, *third_u_blck, *stop_table_u, *forth_u_blck; + t_table_u *first_u_blck, *second_u_blck, *third_u_blck; int first_y_blck, second_y_blck, third_y_blck; #ifdef SAVE - t_table_u *prologue_save_table_u, *first_save_table_u, *first_save_i_table_u, *middle_save_table_u, *middle_save_i_table_u, *last_save_table_u, *save_table_u, *save_i_table_u; + t_table_u *prologue_save_table_u, *first_save_table_u, *first_save_i_table_u, *middle_save_table_u, *middle_save_i_table_u, *last_save_table_u, *save_table_u; t_table_y *prologue_save_table_y, *first_save_table_y, *first_save_i_table_y, *middle_save_table_y, *middle_save_i_table_y, *last_save_table_y; int nb_prologue_save_table_y, nb_first_save_table_y, nb_middle_save_table_y, nb_last_save_table_y; int nb_prologue_save_table_u, nb_first_save_table_u, nb_middle_save_table_u, nb_last_save_table_u, middle_count_loop; @@ -79,15 +77,12 @@ public: int MAX_FREE_U_LIST; int nb_free_u_list,nb_free_u_list1,max_nb_free_u_list1,max_nb_free_u_list; bool simplification_allowed; - void print_free_u_list(); void set_free_u_list(int index); int get_free_u_list(bool dynamic); #endif /**SIMPLIFY**/ SymbolicGaussElimination(); - void list_table_u(int pos); void init_glb(); void write_to_file_table_y( t_table_y *save_table_y, t_table_y *save_i_table_y, int nb_save_table_y, int nb_save_i_table_y); - void write_to_file_table_u(t_table_u *save_table_u,t_table_u *save_i_table_u, int nb_save_table_u); void write_to_file_table_u_b(t_table_u *save_table_u, t_table_u *last_table_u, int *nb_save_table_u, bool chk); bool Check_Regularity(t_table_u *first_u_blck, t_table_u *second_u_blck, t_table_u *third_u_blck); t_table_u* interpolation(t_model_graph* model_graph,t_table_y* table_y, int to_add, bool middle,int per); @@ -98,11 +93,8 @@ public: , string file_name #endif , bool dynamic); - int SGE_all(int endo,int Time, List_IM *First_IM); void SGE_compute(Model_Block *ModelBlock, int blck, bool dynamic, string file_name, int endo_nbr); void file_is_open(); - void file_is_open1(); - }; -//------------------------------------------------------------------------------ + #endif