SubModel.hh 6.45 KB
Newer Older
1
/*
2
 * Copyright © 2018-2019 Dynare Team
3 4 5 6 7 8 9 10 11 12 13
 *
 * 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
14
 * GNU General Public License for more details.SS
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
 *
 * You should have received a copy of the GNU General Public License
 * along with Dynare.  If not, see <http://www.gnu.org/licenses/>.
 */

#ifndef _SUBMODEL_HH
#define _SUBMODEL_HH

#include <set>
#include <map>
#include <vector>
#include <iostream>

#include "ExprNode.hh"
#include "SymbolTable.hh"

using namespace std;

//! A table with all Trend Component Models in the .mod file
/*!
  The unique name of the trend component model is the identifier
*/
class TrendComponentModelTable
{
private:
  SymbolTable &symbol_table;
  set<string> names;
42 43
  map<string, vector<string>> eqtags, target_eqtags;
  map<string, vector<int>> eqnums, target_eqnums, nontarget_eqnums, max_lags, lhs, target_lhs, nontarget_lhs, orig_diff_var;
44
  map<string, vector<set<pair<int, int>>>> rhs;
45
  map<string, vector<bool>> diff;
46
  map<string, vector<expr_t>> lhs_expr_t;
47
  map<string, vector<int>> target_vars;
48
  map<string, map<tuple<int, int, int>, expr_t>> AR; // AR: name -> (eqn, lag, lhs_symb_id) -> expr_t
49
  map<string, map<tuple<int, int, int>, expr_t>> A0, A0star; // EC: name -> (eqn, lag, col) -> expr_t
50
public:
51
  explicit TrendComponentModelTable(SymbolTable &symbol_table_arg);
52 53

  //! Add a trend component model
54
  void addTrendComponentModel(string name_arg, vector<string> eqtags_arg,
55
                              vector<string> target_eqtags_arg);
56 57

  inline bool isExistingTrendComponentModelName(const string &name_arg) const;
58
  inline bool empty() const;
59 60 61

  map<string, vector<string>> getEqTags() const;
  vector<string> getEqTags(const string &name_arg) const;
62
  map<string, vector<string>> getTargetEqTags() const;
63
  map<string, vector<int>> getEqNums() const;
64 65
  map<string, vector<int>> getTargetEqNums() const;
  vector<int> getTargetEqNums(const string &name_arg) const;
66 67 68 69 70 71 72
  vector<int> getEqNums(const string &name_arg) const;
  vector<int> getMaxLags(const string &name_arg) const;
  int getMaxLag(const string &name_arg) const;
  vector<int> getLhs(const string &name_arg) const;
  vector<expr_t> getLhsExprT(const string &name_arg) const;
  vector<bool> getDiff(const string &name_arg) const;
  vector<int> getOrigDiffVar(const string &name_arg) const;
73 74
  map<string, vector<int>> getNonTargetEqNums() const;
  vector<int> getNonTargetEqNums(const string &name_arg) const;
75
  vector<int> getNonTargetLhs(const string &name_arg) const;
76
  vector<int> getTargetLhs(const string &name_arg) const;
77

78
  void setVals(map<string, vector<int>> eqnums_arg, map<string, vector<int>> target_eqnums_arg,
Houtan Bastani's avatar
Houtan Bastani committed
79
               map<string, vector<int>> lhs_arg,
80
               map<string, vector<expr_t>> lhs_expr_t_arg);
81 82 83 84
  void setRhs(map<string, vector<set<pair<int, int>>>> rhs_arg);
  void setMaxLags(map<string, vector<int>> max_lags_arg);
  void setDiff(map<string, vector<bool>> diff_arg);
  void setOrigDiffVar(map<string, vector<int>> orig_diff_var_arg);
85
  void setTargetVar(map<string, vector<int>> target_vars_arg);
86
  void setAR(map<string, map<tuple<int, int, int>, expr_t>> AR_arg);
87 88
  void setA0(map<string, map<tuple<int, int, int>, expr_t>> A0_arg,
             map<string, map<tuple<int, int, int>, expr_t>> A0star_arg);
89 90

  //! Write output of this class
91
  void writeOutput(const string &basename, ostream &output) const;
92 93 94 95 96 97

