2008-02-03 11:28:36 +01:00
|
|
|
/*
|
2019-04-16 11:35:31 +02:00
|
|
|
* Copyright © 2003-2019 Dynare Team
|
2008-02-03 11:28:36 +01: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
|
|
|
|
* 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 _SYMBOLTABLE_HH
|
|
|
|
#define _SYMBOLTABLE_HH
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <string>
|
2018-06-04 12:31:07 +02:00
|
|
|
#include <utility>
|
2008-02-03 11:28:36 +01:00
|
|
|
#include <vector>
|
2009-11-09 12:03:18 +01:00
|
|
|
#include <set>
|
2008-02-03 11:28:36 +01:00
|
|
|
#include <ostream>
|
2009-02-27 13:19:25 +01:00
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
#include "CodeInterpreter.hh"
|
2015-05-26 15:47:56 +02:00
|
|
|
#include "ExprNode.hh"
|
|
|
|
|
2018-06-04 14:07:13 +02:00
|
|
|
using expr_t = class ExprNode *;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
//! Types of auxiliary variables
|
2018-07-17 17:38:26 +02:00
|
|
|
enum class AuxVarType
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
2019-12-20 16:59:30 +01:00
|
|
|
endoLead = 0, //!< Substitute for endo leads >= 2
|
|
|
|
endoLag = 1, //!< Substitute for endo lags >= 2
|
|
|
|
exoLead = 2, //!< Substitute for exo leads >= 1
|
|
|
|
exoLag = 3, //!< Substitute for exo lags >= 1
|
|
|
|
expectation = 4, //!< Substitute for Expectation Operator
|
|
|
|
diffForward = 5, //!< Substitute for the differentiate of a forward variable
|
|
|
|
multiplier = 6, //!< Multipliers for FOC of Ramsey Problem
|
|
|
|
varModel = 7, //!< Variable for var_model with order > abs(min_lag()) present in model
|
|
|
|
diff = 8, //!< Variable for Diff operator
|
|
|
|
diffLag = 9, //!< Variable for timing between Diff operators
|
|
|
|
unaryOp = 10, //!< Variable for allowing the undiff operator to work when diff was taken of unary op, eg diff(log(x))
|
|
|
|
diffLead = 11 //!< Variable for timing between Diff operators
|
2009-09-30 17:10:31 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
//! Information on some auxiliary variables
|
2010-01-18 23:08:44 +01:00
|
|
|
class AuxVarInfo
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
2010-01-18 23:08:44 +01:00
|
|
|
private:
|
2009-09-30 17:10:31 +02:00
|
|
|
int symb_id; //!< Symbol ID of the auxiliary variable
|
2018-07-17 17:38:26 +02:00
|
|
|
AuxVarType type; //!< Its type
|
2010-10-20 14:47:03 +02:00
|
|
|
int orig_symb_id; //!< Symbol ID of the endo of the original model represented by this aux var. Only used for avEndoLag and avExoLag.
|
|
|
|
int orig_lead_lag; //!< Lead/lag of the endo of the original model represented by this aux var. Only used for avEndoLag and avExoLag.
|
2011-03-21 18:40:57 +01:00
|
|
|
int equation_number_for_multiplier; //!< Stores the original constraint equation number associated with this aux var. Only used for avMultiplier.
|
2015-05-26 15:47:56 +02:00
|
|
|
int information_set; //! Argument of expectation operator. Only used for avExpectation.
|
2016-03-18 14:55:14 +01:00
|
|
|
expr_t expr_node; //! Auxiliary variable definition
|
2018-10-15 11:59:15 +02:00
|
|
|
string unary_op; //! Used with AuxUnaryOp
|
2010-01-18 23:08:44 +01:00
|
|
|
public:
|
2018-10-15 11:59:15 +02:00
|
|
|
AuxVarInfo(int symb_id_arg, AuxVarType type_arg, int orig_symb_id, int orig_lead_lag, int equation_number_for_multiplier_arg, int information_set_arg, expr_t expr_node_arg, string unary_op_arg);
|
2017-06-01 19:58:32 +02:00
|
|
|
int
|
|
|
|
get_symb_id() const
|
|
|
|
{
|
|
|
|
return symb_id;
|
|
|
|
};
|
2018-07-17 17:38:26 +02:00
|
|
|
AuxVarType
|
2017-06-01 19:58:32 +02:00
|
|
|
get_type() const
|
|
|
|
{
|
|
|
|
return type;
|
|
|
|
};
|
|
|
|
int
|
2018-07-17 17:38:26 +02:00
|
|
|
get_type_id() const
|
|
|
|
{
|
|
|
|
return static_cast<int>(type);
|
|
|
|
}
|
|
|
|
int
|
2017-06-01 19:58:32 +02:00
|
|
|
get_orig_symb_id() const
|
|
|
|
{
|
|
|
|
return orig_symb_id;
|
|
|
|
};
|
|
|
|
int
|
|
|
|
get_orig_lead_lag() const
|
|
|
|
{
|
|
|
|
return orig_lead_lag;
|
|
|
|
};
|
|
|
|
int
|
|
|
|
get_equation_number_for_multiplier() const
|
|
|
|
{
|
|
|
|
return equation_number_for_multiplier;
|
|
|
|
};
|
|
|
|
int
|
|
|
|
get_information_set() const
|
|
|
|
{
|
|
|
|
return information_set;
|
|
|
|
};
|
|
|
|
expr_t
|
|
|
|
get_expr_node() const
|
|
|
|
{
|
|
|
|
return expr_node;
|
|
|
|
};
|
2018-10-15 11:59:15 +02:00
|
|
|
string
|
|
|
|
get_unary_op() const
|
|
|
|
{
|
|
|
|
return unary_op;
|
|
|
|
};
|
2009-09-30 17:10:31 +02:00
|
|
|
};
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
//! Stores the symbol table
|
|
|
|
/*!
|
2009-02-27 13:19:25 +01:00
|
|
|
A symbol is given by its name, and is internally represented by a unique integer.
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
When method freeze() is called, computes a distinct sequence of IDs for some types
|
|
|
|
(endogenous, exogenous, parameters), which are used by the Matlab/Octave functions.
|
|
|
|
We call these "type specific IDs".
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2009-01-23 11:59:37 +01:00
|
|
|
Also manages a TeX name for each symbol, which by default is an empty string.
|
2008-02-03 11:28:36 +01:00
|
|
|
*/
|
|
|
|
class SymbolTable
|
|
|
|
{
|
|
|
|
private:
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Has method freeze() been called?
|
2018-06-04 12:46:34 +02:00
|
|
|
bool frozen{false};
|
2009-02-27 13:19:25 +01:00
|
|
|
|
2018-06-04 14:31:26 +02:00
|
|
|
using symbol_table_type = map<string, int>;
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Maps strings to symbol IDs
|
2008-02-03 11:28:36 +01:00
|
|
|
symbol_table_type symbol_table;
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Maps IDs to names
|
|
|
|
vector<string> name_table;
|
|
|
|
//! Maps IDs to TeX names
|
|
|
|
vector<string> tex_name_table;
|
2013-11-15 09:46:18 +01:00
|
|
|
//! Maps IDs to string names of variables
|
|
|
|
vector<string> long_name_table;
|
2016-02-26 16:23:39 +01:00
|
|
|
//! Maps IDs to a pair containing the partition and the partition value
|
2018-06-04 14:17:36 +02:00
|
|
|
map<int, map<string, string>> partition_value_map;
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Maps IDs to types
|
|
|
|
vector<SymbolType> type_table;
|
|
|
|
|
|
|
|
//! Maps symbol IDs to type specific IDs
|
|
|
|
vector<int> type_specific_ids;
|
|
|
|
|
|
|
|
//! Maps type specific IDs of endogenous to symbol IDs
|
|
|
|
vector<int> endo_ids;
|
|
|
|
//! Maps type specific IDs of exogenous to symbol IDs
|
|
|
|
vector<int> exo_ids;
|
|
|
|
//! Maps type specific IDs of exogenous deterministic to symbol IDs
|
|
|
|
vector<int> exo_det_ids;
|
|
|
|
//! Maps type specific IDs of parameters to symbol IDs
|
|
|
|
vector<int> param_ids;
|
2009-09-30 17:10:31 +02:00
|
|
|
//! Information about auxiliary variables
|
|
|
|
vector<AuxVarInfo> aux_vars;
|
2009-10-07 16:07:13 +02:00
|
|
|
|
2009-11-09 12:03:18 +01:00
|
|
|
//! Stores the predetermined variables (by symbol IDs)
|
|
|
|
set<int> predetermined_variables;
|
|
|
|
|
2010-04-14 15:03:41 +02:00
|
|
|
//! Stores the list of observed variables
|
|
|
|
vector<int> varobs;
|
|
|
|
|
2016-10-13 18:19:38 +02:00
|
|
|
//! Stores the list of observed exogenous variables
|
|
|
|
vector<int> varexobs;
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
public:
|
|
|
|
//! Thrown when trying to access an unknown symbol (by name)
|
|
|
|
class UnknownSymbolNameException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! Symbol name
|
|
|
|
string name;
|
2018-10-04 17:18:27 +02:00
|
|
|
explicit UnknownSymbolNameException(string name_arg) : name{move(name_arg)}
|
2009-12-16 18:13:23 +01:00
|
|
|
{
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
};
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Thrown when trying to access an unknown symbol (by id)
|
2008-02-03 11:28:36 +01:00
|
|
|
class UnknownSymbolIDException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! Symbol ID
|
|
|
|
int id;
|
2018-10-04 17:18:27 +02:00
|
|
|
explicit UnknownSymbolIDException(int id_arg) : id{id_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
{
|
|
|
|
}
|
2009-02-27 13:19:25 +01:00
|
|
|
};
|
|
|
|
//! Thrown when trying to access an unknown type specific ID
|
|
|
|
class UnknownTypeSpecificIDException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
int tsid;
|
|
|
|
SymbolType type;
|
2018-10-04 17:18:27 +02:00
|
|
|
UnknownTypeSpecificIDException(int tsid_arg, SymbolType type_arg) : tsid{tsid_arg}, type{type_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
{
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
};
|
|
|
|
//! Thrown when trying to declare a symbol twice
|
|
|
|
class AlreadyDeclaredException
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
//! Symbol name
|
|
|
|
string name;
|
|
|
|
//! Was the previous declaration done with the same symbol type ?
|
|
|
|
bool same_type;
|
2018-10-04 17:18:27 +02:00
|
|
|
AlreadyDeclaredException(string name_arg, bool same_type_arg) : name{move(name_arg)}, same_type{same_type_arg}
|
2009-12-16 18:13:23 +01:00
|
|
|
{
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
};
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Thrown when table is frozen and trying to modify it
|
|
|
|
class FrozenException
|
|
|
|
{
|
|
|
|
};
|
|
|
|
//! Thrown when trying to use the result of freeze() while this method has not yet been called
|
|
|
|
class NotYetFrozenException
|
|
|
|
{
|
|
|
|
};
|
2010-10-20 14:47:03 +02:00
|
|
|
//! Thrown when searchAuxiliaryVars() failed
|
|
|
|
class SearchFailedException
|
|
|
|
{
|
|
|
|
public:
|
2016-03-18 14:55:14 +01:00
|
|
|
int orig_symb_id, orig_lead_lag, symb_id;
|
2018-10-04 17:18:27 +02:00
|
|
|
SearchFailedException(int orig_symb_id_arg, int orig_lead_lag_arg) : orig_symb_id{orig_symb_id_arg},
|
|
|
|
orig_lead_lag{orig_lead_lag_arg}
|
2010-10-20 14:47:03 +02:00
|
|
|
{
|
|
|
|
}
|
2018-10-04 17:18:27 +02:00
|
|
|
explicit SearchFailedException(int symb_id_arg) : symb_id{symb_id_arg}
|
2016-03-18 14:55:14 +01:00
|
|
|
{
|
|
|
|
}
|
2010-10-20 14:47:03 +02:00
|
|
|
};
|
2009-10-07 16:07:13 +02:00
|
|
|
|
|
|
|
private:
|
2009-10-07 18:34:42 +02:00
|
|
|
//! Factorized code for adding aux lag variables
|
2018-06-04 12:50:53 +02:00
|
|
|
int addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag, expr_t arg) noexcept(false);
|
2009-10-07 18:34:42 +02:00
|
|
|
//! Factorized code for adding aux lead variables
|
2018-06-04 12:50:53 +02:00
|
|
|
int addLeadAuxiliaryVarInternal(bool endo, int index, expr_t arg) noexcept(false);
|
2017-02-02 15:09:43 +01:00
|
|
|
//! Factorized code for Json writing
|
|
|
|
void writeJsonVarVector(ostream &output, const vector<int> &varvec) const;
|
2017-09-12 14:16:29 +02:00
|
|
|
//! Factorized code for asserting that 0 <= symb_id <= symbol_table.size()
|
2018-06-04 12:50:53 +02:00
|
|
|
inline void validateSymbID(int symb_id) const noexcept(false);
|
2009-10-07 16:07:13 +02:00
|
|
|
public:
|
2008-02-03 11:28:36 +01:00
|
|
|
//! Add a symbol
|
2009-09-30 17:10:31 +02:00
|
|
|
/*! Returns the symbol ID */
|
2018-07-31 11:48:08 +02:00
|
|
|
int addSymbol(const string &name, SymbolType type, const string &tex_name, const vector<pair<string, string>> &partition_value) noexcept(false);
|
2009-04-30 15:14:33 +02:00
|
|
|
//! Add a symbol without its TeX name (will be equal to its name)
|
2009-09-30 17:10:31 +02:00
|
|
|
/*! Returns the symbol ID */
|
2018-06-04 12:50:53 +02:00
|
|
|
int addSymbol(const string &name, SymbolType type) noexcept(false);
|
2009-10-07 16:07:13 +02:00
|
|
|
//! Adds an auxiliary variable for endogenous with lead >= 2
|
|
|
|
/*!
|
|
|
|
\param[in] index Used to construct the variable name
|
|
|
|
\return the symbol ID of the new symbol */
|
2018-06-04 12:50:53 +02:00
|
|
|
int addEndoLeadAuxiliaryVar(int index, expr_t arg) noexcept(false);
|
2009-10-07 16:07:13 +02:00
|
|
|
//! Adds an auxiliary variable for endogenous with lag >= 2
|
|
|
|
/*!
|
|
|
|
\param[in] orig_symb_id symbol ID of the endogenous declared by the user that this new variable will represent
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
\param[in] orig_lead_lag lag value such that this new variable will be equivalent to orig_symb_id(orig_lead_lag)
|
2009-10-07 16:07:13 +02:00
|
|
|
\return the symbol ID of the new symbol */
|
2018-06-04 12:50:53 +02:00
|
|
|
int addEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t arg) noexcept(false);
|
2009-10-07 16:07:13 +02:00
|
|
|
//! Adds an auxiliary variable for endogenous with lead >= 1
|
|
|
|
/*!
|
2009-10-07 18:34:42 +02:00
|
|
|
\param[in] index Used to construct the variable name
|
2009-10-07 16:07:13 +02:00
|
|
|
\return the symbol ID of the new symbol */
|
2018-06-04 12:50:53 +02:00
|
|
|
int addExoLeadAuxiliaryVar(int index, expr_t arg) noexcept(false);
|
2009-10-07 16:07:13 +02:00
|
|
|
//! Adds an auxiliary variable for exogenous with lag >= 1
|
|
|
|
/*!
|
|
|
|
\param[in] orig_symb_id symbol ID of the exogenous declared by the user that this new variable will represent
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
\param[in] orig_lead_lag lag value such that this new variable will be equivalent to orig_symb_id(orig_lead_lag)
|
2009-10-07 16:07:13 +02:00
|
|
|
\return the symbol ID of the new symbol */
|
2018-06-04 12:50:53 +02:00
|
|
|
int addExoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t arg) noexcept(false);
|
2009-11-09 16:13:47 +01:00
|
|
|
//! Adds an auxiliary variable for the expectation operator
|
2009-10-29 18:16:10 +01:00
|
|
|
/*!
|
2009-11-09 16:13:47 +01:00
|
|
|
\param[in] information_set information set (possibly negative) of the expectation operator
|
|
|
|
\param[in] index Used to construct the variable name
|
|
|
|
\return the symbol ID of the new symbol
|
|
|
|
*/
|
2018-06-04 12:50:53 +02:00
|
|
|
int addExpectationAuxiliaryVar(int information_set, int index, expr_t arg) noexcept(false);
|
2011-03-21 18:40:57 +01:00
|
|
|
//! Adds an auxiliary variable for the multiplier for the FOCs of the Ramsey Problem
|
|
|
|
/*!
|
|
|
|
\param[in] index Used to construct the variable name
|
|
|
|
\return the symbol ID of the new symbol
|
|
|
|
*/
|
2018-06-04 12:50:53 +02:00
|
|
|
int addMultiplierAuxiliaryVar(int index) noexcept(false);
|
2013-04-25 18:09:31 +02:00
|
|
|
//! Adds an auxiliary variable for the (time) differentiate of a forward var
|
|
|
|
/*!
|
|
|
|
\param[in] orig_symb_id The symb_id of the forward variable
|
|
|
|
\return the symbol ID of the new symbol
|
|
|
|
*/
|
2018-06-04 12:50:53 +02:00
|
|
|
int addDiffForwardAuxiliaryVar(int orig_symb_id, expr_t arg) noexcept(false);
|
2010-10-20 14:47:03 +02:00
|
|
|
//! Searches auxiliary variables which are substitutes for a given symbol_id and lead/lag
|
2010-09-10 11:43:48 +02:00
|
|
|
/*!
|
2010-10-20 14:47:03 +02:00
|
|
|
The search is only performed among auxiliary variables of endo/exo lag.
|
|
|
|
\return the symbol ID of the auxiliary variable
|
|
|
|
Throws an exception if match not found.
|
2010-09-10 11:43:48 +02:00
|
|
|
*/
|
2018-06-04 12:50:53 +02:00
|
|
|
int searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const noexcept(false);
|
2018-02-15 17:06:30 +01:00
|
|
|
//! Serches aux_vars for the aux var represented by aux_var_symb_id and returns its associated orig_symb_id
|
2018-06-04 12:50:53 +02:00
|
|
|
int getOrigSymbIdForAuxVar(int aux_var_symb_id) const noexcept(false);
|
2018-09-07 10:56:40 +02:00
|
|
|
//! Searches for diff aux var and finds the original lag associated with this variable
|
|
|
|
int getOrigLeadLagForDiffAuxVar(int diff_aux_var_symb_id) const noexcept(false);
|
|
|
|
//! Searches for diff aux var and finds the symb id associated with this variable
|
|
|
|
int getOrigSymbIdForDiffAuxVar(int diff_aux_var_symb_id) const noexcept(false);
|
2016-11-25 17:15:13 +01:00
|
|
|
//! Adds an auxiliary variable when var_model is used with an order that is greater in absolute value
|
|
|
|
//! than the largest lag present in the model.
|
2018-06-04 12:50:53 +02:00
|
|
|
int addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) noexcept(false);
|
2018-01-30 10:06:56 +01:00
|
|
|
//! Adds an auxiliary variable when the diff operator is encountered
|
2018-06-04 12:50:53 +02:00
|
|
|
int addDiffAuxiliaryVar(int index, expr_t expr_arg) noexcept(false);
|
|
|
|
int addDiffAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) noexcept(false);
|
2018-05-15 14:18:42 +02:00
|
|
|
//! Takes care of timing between diff statements
|
2018-06-04 12:50:53 +02:00
|
|
|
int addDiffLagAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lag) noexcept(false);
|
2019-02-15 12:52:46 +01:00
|
|
|
//! Takes care of timing between diff statements
|
|
|
|
int addDiffLeadAuxiliaryVar(int index, expr_t expr_arg, int orig_symb_id, int orig_lead) noexcept(false);
|
2018-05-30 16:48:08 +02:00
|
|
|
//! An Auxiliary variable for a unary op
|
2018-10-15 11:59:15 +02:00
|
|
|
int addUnaryOpAuxiliaryVar(int index, expr_t expr_arg, string unary_op, int orig_symb_id = -1, int orig_lag = 0) noexcept(false);
|
2010-09-10 11:43:48 +02:00
|
|
|
//! Returns the number of auxiliary variables
|
2017-06-01 19:58:32 +02:00
|
|
|
int
|
|
|
|
AuxVarsSize() const
|
|
|
|
{
|
|
|
|
return aux_vars.size();
|
|
|
|
};
|
2016-03-18 14:55:14 +01:00
|
|
|
//! Retruns expr_node for an auxiliary variable
|
2018-06-04 12:50:53 +02:00
|
|
|
expr_t getAuxiliaryVarsExprNode(int symb_id) const noexcept(false);
|
2008-02-03 11:28:36 +01:00
|
|
|
//! Tests if symbol already exists
|
|
|
|
inline bool exists(const string &name) const;
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get symbol name (by ID)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline string getName(int id) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get TeX name
|
2018-06-04 12:50:53 +02:00
|
|
|
inline string getTeXName(int id) const noexcept(false);
|
2013-11-15 09:46:18 +01:00
|
|
|
//! Get long name
|
2018-06-04 12:50:53 +02:00
|
|
|
inline string getLongName(int id) const noexcept(false);
|
2016-02-26 16:23:39 +01:00
|
|
|
//! Returns true if the partition name is the first encountered for the type of variable represented by id
|
2018-06-04 12:50:53 +02:00
|
|
|
bool isFirstOfPartitionForType(int id) const noexcept(false);
|
2016-06-24 17:38:54 +02:00
|
|
|
//! Returns a list of partitions and symbols that belong to that partition
|
2018-07-18 16:58:16 +02:00
|
|
|
map<string, map<int, string>> getPartitionsForType(SymbolType st) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get type (by ID)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline SymbolType getType(int id) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get type (by name)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline SymbolType getType(const string &name) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get ID (by name)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int getID(const string &name) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get ID (by type specific ID)
|
2018-06-04 12:50:53 +02:00
|
|
|
int getID(SymbolType type, int tsid) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Freeze symbol table
|
2018-06-04 12:50:53 +02:00
|
|
|
void freeze() noexcept(false);
|
2017-02-02 15:09:43 +01:00
|
|
|
//! unreeze symbol table
|
|
|
|
//! Used after having written JSON files
|
|
|
|
void unfreeze();
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Change the type of a symbol
|
2018-06-04 12:50:53 +02:00
|
|
|
void changeType(int id, SymbolType newtype) noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get type specific ID (by symbol ID)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int getTypeSpecificID(int id) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get type specific ID (by symbol name)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int getTypeSpecificID(const string &name) const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get number of endogenous variables
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int endo_nbr() const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get number of exogenous variables
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int exo_nbr() const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get number of exogenous deterministic variables
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int exo_det_nbr() const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Get number of parameters
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int param_nbr() const noexcept(false);
|
2009-02-27 13:19:25 +01:00
|
|
|
//! Returns the greatest symbol ID (the smallest is zero)
|
|
|
|
inline int maxID();
|
2010-04-23 18:36:51 +02:00
|
|
|
//! Get number of user-declared endogenous variables (without the auxiliary variables)
|
2018-06-04 12:50:53 +02:00
|
|
|
inline int orig_endo_nbr() const noexcept(false);
|
2008-02-03 11:28:36 +01:00
|
|
|
//! Write output of this class
|
2018-06-04 12:50:53 +02:00
|
|
|
void writeOutput(ostream &output) const noexcept(false);
|
2017-02-02 15:09:43 +01:00
|
|
|
//! Write JSON Output
|
|
|
|
void writeJsonOutput(ostream &output) const;
|
2015-07-21 17:47:56 +02:00
|
|
|
//! Write Julia output of this class
|
2018-06-04 12:50:53 +02:00
|
|
|
void writeJuliaOutput(ostream &output) const noexcept(false);
|
2009-11-09 12:03:18 +01:00
|
|
|
//! Mark a symbol as predetermined variable
|
2018-06-04 12:50:53 +02:00
|
|
|
void markPredetermined(int symb_id) noexcept(false);
|
2009-11-09 12:03:18 +01:00
|
|
|
//! Test if a given symbol is a predetermined variable
|
2018-06-04 12:50:53 +02:00
|
|
|
bool isPredetermined(int symb_id) const noexcept(false);
|
2009-11-09 12:03:18 +01:00
|
|
|
//! Return the number of predetermined variables
|
|
|
|
int predeterminedNbr() const;
|
2010-04-14 15:03:41 +02:00
|
|
|
//! Add an observed variable
|
2018-06-04 12:50:53 +02:00
|
|
|
void addObservedVariable(int symb_id) noexcept(false);
|
2010-04-14 15:03:41 +02:00
|
|
|
//! Return the number of observed variables
|
|
|
|
int observedVariablesNbr() const;
|
|
|
|
//! Is a given symbol in the set of observed variables
|
|
|
|
bool isObservedVariable(int symb_id) const;
|
|
|
|
//! Return the index of a given observed variable in the vector of all observed variables
|
|
|
|
int getObservedVariableIndex(int symb_id) const;
|
2016-10-13 18:19:38 +02:00
|
|
|
//! Add an observed exogenous variable
|
2018-06-04 12:50:53 +02:00
|
|
|
void addObservedExogenousVariable(int symb_id) noexcept(false);
|
2016-10-13 18:19:38 +02:00
|
|
|
//! Return the number of observed exogenous variables
|
|
|
|
int observedExogenousVariablesNbr() const;
|
|
|
|
//! Is a given symbol in the set of observed exogenous variables
|
|
|
|
bool isObservedExogenousVariable(int symb_id) const;
|
|
|
|
//! Return the index of a given observed exogenous variable in the vector of all observed variables
|
|
|
|
int getObservedExogenousVariableIndex(int symb_id) const;
|
2010-10-15 19:05:16 +02:00
|
|
|
vector <int> getTrendVarIds() const;
|
2012-10-31 15:23:02 +01:00
|
|
|
//! Get list of exogenous variables
|
|
|
|
set <int> getExogenous() const;
|
2016-10-14 16:35:15 +02:00
|
|
|
//! Get list of exogenous variables
|
|
|
|
set <int> getObservedExogenous() const;
|
2012-10-31 15:23:02 +01:00
|
|
|
//! Get list of endogenous variables
|
|
|
|
set <int> getEndogenous() const;
|
2014-02-24 17:27:19 +01:00
|
|
|
//! Is a given symbol an auxiliary variable
|
|
|
|
bool isAuxiliaryVariable(int symb_id) const;
|
2016-03-21 11:51:48 +01:00
|
|
|
//! Is a given symbol an auxiliary variable but not a Lagrange multiplier
|
|
|
|
bool isAuxiliaryVariableButNotMultiplier(int symb_id) const;
|
2019-03-15 14:06:02 +01:00
|
|
|
//! Is a given symbol a diff, diff lead, or diff lag auxiliary variable
|
|
|
|
bool isDiffAuxiliaryVariable(int symb_id) const;
|
2014-02-24 17:27:19 +01:00
|
|
|
//! Get list of endogenous variables without aux vars
|
|
|
|
set <int> getOrigEndogenous() const;
|
2019-03-20 17:54:23 +01:00
|
|
|
//! Returns the original symbol corresponding to this variable
|
|
|
|
/* If symb_id is not an auxiliary var, returns symb_id. Otherwise,
|
|
|
|
repeatedly call getOrigSymbIDForAuxVar() until an original
|
|
|
|
(non-auxiliary) variable is found. */
|
|
|
|
int getUltimateOrigSymbID(int symb_id) const;
|
2020-01-06 18:26:35 +01:00
|
|
|
//! If this is a Lagrange multiplier, return its associated equation number; otherwise return -1
|
|
|
|
int getEquationNumberForMultiplier(int symb_id) const;
|
2008-02-03 11:28:36 +01:00
|
|
|
};
|
|
|
|
|
2017-09-12 14:16:29 +02:00
|
|
|
inline void
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::validateSymbID(int symb_id) const noexcept(false)
|
2017-09-12 14:16:29 +02:00
|
|
|
{
|
2019-04-23 11:07:32 +02:00
|
|
|
if (symb_id < 0 || symb_id > static_cast<int>(symbol_table.size()))
|
2017-09-12 14:16:29 +02:00
|
|
|
throw UnknownSymbolIDException(symb_id);
|
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
inline bool
|
|
|
|
SymbolTable::exists(const string &name) const
|
|
|
|
{
|
2019-12-16 19:42:59 +01:00
|
|
|
return symbol_table.find(name) != symbol_table.end();
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline string
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getName(int id) const noexcept(false)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2017-09-12 14:16:29 +02:00
|
|
|
validateSymbID(id);
|
|
|
|
return name_table[id];
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline string
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getTeXName(int id) const noexcept(false)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2017-09-12 14:16:29 +02:00
|
|
|
validateSymbID(id);
|
|
|
|
return tex_name_table[id];
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
2013-11-15 09:46:18 +01:00
|
|
|
inline string
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getLongName(int id) const noexcept(false)
|
2013-11-15 09:46:18 +01:00
|
|
|
{
|
2017-09-12 14:16:29 +02:00
|
|
|
validateSymbID(id);
|
|
|
|
return long_name_table[id];
|
2013-11-15 09:46:18 +01:00
|
|
|
}
|
|
|
|
|
2008-10-17 12:20:19 +02:00
|
|
|
inline SymbolType
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getType(int id) const noexcept(false)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2017-09-12 14:16:29 +02:00
|
|
|
validateSymbID(id);
|
|
|
|
return type_table[id];
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline SymbolType
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getType(const string &name) const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
return getType(getID(name));
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getID(const string &name) const noexcept(false)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2019-12-16 19:42:59 +01:00
|
|
|
if (auto iter = symbol_table.find(name);
|
|
|
|
iter != symbol_table.end())
|
2009-02-27 13:19:25 +01:00
|
|
|
return iter->second;
|
2008-02-03 11:28:36 +01:00
|
|
|
else
|
|
|
|
throw UnknownSymbolNameException(name);
|
|
|
|
}
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getTypeSpecificID(int id) const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
2017-09-12 14:16:29 +02:00
|
|
|
validateSymbID(id);
|
2009-02-27 13:19:25 +01:00
|
|
|
|
|
|
|
return type_specific_ids[id];
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::getTypeSpecificID(const string &name) const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
return getTypeSpecificID(getID(name));
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::endo_nbr() const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
return endo_ids.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::exo_nbr() const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
return exo_ids.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::exo_det_nbr() const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
return exo_det_ids.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::param_nbr() const noexcept(false)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
return param_ids.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int
|
|
|
|
SymbolTable::maxID()
|
|
|
|
{
|
2017-09-12 14:01:25 +02:00
|
|
|
return symbol_table.size() - 1;
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
|
|
|
|
2010-04-23 18:36:51 +02:00
|
|
|
inline int
|
2018-06-04 12:50:53 +02:00
|
|
|
SymbolTable::orig_endo_nbr() const noexcept(false)
|
2010-04-23 18:36:51 +02:00
|
|
|
{
|
2019-12-16 19:42:59 +01:00
|
|
|
return endo_nbr() - aux_vars.size();
|
2010-04-23 18:36:51 +02:00
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
#endif
|