2008-02-03 11:28:36 +01:00
|
|
|
/*
|
2023-01-05 16:40:04 +01:00
|
|
|
* Copyright © 2003-2023 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
|
2021-06-09 16:52:20 +02:00
|
|
|
* along with Dynare. If not, see <https://www.gnu.org/licenses/>.
|
2008-02-03 11:28:36 +01:00
|
|
|
*/
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
#include <cstdlib>
|
2009-07-06 12:36:36 +02:00
|
|
|
#include <fstream>
|
2023-11-30 15:28:57 +01:00
|
|
|
#include <iostream>
|
2012-01-23 16:52:27 +01:00
|
|
|
#include <sstream>
|
2018-06-04 12:31:07 +02:00
|
|
|
#include <utility>
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2009-03-24 17:29:58 +01:00
|
|
|
#include "NumericalInitialization.hh"
|
2009-02-27 13:19:25 +01:00
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
InitParamStatement::InitParamStatement(int symb_id_arg, const expr_t param_value_arg,
|
|
|
|
const SymbolTable& symbol_table_arg) :
|
|
|
|
symb_id {symb_id_arg}, param_value {param_value_arg}, symbol_table {symbol_table_arg}
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-06-21 18:40:36 +02:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitParamStatement::checkPass(ModFileStructure& mod_file_struct,
|
|
|
|
[[maybe_unused]] WarningConsolidation& warnings)
|
2010-06-21 18:40:36 +02:00
|
|
|
{
|
|
|
|
if (symbol_table.getName(symb_id) == "dsge_prior_weight")
|
|
|
|
mod_file_struct.dsge_prior_weight_initialized = true;
|
2020-02-04 17:48:37 +01:00
|
|
|
|
|
|
|
// Needed for the workaround discussed in dynare#1173
|
|
|
|
if (symbol_table.getName(symb_id) == "optimal_policy_discount_factor")
|
2023-11-30 15:28:57 +01:00
|
|
|
param_value->collectVariables(SymbolType::parameter,
|
|
|
|
mod_file_struct.parameters_in_planner_discount);
|
2010-06-21 18:40:36 +02:00
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitParamStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
|
|
|
bool minimal_workspace) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
int id = symbol_table.getTypeSpecificID(symb_id) + 1;
|
2019-12-18 17:35:25 +01:00
|
|
|
output << "M_.params(" << id << ") = ";
|
2008-02-03 11:28:36 +01:00
|
|
|
param_value->writeOutput(output);
|
|
|
|
output << ";" << endl;
|
2015-05-28 11:42:12 +02:00
|
|
|
if (!minimal_workspace)
|
2019-12-18 17:35:25 +01:00
|
|
|
output << symbol_table.getName(symb_id) << " = M_.params(" << id << ");" << endl;
|
2008-12-19 11:24:31 +01:00
|
|
|
}
|
|
|
|
|
2017-02-02 15:09:43 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitParamStatement::writeJsonOutput(ostream& output) const
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
output << R"({"statementName": "param_init", "name": ")" << symbol_table.getName(symb_id)
|
|
|
|
<< R"(", )"
|
|
|
|
<< R"("value": ")";
|
2018-05-29 11:59:42 +02:00
|
|
|
param_value->writeJsonOutput(output, {}, {});
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"("})";
|
2017-02-02 15:09:43 +01:00
|
|
|
}
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitParamStatement::fillEvalContext(eval_context_t& eval_context) const
|
2008-12-19 11:24:31 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
eval_context[symb_id] = param_value->eval(eval_context);
|
|
|
|
}
|
2023-11-30 15:28:57 +01:00
|
|
|
catch (ExprNode::EvalException& e)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
2008-12-19 11:24:31 +01:00
|
|
|
}
|
|
|
|
|
2018-06-04 12:31:07 +02:00
|
|
|
InitOrEndValStatement::InitOrEndValStatement(init_values_t init_values_arg,
|
2023-11-30 15:28:57 +01:00
|
|
|
const SymbolTable& symbol_table_arg,
|
2019-12-16 19:42:59 +01:00
|
|
|
bool all_values_required_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
init_values {move(init_values_arg)},
|
|
|
|
symbol_table {symbol_table_arg},
|
|
|
|
all_values_required {all_values_required_arg}
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitOrEndValStatement::fillEvalContext(eval_context_t& eval_context) const
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
2021-07-22 16:37:18 +02:00
|
|
|
for (auto [symb_id, value] : init_values)
|
2022-06-02 10:50:21 +02:00
|
|
|
try
|
|
|
|
{
|
|
|
|
eval_context[symb_id] = value->eval(eval_context);
|
|
|
|
}
|
2023-11-30 15:28:57 +01:00
|
|
|
catch (ExprNode::EvalException& e)
|
2022-06-02 10:50:21 +02:00
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
|
|
|
|
2012-10-31 15:23:02 +01:00
|
|
|
set<int>
|
|
|
|
InitOrEndValStatement::getUninitializedVariables(SymbolType type)
|
|
|
|
{
|
|
|
|
set<int> unused;
|
|
|
|
if (!all_values_required)
|
|
|
|
return unused;
|
|
|
|
|
2018-07-17 18:34:07 +02:00
|
|
|
if (type == SymbolType::endogenous)
|
2012-10-31 15:23:02 +01:00
|
|
|
unused = symbol_table.getEndogenous();
|
2018-07-17 18:34:07 +02:00
|
|
|
else if (type == SymbolType::exogenous)
|
2012-10-31 15:23:02 +01:00
|
|
|
unused = symbol_table.getExogenous();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
cerr << "ERROR: Shouldn't arrive here." << endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2021-07-22 16:37:18 +02:00
|
|
|
for (auto [symb_id, value] : init_values)
|
2022-05-04 14:42:03 +02:00
|
|
|
unused.erase(symb_id);
|
2019-12-16 19:42:59 +01:00
|
|
|
|
2012-10-31 15:23:02 +01:00
|
|
|
return unused;
|
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitOrEndValStatement::writeInitValues(ostream& output) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2021-07-22 16:37:18 +02:00
|
|
|
for (auto [symb_id, value] : init_values)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2021-11-19 17:49:57 +01:00
|
|
|
if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
|
|
|
|
continue;
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
SymbolType type = symbol_table.getType(symb_id);
|
|
|
|
int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2019-11-18 17:13:49 +01:00
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case SymbolType::endogenous:
|
|
|
|
output << "oo_.steady_state";
|
|
|
|
break;
|
|
|
|
case SymbolType::exogenous:
|
|
|
|
output << "oo_.exo_steady_state";
|
|
|
|
break;
|
|
|
|
case SymbolType::exogenousDet:
|
|
|
|
output << "oo_.exo_det_steady_state";
|
|
|
|
break;
|
|
|
|
case SymbolType::excludedVariable:
|
|
|
|
cerr << "ERROR: Variable `" << symbol_table.getName(symb_id)
|
|
|
|
<< "` was excluded but found in an initval or endval statement" << endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
default:
|
|
|
|
cerr << "Should not arrive here" << endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2019-12-18 17:35:25 +01:00
|
|
|
output << "(" << tsid << ") = ";
|
2021-07-22 16:37:18 +02:00
|
|
|
value->writeOutput(output);
|
2008-02-03 11:28:36 +01:00
|
|
|
output << ";" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-02 15:09:43 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitOrEndValStatement::writeJsonInitValues(ostream& output) const
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
for (bool printed_something {false}; auto& [symb_id, value] : init_values)
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2021-11-19 17:49:57 +01:00
|
|
|
if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
|
|
|
|
continue;
|
2022-06-03 16:24:26 +02:00
|
|
|
if (exchange(printed_something, true))
|
2017-02-08 18:29:57 +01:00
|
|
|
output << ", ";
|
2023-11-30 15:28:57 +01:00
|
|
|
output << R"({"name": ")" << symbol_table.getName(symb_id) << R"(", )"
|
|
|
|
<< R"("value": ")";
|
2021-07-22 16:37:18 +02:00
|
|
|
value->writeJsonOutput(output, {}, {});
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"("})";
|
2017-02-02 15:09:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-10-04 15:59:18 +02:00
|
|
|
InitValStatement::InitValStatement(init_values_t init_values_arg,
|
2023-11-30 15:28:57 +01:00
|
|
|
const SymbolTable& symbol_table_arg,
|
2019-12-16 19:42:59 +01:00
|
|
|
bool all_values_required_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
InitOrEndValStatement {move(init_values_arg), symbol_table_arg, all_values_required_arg}
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-10-31 15:23:02 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitValStatement::checkPass([[maybe_unused]] ModFileStructure& mod_file_struct,
|
|
|
|
[[maybe_unused]] WarningConsolidation& warnings)
|
2012-10-31 15:23:02 +01:00
|
|
|
{
|
2023-11-14 14:28:30 +01:00
|
|
|
if (mod_file_struct.endval_present)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: an 'initval' block cannot appear after an 'endval' block" << endl; // See #104
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2018-07-17 18:34:07 +02:00
|
|
|
set<int> exogs = getUninitializedVariables(SymbolType::exogenous);
|
|
|
|
set<int> endogs = getUninitializedVariables(SymbolType::endogenous);
|
2012-10-31 15:23:02 +01:00
|
|
|
|
|
|
|
if (endogs.size() > 0)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: You have not set the following endogenous variables in initval:";
|
2018-06-04 12:26:16 +02:00
|
|
|
for (int endog : endogs)
|
|
|
|
cerr << " " << symbol_table.getName(endog);
|
2012-10-31 15:23:02 +01:00
|
|
|
cerr << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exogs.size() > 0)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: You have not set the following exogenous variables in initval:";
|
2018-06-04 12:26:16 +02:00
|
|
|
for (int exog : exogs)
|
|
|
|
cerr << " " << symbol_table.getName(exog);
|
2012-10-31 15:23:02 +01:00
|
|
|
cerr << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endogs.size() > 0 || exogs.size() > 0)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitValStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "%" << endl << "% INITVAL instructions" << endl << "%" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
// Writing initval block to set initial values for variables
|
2019-03-19 14:05:41 +01:00
|
|
|
output << "options_.initval_file = false;" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
|
|
writeInitValues(output);
|
2009-09-30 17:10:31 +02:00
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2017-02-02 15:09:43 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitValStatement::writeJsonOutput(ostream& output) const
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"({"statementName": "initval", "vals": [)";
|
2017-02-02 15:09:43 +01:00
|
|
|
writeJsonInitValues(output);
|
|
|
|
output << "]}";
|
|
|
|
}
|
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitValStatement::writeOutputPostInit(ostream& output) const
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
2017-05-18 17:58:27 +02:00
|
|
|
output << "if M_.exo_nbr > 0" << endl
|
|
|
|
<< "\too_.exo_simul = ones(M_.maximum_lag,1)*oo_.exo_steady_state';" << endl
|
2023-11-30 15:28:57 +01:00
|
|
|
<< "end" << endl
|
2017-05-18 17:58:27 +02:00
|
|
|
<< "if M_.exo_det_nbr > 0" << endl
|
|
|
|
<< "\too_.exo_det_simul = ones(M_.maximum_lag,1)*oo_.exo_det_steady_state';" << endl
|
2023-11-30 15:28:57 +01:00
|
|
|
<< "end" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValStatement::EndValStatement(init_values_t init_values_arg, const SymbolTable& symbol_table_arg,
|
2019-12-16 19:42:59 +01:00
|
|
|
bool all_values_required_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
InitOrEndValStatement {move(init_values_arg), symbol_table_arg, all_values_required_arg}
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-10-29 18:16:10 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValStatement::checkPass([[maybe_unused]] ModFileStructure& mod_file_struct,
|
|
|
|
[[maybe_unused]] WarningConsolidation& warnings)
|
2009-10-29 18:16:10 +01:00
|
|
|
{
|
2023-11-14 14:28:30 +01:00
|
|
|
mod_file_struct.endval_present = true;
|
|
|
|
|
2018-07-17 18:34:07 +02:00
|
|
|
set<int> exogs = getUninitializedVariables(SymbolType::exogenous);
|
|
|
|
set<int> endogs = getUninitializedVariables(SymbolType::endogenous);
|
2012-10-31 15:23:02 +01:00
|
|
|
|
|
|
|
if (endogs.size() > 0)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: You have not set the following endogenous variables in endval:";
|
2018-06-04 12:26:16 +02:00
|
|
|
for (int endog : endogs)
|
|
|
|
cerr << " " << symbol_table.getName(endog);
|
2012-10-31 15:23:02 +01:00
|
|
|
cerr << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (exogs.size() > 0)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: You have not set the following exogenous variables in endval:";
|
2018-06-04 12:26:16 +02:00
|
|
|
for (int exog : exogs)
|
|
|
|
cerr << " " << symbol_table.getName(exog);
|
2012-10-31 15:23:02 +01:00
|
|
|
cerr << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (endogs.size() > 0 || exogs.size() > 0)
|
|
|
|
exit(EXIT_FAILURE);
|
2009-10-29 18:16:10 +01:00
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "%" << endl << "% ENDVAL instructions" << endl << "%" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
// Writing endval block to set terminal values for variables
|
2023-10-23 17:33:16 +02:00
|
|
|
output << "oo_.initial_steady_state = oo_.steady_state;" << endl
|
|
|
|
<< "oo_.initial_exo_steady_state = oo_.exo_steady_state;" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
|
|
writeInitValues(output);
|
|
|
|
}
|
|
|
|
|
2017-02-02 15:09:43 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValStatement::writeJsonOutput(ostream& output) const
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"({"statementName": "endval", "vals": [)";
|
2017-02-02 15:09:43 +01:00
|
|
|
writeJsonInitValues(output);
|
|
|
|
output << "]}";
|
|
|
|
}
|
|
|
|
|
2022-04-20 16:57:39 +02:00
|
|
|
EndValLearntInStatement::EndValLearntInStatement(int learnt_in_period_arg,
|
2022-10-04 15:59:18 +02:00
|
|
|
learnt_end_values_t learnt_end_values_arg,
|
2023-11-30 15:28:57 +01:00
|
|
|
const SymbolTable& symbol_table_arg) :
|
|
|
|
learnt_in_period {learnt_in_period_arg},
|
|
|
|
learnt_end_values {move(learnt_end_values_arg)},
|
|
|
|
symbol_table {symbol_table_arg}
|
2022-04-20 16:57:39 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValLearntInStatement::checkPass(ModFileStructure& mod_file_struct,
|
|
|
|
[[maybe_unused]] WarningConsolidation& warnings)
|
2022-04-20 16:57:39 +02:00
|
|
|
{
|
|
|
|
mod_file_struct.endval_learnt_in_present = true;
|
|
|
|
}
|
|
|
|
|
2022-05-03 16:52:04 +02:00
|
|
|
string
|
|
|
|
EndValLearntInStatement::typeToString(LearntEndValType type)
|
|
|
|
{
|
|
|
|
switch (type)
|
|
|
|
{
|
|
|
|
case LearntEndValType::level:
|
|
|
|
return "level";
|
|
|
|
case LearntEndValType::add:
|
|
|
|
return "add";
|
|
|
|
case LearntEndValType::multiply:
|
|
|
|
return "multiply";
|
|
|
|
}
|
2023-10-18 20:21:40 +02:00
|
|
|
__builtin_unreachable(); // Silence GCC warning
|
2022-05-03 16:52:04 +02:00
|
|
|
}
|
|
|
|
|
2022-04-20 16:57:39 +02:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValLearntInStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2022-04-20 16:57:39 +02:00
|
|
|
{
|
|
|
|
output << "M_.learnt_endval = [ M_.learnt_endval;" << endl;
|
2022-05-03 16:52:04 +02:00
|
|
|
for (auto [type, symb_id, value] : learnt_end_values)
|
2022-04-20 16:57:39 +02:00
|
|
|
{
|
2022-05-06 12:56:24 +02:00
|
|
|
if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
|
|
|
|
continue;
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "struct('learnt_in'," << learnt_in_period << ",'exo_id',"
|
|
|
|
<< symbol_table.getTypeSpecificID(symb_id) + 1 << ",'type','" << typeToString(type)
|
|
|
|
<< "'"
|
2022-04-20 16:57:39 +02:00
|
|
|
<< ",'value',";
|
|
|
|
value->writeOutput(output);
|
|
|
|
output << ");" << endl;
|
|
|
|
}
|
|
|
|
output << "];" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
EndValLearntInStatement::writeJsonOutput(ostream& output) const
|
2022-04-20 16:57:39 +02:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
output << R"({"statementName": "endval", "learnt_in": )" << learnt_in_period << R"(, "vals": [)";
|
|
|
|
for (bool printed_something {false}; auto& [type, symb_id, value] : learnt_end_values)
|
2022-04-20 16:57:39 +02:00
|
|
|
{
|
2022-05-06 12:56:24 +02:00
|
|
|
if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
|
|
|
|
continue;
|
2022-06-03 16:24:26 +02:00
|
|
|
if (exchange(printed_something, true))
|
2022-04-20 16:57:39 +02:00
|
|
|
output << ", ";
|
2022-05-03 16:52:04 +02:00
|
|
|
output << R"({"name": ")" << symbol_table.getName(symb_id) << R"(", )"
|
|
|
|
<< R"("type": ")" << typeToString(type) << R"(", )"
|
|
|
|
<< R"("value": ")";
|
2022-04-20 16:57:39 +02:00
|
|
|
value->writeJsonOutput(output, {}, {});
|
|
|
|
output << R"("})";
|
|
|
|
}
|
|
|
|
output << "]}";
|
|
|
|
}
|
|
|
|
|
2018-06-04 12:31:07 +02:00
|
|
|
HistValStatement::HistValStatement(hist_values_t hist_values_arg,
|
2023-11-30 15:28:57 +01:00
|
|
|
const SymbolTable& symbol_table_arg,
|
2019-12-16 19:42:59 +01:00
|
|
|
bool all_values_required_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
hist_values {move(hist_values_arg)},
|
|
|
|
symbol_table {symbol_table_arg},
|
|
|
|
all_values_required {all_values_required_arg}
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-02-04 12:38:12 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HistValStatement::checkPass([[maybe_unused]] ModFileStructure& mod_file_struct,
|
|
|
|
[[maybe_unused]] WarningConsolidation& warnings)
|
2011-02-04 12:38:12 +01:00
|
|
|
{
|
2016-06-02 12:57:11 +02:00
|
|
|
if (all_values_required)
|
|
|
|
{
|
|
|
|
set<int> unused_endo = symbol_table.getEndogenous();
|
|
|
|
set<int> unused_exo = symbol_table.getExogenous();
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
for (const auto& [key, value] : hist_values)
|
2016-06-02 12:57:11 +02:00
|
|
|
{
|
2021-07-22 16:37:18 +02:00
|
|
|
int symb_id = key.first;
|
2022-05-04 14:42:03 +02:00
|
|
|
unused_endo.erase(symb_id);
|
|
|
|
unused_exo.erase(symb_id);
|
2016-06-02 12:57:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (unused_endo.size() > 0)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: You have not set the following endogenous variables in histval:";
|
2018-06-04 12:26:16 +02:00
|
|
|
for (int it : unused_endo)
|
|
|
|
cerr << " " << symbol_table.getName(it);
|
2016-06-02 12:57:11 +02:00
|
|
|
cerr << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unused_exo.size() > 0)
|
|
|
|
{
|
|
|
|
cerr << "ERROR: You have not set the following exogenous variables in endval:";
|
2018-06-04 12:26:16 +02:00
|
|
|
for (int it : unused_exo)
|
|
|
|
cerr << " " << symbol_table.getName(it);
|
2016-06-02 12:57:11 +02:00
|
|
|
cerr << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unused_endo.size() > 0 || unused_exo.size() > 0)
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2011-02-04 12:38:12 +01:00
|
|
|
}
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HistValStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2008-06-16 18:33:28 +02:00
|
|
|
output << "%" << endl
|
|
|
|
<< "% HISTVAL instructions" << endl
|
2010-09-10 11:43:48 +02:00
|
|
|
<< "%" << endl
|
2023-11-30 15:28:57 +01:00
|
|
|
<< "M_.histval_dseries = dseries(zeros(M_.orig_maximum_lag_with_diffs_expanded, "
|
|
|
|
"M_.orig_endo_nbr"
|
2018-12-20 17:45:54 +01:00
|
|
|
<< (symbol_table.AuxVarsSize() > 0 ? "+sum([M_.aux_vars.type]==6)" : "")
|
2018-12-11 17:26:50 +01:00
|
|
|
<< (symbol_table.exo_nbr() > 0 ? "+M_.exo_nbr" : "")
|
|
|
|
<< (symbol_table.exo_det_nbr() > 0 ? "+M_.exo_det_nbr" : "")
|
2023-11-30 15:28:57 +01:00
|
|
|
<< "), dates(sprintf('%dY', -M_.orig_maximum_lag_with_diffs_expanded+1)), [ "
|
|
|
|
"M_.endo_names(1:M_.orig_endo_nbr); "
|
|
|
|
<< (symbol_table.AuxVarsSize() > 0
|
|
|
|
? "M_.endo_names([M_.aux_vars(find([M_.aux_vars.type]==6)).endo_index]); "
|
|
|
|
: "")
|
2018-12-11 17:26:50 +01:00
|
|
|
<< (symbol_table.exo_nbr() > 0 ? "M_.exo_names; " : "")
|
2023-11-30 15:28:57 +01:00
|
|
|
<< (symbol_table.exo_det_nbr() > 0 ? "M_.exo_det_names; " : "") << "]);" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
for (const auto& [key, value] : hist_values)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2021-07-22 16:37:18 +02:00
|
|
|
auto [symb_id, lag] = key;
|
2021-11-19 17:49:57 +01:00
|
|
|
if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
|
|
|
|
continue;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "M_.histval_dseries{'" << symbol_table.getName(symb_id) << "'}(dates('" << lag
|
|
|
|
<< "Y'))=";
|
2021-07-22 16:37:18 +02:00
|
|
|
value->writeOutput(output);
|
2008-02-03 11:28:36 +01:00
|
|
|
output << ";" << endl;
|
|
|
|
}
|
2018-12-11 17:26:50 +01:00
|
|
|
|
2019-02-25 16:56:11 +01:00
|
|
|
output << "if exist(['+' M_.fname '/dynamic_set_auxiliary_series.m'])" << endl
|
2023-11-30 15:28:57 +01:00
|
|
|
<< " eval(['M_.histval_dseries = ' M_.fname "
|
|
|
|
"'.dynamic_set_auxiliary_series(M_.histval_dseries, M_.params);']);"
|
|
|
|
<< endl
|
2019-12-20 16:59:30 +01:00
|
|
|
<< "end" << endl
|
2023-11-30 15:28:57 +01:00
|
|
|
<< "M_.endo_histval = M_.histval_dseries{M_.endo_names{:}}(dates(sprintf('%dY', "
|
|
|
|
"1-M_.maximum_lag)):dates('0Y')).data';"
|
|
|
|
<< endl
|
|
|
|
<< "M_.endo_histval(isnan(M_.endo_histval)) = 0;"
|
|
|
|
<< endl; // Ensure that lead aux variables do not have a NaN
|
2018-12-11 17:26:50 +01:00
|
|
|
|
|
|
|
if (symbol_table.exo_nbr() > 0)
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "M_.exo_histval = M_.histval_dseries{M_.exo_names{:}}(dates(sprintf('%dY', "
|
|
|
|
"1-M_.maximum_lag)):dates('0Y')).data';"
|
|
|
|
<< endl;
|
2018-12-11 17:26:50 +01:00
|
|
|
if (symbol_table.exo_det_nbr() > 0)
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "M_.exo_det_histval = M_.histval_dseries{M_.exo_det_names{:}}(dates(sprintf('%dY', "
|
|
|
|
"1-M_.maximum_lag)):dates('0Y')).data';"
|
|
|
|
<< endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
|
2017-02-02 15:09:43 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HistValStatement::writeJsonOutput(ostream& output) const
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"({"statementName": "histval", "vals": [)";
|
2023-11-30 15:28:57 +01:00
|
|
|
for (bool printed_something {false}; const auto& [key, value] : hist_values)
|
2017-02-02 15:09:43 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
auto& [symb_id, lag] = key;
|
2021-11-19 17:49:57 +01:00
|
|
|
if (symbol_table.getType(symb_id) == SymbolType::unusedEndogenous) // See #82
|
|
|
|
continue;
|
2022-06-03 16:24:26 +02:00
|
|
|
if (exchange(printed_something, true))
|
2017-02-08 18:29:57 +01:00
|
|
|
output << ", ";
|
2021-07-22 16:37:18 +02:00
|
|
|
output << R"({ "name": ")" << symbol_table.getName(symb_id) << R"(")"
|
2023-11-30 15:28:57 +01:00
|
|
|
<< R"(, "lag": )" << lag << R"(, "value": ")";
|
2022-06-03 16:24:26 +02:00
|
|
|
value->writeJsonOutput(output, {}, {});
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"("})";
|
2017-02-02 15:09:43 +01:00
|
|
|
}
|
|
|
|
output << "]}";
|
|
|
|
}
|
|
|
|
|
2020-05-14 16:36:35 +02:00
|
|
|
InitvalFileStatement::InitvalFileStatement(OptionsList options_list_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
options_list {move(options_list_arg)}
|
2008-04-14 09:22:10 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2008-04-14 11:17:15 +02:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitvalFileStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2008-04-14 09:22:10 +02:00
|
|
|
{
|
2008-06-16 18:33:28 +02:00
|
|
|
output << "%" << endl
|
|
|
|
<< "% INITVAL_FILE statement" << endl
|
|
|
|
<< "%" << endl
|
2020-05-14 16:36:35 +02:00
|
|
|
<< "options_.initval_file = true;" << endl;
|
|
|
|
options_list.writeOutput(output, "options_initvalf");
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "[oo_.initval_series, options_.periods] = histvalf_initvalf('INITVALF', M_, "
|
|
|
|
"options_initvalf);"
|
|
|
|
<< endl;
|
2008-04-14 09:22:10 +02:00
|
|
|
}
|
|
|
|
|
2017-02-08 18:29:57 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
InitvalFileStatement::writeJsonOutput(ostream& output) const
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2020-05-14 16:36:35 +02:00
|
|
|
output << R"({"statementName": "initval_file")";
|
2022-09-18 09:30:13 +02:00
|
|
|
if (!options_list.empty())
|
2020-05-14 16:36:35 +02:00
|
|
|
{
|
|
|
|
output << ", ";
|
|
|
|
options_list.writeJsonOutput(output);
|
|
|
|
}
|
|
|
|
output << "}";
|
2017-02-08 18:29:57 +01:00
|
|
|
}
|
|
|
|
|
2020-05-14 16:36:35 +02:00
|
|
|
HistvalFileStatement::HistvalFileStatement(OptionsList options_list_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
options_list {move(options_list_arg)}
|
2014-04-03 15:05:20 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HistvalFileStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2014-04-03 15:05:20 +02:00
|
|
|
{
|
2020-05-14 16:36:35 +02:00
|
|
|
output << "%" << endl
|
|
|
|
<< "% HISTVAL_FILE statement" << endl
|
|
|
|
<< "%" << endl
|
|
|
|
<< "options_.histval_file = true;" << endl;
|
|
|
|
options_list.writeOutput(output, "options_histvalf");
|
2023-11-30 15:28:57 +01:00
|
|
|
output
|
|
|
|
<< "[M_.endo_histval, M_.exo_histval, M_.exo_det_histval] = histvalf(M_, options_histvalf);"
|
|
|
|
<< endl;
|
2014-04-03 15:05:20 +02:00
|
|
|
}
|
|
|
|
|
2017-02-08 18:29:57 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HistvalFileStatement::writeJsonOutput(ostream& output) const
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2020-05-14 16:36:35 +02:00
|
|
|
output << R"({"statementName": "histval_file")";
|
2022-09-18 09:30:13 +02:00
|
|
|
if (!options_list.empty())
|
2020-05-14 16:36:35 +02:00
|
|
|
{
|
|
|
|
output << ", ";
|
|
|
|
options_list.writeJsonOutput(output);
|
|
|
|
}
|
|
|
|
output << "}";
|
2017-02-08 18:29:57 +01:00
|
|
|
}
|
|
|
|
|
2023-10-06 23:44:42 +02:00
|
|
|
HomotopySetupStatement::HomotopySetupStatement(bool from_initval_to_endval_arg,
|
|
|
|
homotopy_values_t homotopy_values_arg,
|
2023-11-30 15:28:57 +01:00
|
|
|
const SymbolTable& symbol_table_arg) :
|
|
|
|
from_initval_to_endval {from_initval_to_endval_arg},
|
|
|
|
homotopy_values {move(homotopy_values_arg)},
|
|
|
|
symbol_table {symbol_table_arg}
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HomotopySetupStatement::writeOutput(ostream& output, [[maybe_unused]] const string& basename,
|
2023-10-06 22:50:53 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2008-06-16 18:33:28 +02:00
|
|
|
output << "%" << endl
|
|
|
|
<< "% HOMOTOPY_SETUP instructions" << endl
|
|
|
|
<< "%" << endl
|
2023-11-30 15:28:57 +01:00
|
|
|
<< "options_.homotopy_from_initval_to_endval = " << boolalpha << from_initval_to_endval
|
|
|
|
<< ';' << endl
|
2023-10-06 23:44:42 +02:00
|
|
|
<< "options_.homotopy_values = zeros(0, 4);" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2019-09-11 15:59:23 +02:00
|
|
|
for (auto [symb_id, expression1, expression2] : homotopy_values)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
const SymbolType type = symbol_table.getType(symb_id);
|
|
|
|
const int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
output << "options_.homotopy_values = vertcat(options_.homotopy_values, [ "
|
|
|
|
<< static_cast<int>(type) << ", " << tsid << ", ";
|
2018-12-03 15:05:49 +01:00
|
|
|
if (expression1)
|
2008-04-03 18:22:52 +02:00
|
|
|
expression1->writeOutput(output);
|
|
|
|
else
|
|
|
|
output << "NaN";
|
2008-02-03 11:28:36 +01:00
|
|
|
output << ", ";
|
|
|
|
expression2->writeOutput(output);
|
2008-03-31 18:19:16 +02:00
|
|
|
output << "]);" << endl;
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
}
|
2009-02-27 13:19:25 +01:00
|
|
|
|
2017-02-08 18:29:57 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
HomotopySetupStatement::writeJsonOutput(ostream& output) const
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"({"statementName": "homotopy", )"
|
|
|
|
<< R"("values": [)";
|
2023-11-30 15:28:57 +01:00
|
|
|
for (bool printed_something {false};
|
|
|
|
const auto& [symb_id, expression1, expression2] : homotopy_values)
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2022-06-03 16:24:26 +02:00
|
|
|
if (exchange(printed_something, true))
|
2017-02-08 18:29:57 +01:00
|
|
|
output << ", ";
|
2018-12-03 15:05:49 +01:00
|
|
|
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"({"name": ")" << symbol_table.getName(symb_id) << R"(")"
|
|
|
|
<< R"(, "initial_value": ")";
|
2018-12-03 15:05:49 +01:00
|
|
|
if (expression1)
|
|
|
|
expression1->writeJsonOutput(output, {}, {});
|
2017-02-08 18:29:57 +01:00
|
|
|
else
|
|
|
|
output << "NaN";
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"(", "final_value": ")";
|
2018-12-03 15:05:49 +01:00
|
|
|
expression2->writeJsonOutput(output, {}, {});
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"("})";
|
2017-02-08 18:29:57 +01:00
|
|
|
}
|
|
|
|
output << "]"
|
|
|
|
<< "}";
|
|
|
|
}
|
|
|
|
|
2018-06-04 12:31:07 +02:00
|
|
|
SaveParamsAndSteadyStateStatement::SaveParamsAndSteadyStateStatement(string filename_arg) :
|
2023-11-30 15:28:57 +01:00
|
|
|
filename {move(filename_arg)}
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
SaveParamsAndSteadyStateStatement::writeOutput(ostream& output,
|
|
|
|
[[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
output << "save_params_and_steady_state('" << filename << "');" << endl;
|
|
|
|
}
|
|
|
|
|
2017-02-08 18:29:57 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
SaveParamsAndSteadyStateStatement::writeJsonOutput(ostream& output) const
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2019-04-03 16:32:52 +02:00
|
|
|
output << R"({"statementName": "save_params_and_steady_state")"
|
|
|
|
<< R"(, "filename": ")" << filename << R"(")"
|
2017-02-08 18:29:57 +01:00
|
|
|
<< "}";
|
|
|
|
}
|
|
|
|
|
2023-11-30 15:28:57 +01:00
|
|
|
LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(
|
|
|
|
const filesystem::path& filename, const SymbolTable& symbol_table_arg,
|
|
|
|
WarningConsolidation& warnings) :
|
|
|
|
symbol_table {symbol_table_arg}
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
2023-01-05 16:40:04 +01:00
|
|
|
cout << "Reading " << filename.string() << "." << endl;
|
2009-02-27 13:19:25 +01:00
|
|
|
|
2009-03-24 17:29:58 +01:00
|
|
|
ifstream f;
|
2018-06-27 15:12:12 +02:00
|
|
|
f.open(filename, ios::in);
|
2009-06-10 16:45:41 +02:00
|
|
|
if (f.fail())
|
2009-03-24 17:29:58 +01:00
|
|
|
{
|
2023-01-05 16:40:04 +01:00
|
|
|
cerr << "ERROR: Can't open " << filename.string() << endl;
|
2009-03-24 17:29:58 +01:00
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2009-02-27 13:19:25 +01:00
|
|
|
|
2009-12-16 18:13:23 +01:00
|
|
|
while (true)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
2009-03-24 17:29:58 +01:00
|
|
|
string symb_name, value;
|
|
|
|
f >> symb_name >> value;
|
|
|
|
if (f.eof())
|
|
|
|
break;
|
2009-02-27 13:19:25 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2009-03-24 17:29:58 +01:00
|
|
|
int symb_id = symbol_table.getID(symb_name);
|
|
|
|
content[symb_id] = value;
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
2023-11-30 15:28:57 +01:00
|
|
|
catch (SymbolTable::UnknownSymbolNameException& e)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
warnings << "WARNING: Unknown symbol " << symb_name << " in " << filename.string()
|
|
|
|
<< endl;
|
2009-03-24 17:29:58 +01:00
|
|
|
}
|
|
|
|
}
|
2012-01-18 14:30:43 +01:00
|
|
|
f.close();
|
2009-03-24 17:29:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
LoadParamsAndSteadyStateStatement::writeOutput(ostream& output,
|
|
|
|
[[maybe_unused]] const string& basename,
|
2022-06-24 17:10:12 +02:00
|
|
|
[[maybe_unused]] bool minimal_workspace) const
|
2009-03-24 17:29:58 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
for (const auto& [id, value] : content)
|
2009-03-24 17:29:58 +01:00
|
|
|
{
|
2019-12-16 19:42:59 +01:00
|
|
|
switch (symbol_table.getType(id))
|
2009-03-24 17:29:58 +01:00
|
|
|
{
|
2018-07-17 18:34:07 +02:00
|
|
|
case SymbolType::parameter:
|
2009-03-24 17:29:58 +01:00
|
|
|
output << "M_.params";
|
|
|
|
break;
|
2018-07-17 18:34:07 +02:00
|
|
|
case SymbolType::endogenous:
|
2009-03-24 17:29:58 +01:00
|
|
|
output << "oo_.steady_state";
|
|
|
|
break;
|
2018-07-17 18:34:07 +02:00
|
|
|
case SymbolType::exogenous:
|
2009-03-24 17:29:58 +01:00
|
|
|
output << "oo_.exo_steady_state";
|
|
|
|
break;
|
2018-07-17 18:34:07 +02:00
|
|
|
case SymbolType::exogenousDet:
|
2009-03-24 17:29:58 +01:00
|
|
|
output << "oo_.exo_det_steady_state";
|
|
|
|
break;
|
|
|
|
default:
|
2023-11-30 15:28:57 +01:00
|
|
|
cerr << "ERROR: Unsupported variable type for " << symbol_table.getName(id)
|
|
|
|
<< " in load_params_and_steady_state" << endl;
|
2009-03-24 17:29:58 +01:00
|
|
|
exit(EXIT_FAILURE);
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
2009-03-24 17:29:58 +01:00
|
|
|
|
2019-12-16 19:42:59 +01:00
|
|
|
int tsid = symbol_table.getTypeSpecificID(id) + 1;
|
|
|
|
output << "(" << tsid << ") = " << value << ";" << endl;
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
|
|
|
}
|
2009-03-24 17:29:58 +01:00
|
|
|
|
2017-02-08 18:29:57 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
LoadParamsAndSteadyStateStatement::writeJsonOutput(ostream& output) const
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2021-01-06 08:33:44 +01:00
|
|
|
output << R"({"statementName": "load_params_and_steady_state",)"
|
2019-04-03 16:32:52 +02:00
|
|
|
<< R"("values": [)";
|
2023-11-30 15:28:57 +01:00
|
|
|
for (bool printed_something {false}; const auto& [id, value] : content)
|
2017-02-08 18:29:57 +01:00
|
|
|
{
|
2022-06-03 16:24:26 +02:00
|
|
|
if (exchange(printed_something, true))
|
2017-02-08 18:29:57 +01:00
|
|
|
output << ", ";
|
2022-06-03 16:24:26 +02:00
|
|
|
output << R"({"name": ")" << symbol_table.getName(id) << R"(")"
|
|
|
|
<< R"(, "value": ")" << value << R"("})";
|
2017-02-08 18:29:57 +01:00
|
|
|
}
|
|
|
|
output << "]"
|
|
|
|
<< "}";
|
|
|
|
}
|
|
|
|
|
2009-03-24 17:29:58 +01:00
|
|
|
void
|
2023-11-30 15:28:57 +01:00
|
|
|
LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t& eval_context) const
|
2009-03-24 17:29:58 +01:00
|
|
|
{
|
2023-11-30 15:28:57 +01:00
|
|
|
for (const auto& [id, value] : content)
|
2019-07-11 18:39:32 +02:00
|
|
|
/* We use strtod() instead of stod() because we want underflows and
|
|
|
|
overflows to respectively yield 0 and ±Inf. See also the comment in
|
2019-07-11 18:35:42 +02:00
|
|
|
NumericalConstants.cc */
|
2019-12-16 19:42:59 +01:00
|
|
|
eval_context[id] = strtod(value.c_str(), nullptr);
|
2009-03-24 17:29:58 +01:00
|
|
|
}
|