2013-03-22 16:34:50 +01:00
|
|
|
/*
|
2023-01-17 13:50:16 +01:00
|
|
|
* Copyright © 2007-2023 Dynare Team
|
2013-03-22 16:34:50 +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
|
2021-06-09 17:33:48 +02:00
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2013-03-22 16:34:50 +01:00
|
|
|
*/
|
|
|
|
|
2022-07-29 12:40:33 +02:00
|
|
|
#ifndef _EVALUATE_HH
|
|
|
|
#define _EVALUATE_HH
|
2013-03-22 16:34:50 +01:00
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
#include <string>
|
2022-07-29 12:58:10 +02:00
|
|
|
#include <map>
|
2022-07-29 14:30:45 +02:00
|
|
|
#include <optional>
|
2023-02-21 22:58:45 +01:00
|
|
|
#include <memory>
|
2023-02-23 17:21:22 +01:00
|
|
|
#include <filesystem>
|
2021-02-09 15:55:36 +01:00
|
|
|
|
2022-06-16 18:05:00 +02:00
|
|
|
#include "Bytecode.hh"
|
2022-07-29 12:58:10 +02:00
|
|
|
#include "BasicSymbolTable.hh"
|
|
|
|
|
2023-02-23 17:21:22 +01:00
|
|
|
class Evaluate
|
2023-02-21 22:02:21 +01:00
|
|
|
{
|
|
|
|
private:
|
2023-02-23 17:21:22 +01:00
|
|
|
using instructions_list_t = vector<BytecodeInstruction *>;
|
|
|
|
using it_code_type = instructions_list_t::const_iterator;
|
|
|
|
|
|
|
|
// Memory copy of the contents of the .cod file
|
|
|
|
unique_ptr<char[]> raw_bytecode;
|
|
|
|
|
|
|
|
/* Owns read instructions that have their specialized deserializing
|
|
|
|
constructors (and are thus not part of the “code” memory block) */
|
2023-02-21 22:58:45 +01:00
|
|
|
vector<unique_ptr<BytecodeInstruction>> deserialized_special_instrs;
|
2023-02-21 22:02:21 +01:00
|
|
|
|
2023-02-23 17:21:22 +01:00
|
|
|
/* List of deserialized instructions
|
|
|
|
Those are either pointers inside “raw_bytecode” or “deserialized_special_instrs” */
|
|
|
|
instructions_list_t instructions_list;
|
|
|
|
|
|
|
|
// Number of blocks in the model
|
|
|
|
int nb_blocks {0};
|
|
|
|
|
|
|
|
// Index of beginnings of blocks within instructions_list
|
|
|
|
vector<size_t> begin_block;
|
|
|
|
|
2022-07-29 12:58:10 +02:00
|
|
|
ExpressionType EQN_type;
|
|
|
|
int EQN_equation, EQN_block, EQN_dvar1;
|
2013-03-22 16:34:50 +01:00
|
|
|
int EQN_lag1, EQN_lag2, EQN_lag3;
|
2022-07-25 16:20:19 +02:00
|
|
|
map<int, double> TEF;
|
|
|
|
map<pair<int, int>, double> TEFD;
|
|
|
|
map<tuple<int, int, int>, double> TEFDD;
|
|
|
|
|
2022-07-29 12:58:10 +02:00
|
|
|
string error_location(it_code_type expr_begin, it_code_type faulty_op, bool steady_state, int it_) const;
|
|
|
|
|
2023-02-23 23:37:08 +01:00
|
|
|
FBEGINBLOCK_ *
|
|
|
|
currentBlockTag() const
|
|
|
|
{
|
|
|
|
return reinterpret_cast<FBEGINBLOCK_ *>(instructions_list[begin_block[block_num]]);
|
|
|
|
}
|
|
|
|
|
2023-02-24 20:30:15 +01:00
|
|
|
// Returns iterator to first instruction in the current block (after FBEGINBLOCK)
|
|
|
|
it_code_type
|
|
|
|
currentBlockBeginning()
|
|
|
|
{
|
|
|
|
return instructions_list.begin() + begin_block[block_num] + 1;
|
|
|
|
}
|
|
|
|
|
2013-03-22 16:34:50 +01:00
|
|
|
protected:
|
2022-07-29 12:58:10 +02:00
|
|
|
BasicSymbolTable &symbol_table;
|
|
|
|
int EQN_block_number;
|
2022-07-25 16:20:19 +02:00
|
|
|
double *y, *ya;
|
|
|
|
int y_size;
|
|
|
|
double *T;
|
2023-02-17 19:46:41 +01:00
|
|
|
int nb_row_x;
|
2022-07-25 16:20:19 +02:00
|
|
|
int y_kmin, y_kmax, periods;
|
|
|
|
double *x, *params;
|
|
|
|
double *u;
|
2023-02-17 19:46:41 +01:00
|
|
|
double *steady_y;
|
2022-07-25 16:20:19 +02:00
|
|
|
double *g1, *r, *res;
|
2023-01-17 13:50:16 +01:00
|
|
|
vector<mxArray *> jacobian_block, jacobian_exo_block, jacobian_det_exo_block;
|
2013-03-22 16:34:50 +01:00
|
|
|
mxArray *GlobalTemporaryTerms;
|
2023-04-06 18:44:22 +02:00
|
|
|
void evaluateBlock(int Per_u_, bool evaluate, bool no_derivatives);
|
2013-03-22 16:34:50 +01:00
|
|
|
int it_;
|
|
|
|
|
2023-02-23 23:37:08 +01:00
|
|
|
int block_num; // Index of the current block
|
|
|
|
int size; // Size of the current block
|
2022-06-20 16:26:58 +02:00
|
|
|
BlockSimulationType type;
|
2023-02-17 19:46:41 +01:00
|
|
|
bool is_linear;
|
2023-02-23 23:37:08 +01:00
|
|
|
int symbol_table_endo_nbr, u_count_int;
|
|
|
|
vector<Block_contain_type> Block_Contain;
|
2023-02-17 19:46:41 +01:00
|
|
|
|
|
|
|
bool steady_state;
|
2022-07-29 12:58:10 +02:00
|
|
|
|
|
|
|
/* Prints a bytecode expression in human readable form.
|
2023-02-23 17:21:22 +01:00
|
|
|
If faulty_op is not default constructed, it should point to a tag within
|
2022-07-29 12:58:10 +02:00
|
|
|
the expression that created a floating point exception, in which case the
|
|
|
|
corresponding mathematical operator will be printed within braces.
|
|
|
|
The second output argument points to the tag past the expression. */
|
|
|
|
pair<string, it_code_type> print_expression(const it_code_type &expr_begin, const optional<it_code_type> &faulty_op = nullopt) const;
|
|
|
|
|
2023-02-23 23:37:08 +01:00
|
|
|
// Prints current block
|
|
|
|
void printCurrentBlock();
|
|
|
|
|
|
|
|
void gotoBlock(int block);
|
|
|
|
|
|
|
|
void initializeTemporaryTerms(bool global_temporary_terms);
|
|
|
|
|
|
|
|
auto
|
|
|
|
getCurrentBlockExogenous() const
|
|
|
|
{
|
|
|
|
return currentBlockTag()->get_exogenous();
|
|
|
|
}
|
|
|
|
auto
|
|
|
|
getCurrentBlockEndogenous() const
|
|
|
|
{
|
|
|
|
return currentBlockTag()->get_endogenous();
|
|
|
|
}
|
|
|
|
auto
|
|
|
|
getCurrentBlockNbColJacob() const
|
|
|
|
{
|
|
|
|
return currentBlockTag()->get_nb_col_jacob();
|
|
|
|
}
|
|
|
|
auto
|
|
|
|
getCurrentBlockExoSize() const
|
|
|
|
{
|
|
|
|
return currentBlockTag()->get_exo_size();
|
|
|
|
}
|
|
|
|
auto
|
|
|
|
getCurrentBlockExoDetSize() const
|
|
|
|
{
|
|
|
|
return currentBlockTag()->get_det_exo_size();
|
|
|
|
}
|
|
|
|
|
2013-03-22 16:34:50 +01:00
|
|
|
public:
|
2023-02-17 19:46:41 +01:00
|
|
|
Evaluate(int y_size_arg, int y_kmin_arg, int y_kmax_arg, bool steady_state_arg, int periods_arg, BasicSymbolTable &symbol_table_arg);
|
2023-02-23 17:21:22 +01:00
|
|
|
// TODO: integrate into the constructor
|
|
|
|
void loadCodeFile(const filesystem::path &codfile);
|
|
|
|
|
|
|
|
int
|
|
|
|
get_block_number() const
|
|
|
|
{
|
|
|
|
return nb_blocks;
|
|
|
|
}
|
2013-03-22 16:34:50 +01:00
|
|
|
};
|
|
|
|
|
2022-07-29 12:40:33 +02:00
|
|
|
#endif // _EVALUATE_HH
|