2018-08-14 14:23:21 +02:00
|
|
|
/*
|
2021-07-01 16:16:04 +02:00
|
|
|
* Copyright © 2018-2021 Dynare Team
|
2018-08-14 14:23:21 +02:00
|
|
|
*
|
|
|
|
* 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
|
2018-09-13 12:21:23 +02:00
|
|
|
* GNU General Public License for more details.SS
|
2018-08-14 14:23:21 +02:00
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
2021-06-09 16:52:20 +02:00
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2018-08-14 14:23:21 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _SUBMODEL_HH
|
|
|
|
#define _SUBMODEL_HH
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
#include "ExprNode.hh"
|
|
|
|
#include "SymbolTable.hh"
|
2019-12-19 16:38:46 +01:00
|
|
|
#include "SymbolList.hh"
|
2018-08-14 14:23:21 +02:00
|
|
|
|
|
|
|
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;
|
2018-09-13 12:21:23 +02:00
|
|
|
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;
|
2018-08-14 14:23:21 +02:00
|
|
|
map<string, vector<set<pair<int, int>>>> rhs;
|
2018-10-24 15:57:07 +02:00
|
|
|
map<string, vector<bool>> diff;
|
2018-08-14 14:23:21 +02:00
|
|
|
map<string, vector<expr_t>> lhs_expr_t;
|
2018-09-13 12:21:23 +02:00
|
|
|
map<string, vector<int>> target_vars;
|
2021-07-01 16:16:04 +02:00
|
|
|
map<string, map<tuple<int, int, int>, expr_t>> AR; // name -> (eqn, lag, lhs_symb_id) -> expr_t
|
|
|
|
map<string, map<tuple<int, int, int>, expr_t>> A0, A0star; // name -> (eqn, lag, col) -> expr_t
|
2018-08-14 14:23:21 +02:00
|
|
|
public:
|
2018-10-04 15:17:13 +02:00
|
|
|
explicit TrendComponentModelTable(SymbolTable &symbol_table_arg);
|
2018-08-14 14:23:21 +02:00
|
|
|
|
|
|
|
//! Add a trend component model
|
2018-08-22 09:15:00 +02:00
|
|
|
void addTrendComponentModel(string name_arg, vector<string> eqtags_arg,
|
2018-09-13 12:21:23 +02:00
|
|
|
vector<string> target_eqtags_arg);
|
2018-08-14 14:23:21 +02:00
|
|
|
|
|
|
|
inline bool isExistingTrendComponentModelName(const string &name_arg) const;
|
2018-08-22 09:15:00 +02:00
|
|
|
inline bool empty() const;
|
2018-08-14 14:23:21 +02:00
|
|
|
|
2021-07-01 16:16:04 +02:00
|
|
|
const map<string, vector<string>> &getEqTags() const;
|
|
|
|
const vector<string> &getEqTags(const string &name_arg) const;
|
|
|
|
const map<string, vector<string>> &getTargetEqTags() const;
|
|
|
|
const map<string, vector<int>> &getEqNums() const;
|
|
|
|
const map<string, vector<int>> &getTargetEqNums() const;
|
|
|
|
const vector<int> &getTargetEqNums(const string &name_arg) const;
|
|
|
|
const vector<int> &getEqNums(const string &name_arg) const;
|
|
|
|
const vector<int> &getMaxLags(const string &name_arg) const;
|
2018-08-14 14:23:21 +02:00
|
|
|
int getMaxLag(const string &name_arg) const;
|
2021-07-01 16:16:04 +02:00
|
|
|
const vector<int> &getLhs(const string &name_arg) const;
|
|
|
|
const vector<expr_t> &getLhsExprT(const string &name_arg) const;
|
|
|
|
const vector<bool> &getDiff(const string &name_arg) const;
|
|
|
|
const vector<int> &getOrigDiffVar(const string &name_arg) const;
|
|
|
|
const map<string, vector<int>> &getNonTargetEqNums() const;
|
|
|
|
const vector<int> &getNonTargetEqNums(const string &name_arg) const;
|
|
|
|
const vector<int> &getNonTargetLhs(const string &name_arg) const;
|
|
|
|
const vector<int> &getTargetLhs(const string &name_arg) const;
|
2018-08-14 14:23:21 +02:00
|
|
|
|
2018-09-13 12:21:23 +02:00
|
|
|
void setVals(map<string, vector<int>> eqnums_arg, map<string, vector<int>> target_eqnums_arg,
|
2018-09-12 11:56:04 +02:00
|
|
|
map<string, vector<int>> lhs_arg,
|
2018-10-24 15:57:07 +02:00
|
|
|
map<string, vector<expr_t>> lhs_expr_t_arg);
|
2018-08-14 14:23:21 +02:00
|
|
|
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);
|
2018-09-13 12:21:23 +02:00
|
|
|
void setTargetVar(map<string, vector<int>> target_vars_arg);
|
2018-09-07 10:56:40 +02:00
|
|
|
void setAR(map<string, map<tuple<int, int, int>, expr_t>> AR_arg);
|
2019-02-19 12:08:00 +01:00
|
|
|
void setA0(map<string, map<tuple<int, int, int>, expr_t>> A0_arg,
|
|
|
|
map<string, map<tuple<int, int, int>, expr_t>> A0star_arg);
|
2018-08-14 14:23:21 +02:00
|
|
|
|
|
|
|
//! Write output of this class
|
2018-09-07 10:56:40 +02:00
|
|
|
void writeOutput(const string &basename, ostream &output) const;
|
2018-08-14 14:23:21 +02:00
|
|
|
|
|
|
|
//! Write JSON Output
|
|
|
|
void writeJsonOutput(ostream &output) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
void checkModelName(const string &name_arg) const;
|
2018-09-13 12:21:23 +02:00
|
|
|
void setNonTargetEqnums();
|
2018-08-14 14:23:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
TrendComponentModelTable::isExistingTrendComponentModelName(const string &name_arg) const
|
|
|
|
{
|
2019-03-19 17:36:35 +01:00
|
|
|
return names.find(name_arg) != names.end();
|
2018-08-14 14:23:21 +02:00
|
|
|
}
|
|
|
|
|
2018-08-22 09:15:00 +02:00
|
|
|
inline bool
|
|
|
|
TrendComponentModelTable::empty() const
|
|
|
|
{
|
|
|
|
return names.empty();
|
|
|
|
}
|
|
|
|
|
2018-08-21 11:46:59 +02:00
|
|
|
class VarModelTable
|
|
|
|
{
|
|
|
|
private:
|
|
|
|
SymbolTable &symbol_table;
|
|
|
|
set<string> names;
|
|
|
|
map<string, vector<string>> eqtags;
|
2019-03-14 17:20:45 +01:00
|
|
|
map<string, vector<int>> eqnums, max_lags, lhs, lhs_orig_symb_ids, orig_diff_var;
|
2021-07-01 16:16:04 +02:00
|
|
|
map<string, vector<set<pair<int, int>>>> rhs; // name -> for each equation: set of pairs (var, lag)
|
2018-10-24 15:57:07 +02:00
|
|
|
map<string, vector<bool>> diff;
|
2018-08-21 11:46:59 +02:00
|
|
|
map<string, vector<expr_t>> lhs_expr_t;
|
2021-07-01 16:16:04 +02:00
|
|
|
map<string, map<tuple<int, int, int>, expr_t>> AR; // name -> (eqn, lag, lhs_symb_id) -> param_expr_t
|
2018-08-21 11:46:59 +02:00
|
|
|
public:
|
2018-10-04 15:17:13 +02:00
|
|
|
explicit VarModelTable(SymbolTable &symbol_table_arg);
|
2018-08-21 11:46:59 +02:00
|
|
|
|
2018-09-07 10:56:40 +02:00
|
|
|
//! Add a VAR model
|
2021-07-07 15:08:17 +02:00
|
|
|
void addVarModel(string name, vector<string> eqtags);
|
2018-08-21 11:46:59 +02:00
|
|
|
|
|
|
|
inline bool isExistingVarModelName(const string &name_arg) const;
|
|
|
|
inline bool empty() const;
|
|
|
|
|
2021-07-01 16:16:04 +02:00
|
|
|
const map<string, vector<string>> &getEqTags() const;
|
|
|
|
const vector<string> &getEqTags(const string &name_arg) const;
|
|
|
|
const map<string, vector<int>> &getEqNums() const;
|
|
|
|
const vector<bool> &getDiff(const string &name_arg) const;
|
|
|
|
const vector<int> &getEqNums(const string &name_arg) const;
|
|
|
|
const vector<int> &getMaxLags(const string &name_arg) const;
|
2018-08-21 11:46:59 +02:00
|
|
|
int getMaxLag(const string &name_arg) const;
|
2021-07-01 16:16:04 +02:00
|
|
|
const vector<int> &getLhs(const string &name_arg) const;
|
|
|
|
const vector<int> &getLhsOrigIds(const string &name_arg) const;
|
|
|
|
const vector<set<pair<int, int>>> &getRhs(const string &name_arg) const;
|
|
|
|
const vector<expr_t> &getLhsExprT(const string &name_arg) const;
|
2018-08-21 11:46:59 +02:00
|
|
|
|
|
|
|
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);
|
2018-09-07 10:14:18 +02:00
|
|
|
void setAR(map<string, map<tuple<int, int, int>, expr_t>> AR_arg);
|
2018-08-21 11:46:59 +02:00
|
|
|
|
|
|
|
//! Write output of this class
|
2018-09-06 17:53:07 +02:00
|
|
|
void writeOutput(const string &basename, ostream &output) const;
|
2018-08-21 11:46:59 +02:00
|
|
|
|
|
|
|
//! 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
|
|
|
|
{
|
2019-03-19 17:36:35 +01:00
|
|
|
return names.find(name_arg) != names.end();
|
2018-08-21 11:46:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
inline bool
|
|
|
|
VarModelTable::empty() const
|
|
|
|
{
|
|
|
|
return names.empty();
|
|
|
|
}
|
|
|
|
|
2018-08-14 14:23:21 +02:00
|
|
|
#endif
|