ModelNormalization.hh 2.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * 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/>.
 */

#ifndef MODELNORMALIZATION
#define MODELNORMALIZATION
#include "SymbolTable.hh"
#include "CodeInterpreter.hh"


26
struct Edge
27
28
29
30
31
{
  Edge *next;
  int Vertex_Index;
};

32
struct Equation_vertex
33
34
35
{
  Edge *First_Edge;
  Edge *Next_Edge;
36
  int matched;
37
38
};

39
struct Equation_set
40
41
42
43
44
45
{
  Equation_vertex *Number;
  int size;
  int edges;
};

sebastien's avatar
sebastien committed
46
//! Stores result of block decomposition for ONE equation or ONE variable
47
struct simple
48
{
sebastien's avatar
sebastien committed
49
50
  //! New {variable, equation} index after reordering
  int index;
51
52
53
54
55
};

class Normalization
{
private:
56
  struct Variable_vertex
57
58
59
  {
    int  matched;
  };
60
  struct Variable_set
61
62
63
64
  {
    Variable_vertex *Number;
    int size;
  };
65
  struct t_Heap
66
67
68
69
70
71
72
73
74
75
76
  {
    int u;        /* vertex */
    int i_parent; /* index in t_Heap of parent vertex in tree of u */
    int v;        /* current matched of u */
  };
public:
  Normalization(const SymbolTable &symbol_table_arg);
  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);
  const SymbolTable &symbol_table;
  void Set_fp_verbose(bool ok);
77
  void Free_Equation(int n, Equation_set* Equation);
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
private:
  void IM_to_Gr(int n0, int prologue, int epilogue, bool* IM, Equation_set *Equation, Variable_set *Variable );
  void Inits(Equation_set *Equation);
  void UpdatePath(Equation_set *Equation, Variable_set *Variable, int i1, int i2);
  void FindAugmentingPaths(Equation_set *Equation, Variable_set *Variable);
  void CheapMatching(Equation_set *Equation, Variable_set *Variable);
  void MaximumMatching(Equation_set *Equation, Variable_set *Variable);
  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_Other(Variable_set* Variable);
  void Free_All(int n, Equation_set* Equation, Variable_set* Variable);
  int eq, eex;
  int IndexUnmatched;
  bool fp_verbose;
  bool* visited;
  t_Heap* Local_Heap;
};
#endif