  //! Write JSON Output
  void writeJsonOutput(ostream &output) const;

private:
  void checkModelName(const string &name_arg) const;
98
  void setNonTargetEqnums();
99 100 101 102 103
};

inline bool
TrendComponentModelTable::isExistingTrendComponentModelName(const string &name_arg) const
{
104
  return names.find(name_arg) != names.end();
105 106
}

107 108 109 110 111 112
inline bool
TrendComponentModelTable::empty() const
{
  return names.empty();
}

Houtan Bastani's avatar
Houtan Bastani committed
113 114 115 116 117 118 119 120

class VarModelTable
{
private:
  SymbolTable &symbol_table;
  set<string> names;
  map<string, pair<SymbolList, int>> symbol_list_and_order;
  map<string, vector<string>> eqtags;
121
  map<string, vector<int>> eqnums, max_lags, lhs, lhs_orig_symb_ids, orig_diff_var;
Houtan Bastani's avatar
Houtan Bastani committed
122
  map<string, vector<set<pair<int, int>>>> rhs;
123
  map<string, vector<bool>> diff;
Houtan Bastani's avatar
Houtan Bastani committed
124
  map<string, vector<expr_t>> lhs_expr_t;
125
  map<string, map<tuple<int, int, int>, expr_t>> AR; // AR: name -> (eqn, lag, lhs_symb_id) -> param_expr_t
Houtan Bastani's avatar
Houtan Bastani committed
126
public:
127
  explicit VarModelTable(SymbolTable &symbol_table_arg);
Houtan Bastani's avatar
Houtan Bastani committed
128

129
  //! Add a VAR model
Houtan Bastani's avatar
Houtan Bastani committed
130 131 132 133 134 135 136 137 138
  void addVarModel(string name, vector<string> eqtags,
                   pair<SymbolList, int> symbol_list_and_order_arg);

  inline bool isExistingVarModelName(const string &name_arg) const;
  inline bool empty() const;

  map<string, vector<string>> getEqTags() const;
  vector<string> getEqTags(const string &name_arg) const;
  map<string, vector<int>> getEqNums() const;
139
  vector<bool> getDiff(const string &name_arg) const;
Houtan Bastani's avatar
Houtan Bastani committed
140 141 142 143
  vector<int> getEqNums(const string &name_arg) const;
  vector<int> getMaxLags(const string &name_arg) const;
  int getMaxLag(const string &name_arg) const;
  vector<int> getLhs(const string &name_arg) const;
144
  vector<int> getLhsOrigIds(const string &name_arg) const;
Houtan Bastani's avatar
Houtan Bastani committed
145 146 147 148 149 150 151 152 153 154 155
  map<string, pair<SymbolList, int>> getSymbolListAndOrder() const;
  vector<set<pair<int, int>>> getRhs(const string &name_arg) const;
  vector<expr_t> getLhsExprT(const string &name_arg) const;

  void setEqNums(map<string, vector<int>> eqnums_arg);
  void setLhs(map<string, vector<int>> lhs_arg);
  void setRhs(map<string, vector<set<pair<int, int>>>> rhs_arg);
  void setLhsExprT(map<string, vector<expr_t>> lhs_expr_t_arg);
  void setDiff(map<string, vector<bool>> diff_arg);
  void setMaxLags(map<string, vector<int>> max_lags_arg);
  void setOrigDiffVar(map<string, vector<int>> orig_diff_var_arg);
156
  void setAR(map<string, map<tuple<int, int, int>, expr_t>> AR_arg);
Houtan Bastani's avatar
Houtan Bastani committed
157 158

  //! Write output of this class
Houtan Bastani's avatar
Houtan Bastani committed
159
  void writeOutput(const string &basename, ostream &output) const;
Houtan Bastani's avatar
Houtan Bastani committed
160 161 162 163 164 165 166 167 168 169 170

  //! Write JSON Output
  void writeJsonOutput(ostream &output) const;

private:
  void checkModelName(const string &name_arg) const;
};

inline bool
VarModelTable::isExistingVarModelName(const string &name_arg) const
{
171
  return names.find(name_arg) != names.end();
Houtan Bastani's avatar
Houtan Bastani committed
172 173 174 175 176 177 178 179
}

inline bool
VarModelTable::empty() const
{
  return names.empty();
}

180
#endif