BlockTriangular.hh 4.81 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
 * Copyright (C) 2007-2008 Dynare Team
 *
 * This file is part of Dynare.
 *
 * Dynare is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Dynare is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

20
21
#ifndef _BLOCKTRIANGULAR_HH
#define _BLOCKTRIANGULAR_HH
22
23
24
25
26
27
28
29
30

#include <string>
#include "ExprNode.hh"
#include "SymbolTable.hh"
#include "ModelNormalization.hh"
#include "ModelBlocks.hh"

#include "ExprNode.hh"

sebastien's avatar
sebastien committed
31
//! List of incidence matrix (one matrix per lead/lag)
32
struct List_IM
33
34
35
36
37
38
{
  List_IM* pNext;
  int lead_lag;
  bool* IM;
};

ferhat's avatar
ferhat committed
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66

//! create and manage the incidence matrix
class IncidenceMatrix //: SymbolTable
{
  //friend class BlockTriangular;
public:
const SymbolTable &symbol_table;
  IncidenceMatrix(const SymbolTable &symbol_table_arg);
  List_IM* Build_IM(int lead_lag, SymbolType type);
  List_IM* Get_IM(int lead_lag, SymbolType type) const;
  bool* bGet_IM(int lead_lag, SymbolType type) const;
  void fill_IM(int equation, int variable_endo, int lead_lag, SymbolType type);
  void unfill_IM(int equation, int variable_endo, int lead_lag, SymbolType type);
  void init_incidence_matrix();
  void Free_IM() const;
  List_IM* Get_First(SymbolType type) const;
  void Print_IM(SymbolType type) const;
  void Print_SIM(bool* IM, SymbolType type) const;

  void swap_IM_c(bool *SIM, int pos1, int pos2, int pos3, simple* Index_Var_IM, simple* Index_Equ_IM, int n) const;
private:
  List_IM *First_IM, *Last_IM, *First_IM_X, *Last_IM_X ;
public:
  int Model_Max_Lead, Model_Max_Lag;
  int Model_Max_Lead_Endo, Model_Max_Lag_Endo, Model_Max_Lead_Exo, Model_Max_Lag_Exo;
};


sebastien's avatar
sebastien committed
67
//! Matrix of doubles for representing jacobian
68
69
typedef map<pair<int ,int >,double> jacob_map;

sebastien's avatar
sebastien committed
70
//! Create the incidence matrix, computes prologue & epilogue, normalizes the model and computes the block decomposition
71
72
class BlockTriangular
{
ferhat's avatar
ferhat committed
73
  //friend class IncidenceMatrix;
74
75
public:
  const SymbolTable &symbol_table;
ferhat's avatar
ferhat committed
76
77
78
  BlockTriangular(const SymbolTable &symbol_table_arg);
  //BlockTriangular(const IncidenceMatrix &incidence_matrix_arg);
  //const SymbolTable &symbol_table;
79
80
  Blocks blocks;
  Normalization normalization;
ferhat's avatar
ferhat committed
81
  IncidenceMatrix incidencematrix;
82
83
  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);
84
  void Prologue_Epilogue(bool* IM, int* prologue, int* epilogue, int n, simple* Index_Var_IM, simple* Index_Equ_IM, bool* IM0);
sebastien's avatar
sebastien committed
85
  void Allocate_Block(int size, int *count_Equ, int *count_Block, BlockType type, Model_Block * ModelBlock);
86
  void Free_Block(Model_Block* ModelBlock) const;
87
88
89
90
  simple *Index_Equ_IM;
  simple *Index_Var_IM;
  int prologue, epilogue;
  bool bt_verbose;
ferhat's avatar
ferhat committed
91
  //int endo_nbr, exo_nbr;
92
  Model_Block* ModelBlock;
ferhat's avatar
ferhat committed
93
  int periods;
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
  inline static std::string BlockType0(int type)
  {
    switch (type)
      {
      case 0:
        return ("SIMULTANEOUS TIME SEPARABLE  ");
        break;
      case 1:
        return ("PROLOGUE                     ");
        break;
      case 2:
        return ("EPILOGUE                     ");
        break;
      case 3:
        return ("SIMULTANEOUS TIME UNSEPARABLE");
        break;
      default:
        return ("UNKNOWN                      ");
        break;
      }
  };
  inline static std::string BlockSim(int type)
  {
    switch (type)
      {
119
120
      case EVALUATE_FORWARD:
      case EVALUATE_FORWARD_R:
ferhat's avatar
ferhat committed
121
        return ("EVALUATE FORWARD             ");
122
123
124
125
126
        break;
      case EVALUATE_BACKWARD:
      case EVALUATE_BACKWARD_R:
        return ("EVALUATE BACKWARD            ");
        break;
127
      case SOLVE_FORWARD_SIMPLE:
ferhat's avatar
ferhat committed
128
        return ("SOLVE FORWARD SIMPLE         ");
129
130
131
132
133
134
135
        break;
      case SOLVE_BACKWARD_SIMPLE:
        return ("SOLVE BACKWARD SIMPLE        ");
        break;
      case SOLVE_TWO_BOUNDARIES_SIMPLE:
        return ("SOLVE TWO BOUNDARIES SIMPLE  ");
        break;
136
      case SOLVE_FORWARD_COMPLETE:
ferhat's avatar
ferhat committed
137
        return ("SOLVE FORWARD COMPLETE       ");
138
139
140
141
142
143
144
145
146
147
148
149
150
151
        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