handle additive terms when PAC equation does NOT have non/optimizing agents

parent a3fc7a77
Pipeline #936 passed with stage
in 1 minute and 32 seconds
......@@ -3662,7 +3662,7 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
pair<int, int> lhs_pac_var;
int optim_share_index;
set<pair<int, pair<int, int>>> ar_params_and_vars;
pair<int, pair<vector<int>, vector<bool>>> ec_params_and_vars;
pair<int, vector<pair<int,bool>>> ec_params_and_vars;
vector<tuple<int, int, int, double>> non_optim_vars_params_and_constants, additive_vars_params_and_constants;
tie(lhs_pac_var, optim_share_index, ar_params_and_vars, ec_params_and_vars, non_optim_vars_params_and_constants, additive_vars_params_and_constants) = pit.second;
string substruct = pit.first.first + ".equations." + pit.first.second + ".";
......@@ -3677,12 +3677,30 @@ DynamicModel::writeOutput(ostream &output, const string &basename, bool block_de
output << modstruct << "pac." << substruct << "ec.params = "
<< symbol_table.getTypeSpecificID(ec_params_and_vars.first) + 1 << ";" << endl
<< modstruct << "pac." << substruct << "ec.vars = [";
for (auto it : ec_params_and_vars.second.first)
output << symbol_table.getTypeSpecificID(it) + 1 << " ";
for (auto it : ec_params_and_vars.second)
output << symbol_table.getTypeSpecificID(it.first) + 1 << " ";
output << "];" << endl
<< modstruct << "pac." << substruct << "ec.istarget = [";
for (auto it : ec_params_and_vars.second)
if (it.second)
output << "true ";
else
output << "false ";
output << "];" << endl
<< modstruct << "pac." << substruct << "ec.isendo = [";
for (auto it : ec_params_and_vars.second.second)
output << (it ? "true" : "false") << " ";
for (auto it : ec_params_and_vars.second)
switch (symbol_table.getType(it.first))
{
case SymbolType::endogenous:
output << "true ";
break;
case SymbolType::exogenous:
output << "false ";
break;
default:
cerr << "expecting endogenous or exogenous" << endl;
exit(EXIT_FAILURE);
}
output << "];" << endl
<< modstruct << "pac." << substruct << "ar.params = [";
for (auto & it : ar_params_and_vars)
......@@ -4419,7 +4437,7 @@ DynamicModel::walkPacParameters(const string &name, map<pair<string, string>, pa
for (auto & equation : equations)
{
pair<int, int> lhs (-1, -1);
pair<int, pair<vector<int>, vector<bool>>> ec_params_and_vars;
pair<int, vector<pair<int,bool>>> ec_params_and_vars;
set<pair<int, pair<int, int>>> ar_params_and_vars;
vector<tuple<int, int, int, double>> non_optim_vars_params_and_constants, additive_vars_params_and_constants;
......@@ -4451,10 +4469,24 @@ DynamicModel::walkPacParameters(const string &name, map<pair<string, string>, pa
arg2->getPacOptimizingShareAndExprNodes(lhs_symb_id, lhs_orig_symb_id);
if (optim_part == nullptr)
equation->arg2->getPacOptimizingPart(lhs_orig_symb_id, ec_params_and_vars, ar_params_and_vars);
{
auto bopn = dynamic_cast<BinaryOpNode *>(equation->arg2);
if (bopn == nullptr)
{
cerr << "Error in PAC equation" << endl;
exit(EXIT_FAILURE);
}
bopn->getPacAREC(lhs_symb_id, lhs_orig_symb_id, ec_params_and_vars, ar_params_and_vars, additive_vars_params_and_constants);
}
else
{
optim_part->getPacOptimizingPart(lhs_orig_symb_id, ec_params_and_vars, ar_params_and_vars);
auto bopn = dynamic_cast<BinaryOpNode *>(optim_part);
if (bopn == nullptr)
{
cerr << "Error in PAC equation" << endl;
exit(EXIT_FAILURE);
}
bopn->getPacAREC(lhs_symb_id, lhs_orig_symb_id, ec_params_and_vars, ar_params_and_vars, additive_vars_params_and_constants);
try
{
non_optim_vars_params_and_constants = non_optim_part->matchLinearCombinationOfVariables();
......@@ -4487,7 +4519,7 @@ DynamicModel::walkPacParameters(const string &name, map<pair<string, string>, pa
cerr << "walkPacParameters: error obtaining LHS varibale." << endl;
exit(EXIT_FAILURE);
}
if (ec_params_and_vars.second.first.empty() || ar_params_and_vars.empty())
if (ec_params_and_vars.second.empty() || ar_params_and_vars.empty())
{
cerr << "walkPacParameters: error obtaining RHS parameters." << endl;
exit(EXIT_FAILURE);
......
......@@ -487,7 +487,7 @@ public:
//! (pac_model_name, standardized_eqtag) ->
//! (lhs, optim_share_index, ar_params_and_vars, ec_params_and_vars, non_optim_vars_params_and_constants)
map<pair<string, string>,
tuple<pair<int, int>, int, set<pair<int, pair<int, int>>>, pair<int, pair<vector<int>, vector<bool>>>, vector<tuple<int, int, int, double>>, vector<tuple<int, int, int, double>>>> pac_equation_info;
tuple<pair<int, int>, int, set<pair<int, pair<int, int>>>, pair<int, vector<pair<int,bool>>>, vector<tuple<int, int, int, double>>, vector<tuple<int, int, int, double>>>> pac_equation_info;
//! Table to undiff LHS variables for pac vector z
vector<int> getUndiffLHSForPac(const string &aux_model_name,
......
This diff is collapsed.
......@@ -583,10 +583,6 @@ class ExprNode
//! Returns true if model_info_name is referenced by a VarExpectationNode
virtual bool isVarModelReferenced(const string &model_info_name) const = 0;
//! Fills parameter information rerhs_symblated to PAC equation
virtual void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const = 0;
//! Matches a linear combination of variables, where scalars can be constant*parameter
/*! Returns a list of (variable_id, lag, param_id, constant)
corresponding to the terms in the expression. When there is no
......@@ -727,8 +723,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......@@ -814,8 +808,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......@@ -929,8 +921,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......@@ -995,10 +985,6 @@ public:
double eval(const eval_context_t &eval_context) const noexcept(false) override;
void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const deriv_node_temp_terms_t &tef_terms) const override;
expr_t Compute_RHS(expr_t arg1, expr_t arg2, int op, int op_type) const;
void getPacOptimizingPartHelper(const expr_t arg1, const expr_t arg2,
int lhs_orig_symb_id,
pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &ar_params_and_vars) const;
expr_t toStatic(DataTree &static_datatree) const override;
void computeXrefs(EquationInfo &ei) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
......@@ -1062,8 +1048,11 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
pair<int, vector<pair<int,bool>>> getPacEC(BinaryOpNode *bopn, int lhs_symb_id, int lhs_orig_symb_id) const;
void getPacAREC(int lhs_symb_id, int lhs_orig_symb_id,
pair<int, vector<pair<int,bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &ar_params_and_vars,
vector<tuple<int, int, int, double>> &additive_vars_params_and_constants) const;
//! Finds the share of optimizing agents in the PAC equation,
//! the expr node associated with it,
......@@ -1182,8 +1171,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......@@ -1306,8 +1293,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......@@ -1518,8 +1503,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......@@ -1603,8 +1586,6 @@ public:
void findConstantEquations(map<VariableNode *, NumConstNode *> &table) const override;
expr_t replaceVarsInEquation(map<VariableNode *, NumConstNode *> &table) const override;
bool containsPacExpectation(const string &pac_model_name = "") const override;
void getPacOptimizingPart(int lhs_orig_symb_id, pair<int, pair<vector<int>, vector<bool>>> &ec_params_and_vars,
set<pair<int, pair<int, int>>> &params_and_vars) const override;
bool isParamTimesEndogExpr() const override;
bool isVarModelReferenced(const string &model_info_name) const override;
void getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment