Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Dynare
preprocessor
Commits
b88e0de5
Verified
Commit
b88e0de5
authored
Nov 28, 2018
by
Sébastien Villemot
Browse files
Remove useless accessor methods for data members that are const in ExprNode classes
Those const data members are simply made public.
parent
cac65b07
Pipeline
#397
passed with stage
in 1 minute and 21 seconds
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/ComputingTasks.cc
View file @
b88e0de5
...
@@ -4936,7 +4936,7 @@ VarExpectationModelStatement::writeOutput(ostream &output, const string &basenam
...
@@ -4936,7 +4936,7 @@ VarExpectationModelStatement::writeOutput(ostream &output, const string &basenam
<<
mstruct
<<
".variable_id = "
<<
symbol_table
.
getTypeSpecificID
(
variable
)
+
1
<<
";"
<<
endl
;
<<
mstruct
<<
".variable_id = "
<<
symbol_table
.
getTypeSpecificID
(
variable
)
+
1
<<
";"
<<
endl
;
auto
disc_var
=
dynamic_cast
<
const
VariableNode
*>
(
discount
);
auto
disc_var
=
dynamic_cast
<
const
VariableNode
*>
(
discount
);
if
(
disc_var
)
if
(
disc_var
)
output
<<
mstruct
<<
".discount_index = "
<<
symbol_table
.
getTypeSpecificID
(
disc_var
->
get_
symb_id
()
)
+
1
<<
';'
<<
endl
;
output
<<
mstruct
<<
".discount_index = "
<<
symbol_table
.
getTypeSpecificID
(
disc_var
->
symb_id
)
+
1
<<
';'
<<
endl
;
else
else
{
{
output
<<
mstruct
<<
".discount_value = "
;
output
<<
mstruct
<<
".discount_value = "
;
...
...
src/DataTree.cc
View file @
b88e0de5
...
@@ -174,13 +174,13 @@ DataTree::AddPlus(expr_t iArg1, expr_t iArg2)
...
@@ -174,13 +174,13 @@ DataTree::AddPlus(expr_t iArg1, expr_t iArg2)
{
{
// Simplify x+(-y) in x-y
// Simplify x+(-y) in x-y
auto
uarg2
=
dynamic_cast
<
UnaryOpNode
*>
(
iArg2
);
auto
uarg2
=
dynamic_cast
<
UnaryOpNode
*>
(
iArg2
);
if
(
uarg2
!=
nullptr
&&
uarg2
->
get_
op_code
()
==
UnaryOpcode
::
uminus
)
if
(
uarg2
!=
nullptr
&&
uarg2
->
op_code
==
UnaryOpcode
::
uminus
)
return
AddMinus
(
iArg1
,
uarg2
->
get_
arg
()
);
return
AddMinus
(
iArg1
,
uarg2
->
arg
);
// Simplify (-x)+y in y-x
// Simplify (-x)+y in y-x
auto
uarg1
=
dynamic_cast
<
UnaryOpNode
*>
(
iArg1
);
auto
uarg1
=
dynamic_cast
<
UnaryOpNode
*>
(
iArg1
);
if
(
uarg1
!=
nullptr
&&
uarg1
->
get_
op_code
()
==
UnaryOpcode
::
uminus
)
if
(
uarg1
!=
nullptr
&&
uarg1
->
op_code
==
UnaryOpcode
::
uminus
)
return
AddMinus
(
iArg2
,
uarg1
->
get_
arg
()
);
return
AddMinus
(
iArg2
,
uarg1
->
arg
);
// To treat commutativity of "+"
// To treat commutativity of "+"
// Nodes iArg1 and iArg2 are sorted by index
// Nodes iArg1 and iArg2 are sorted by index
...
@@ -219,8 +219,8 @@ DataTree::AddUMinus(expr_t iArg1)
...
@@ -219,8 +219,8 @@ DataTree::AddUMinus(expr_t iArg1)
{
{
// Simplify -(-x) in x
// Simplify -(-x) in x
auto
*
uarg
=
dynamic_cast
<
UnaryOpNode
*>
(
iArg1
);
auto
*
uarg
=
dynamic_cast
<
UnaryOpNode
*>
(
iArg1
);
if
(
uarg
!=
nullptr
&&
uarg
->
get_
op_code
()
==
UnaryOpcode
::
uminus
)
if
(
uarg
!=
nullptr
&&
uarg
->
op_code
==
UnaryOpcode
::
uminus
)
return
uarg
->
get_
arg
()
;
return
uarg
->
arg
;
return
AddUnaryOp
(
UnaryOpcode
::
uminus
,
iArg1
);
return
AddUnaryOp
(
UnaryOpcode
::
uminus
,
iArg1
);
}
}
...
...
src/DynamicModel.cc
View file @
b88e0de5
...
@@ -649,8 +649,8 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
...
@@ -649,8 +649,8 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
EquationType equ_type = getBlockEquationType(block, i);
EquationType equ_type = getBlockEquationType(block, i);
string sModel = symbol_table.getName(symbol_table.getID(SymbolType::endogenous, variable_ID));
string sModel = symbol_table.getName(symbol_table.getID(SymbolType::endogenous, variable_ID));
eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i);
eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i);
lhs = eq_node->
get_
arg1
()
;
lhs = eq_node->arg1;
rhs = eq_node->
get_
arg2
()
;
rhs = eq_node->arg2;
tmp_output.str("");
tmp_output.str("");
lhs->writeOutput(tmp_output, local_output_type, local_temporary_terms, {});
lhs->writeOutput(tmp_output, local_output_type, local_temporary_terms, {});
switch (simulation_type)
switch (simulation_type)
...
@@ -677,8 +677,8 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
...
@@ -677,8 +677,8 @@ DynamicModel::writeModelEquationsOrdered_M(const string &basename) const
output << endl << " ";
output << endl << " ";
tmp_output.str("");
tmp_output.str("");
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
lhs = eq_node->
get_
arg1
()
;
lhs = eq_node->arg1;
rhs = eq_node->
get_
arg2
()
;
rhs = eq_node->arg2;
lhs->writeOutput(output, local_output_type, local_temporary_terms, {});
lhs->writeOutput(output, local_output_type, local_temporary_terms, {});
output << " = ";
output << " = ";
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
rhs->writeOutput(output, local_output_type, local_temporary_terms, {});
...
@@ -1415,16 +1415,16 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id
...
@@ -1415,16 +1415,16 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id
if (equ_type == E_EVALUATE)
if (equ_type == E_EVALUATE)
{
{
eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i);
eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i);
lhs = eq_node->
get_
arg1
()
;
lhs = eq_node->arg1;
rhs = eq_node->
get_
arg2
()
;
rhs = eq_node->arg2;
rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
lhs->compile(code_file, instruction_number, true, temporary_terms, map_idx, true, false);
lhs->compile(code_file, instruction_number, true, temporary_terms, map_idx, true, false);
}
}
else if (equ_type == E_EVALUATE_S)
else if (equ_type == E_EVALUATE_S)
{
{
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
eq_node = (BinaryOpNode *) getBlockEquationRenormalizedExpr(block, i);
lhs = eq_node->
get_
arg1
()
;
lhs = eq_node->arg1;
rhs = eq_node->
get_
arg2
()
;
rhs = eq_node->arg2;
rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
lhs->compile(code_file, instruction_number, true, temporary_terms, map_idx, true, false);
lhs->compile(code_file, instruction_number, true, temporary_terms, map_idx, true, false);
}
}
...
@@ -1445,8 +1445,8 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id
...
@@ -1445,8 +1445,8 @@ DynamicModel::writeModelEquationsCode_Block(const string &basename, const map_id
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i));
FNUMEXPR_ fnumexpr(ModelEquation, getBlockEquationID(block, i));
fnumexpr.write(code_file, instruction_number);
fnumexpr.write(code_file, instruction_number);
eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i);
eq_node = (BinaryOpNode *) getBlockEquationExpr(block, i);
lhs = eq_node->
get_
arg1
()
;
lhs = eq_node->arg1;
rhs = eq_node->
get_
arg2
()
;
rhs = eq_node->arg2;
lhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
lhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
rhs->compile(code_file, instruction_number, false, temporary_terms, map_idx, true, false);
...
@@ -3681,7 +3681,7 @@ DynamicModel::updateVarAndTrendModel() const
...
@@ -3681,7 +3681,7 @@ DynamicModel::updateVarAndTrendModel() const
for (auto eqn : it.second)
for (auto eqn : it.second)
{
{
set<pair<int, int>> rhs_set;
set<pair<int, int>> rhs_set;
equations[eqn]->
get_
arg2
()
->collectDynamicVariables(SymbolType::endogenous, rhs_set);
equations[eqn]->arg2->collectDynamicVariables(SymbolType::endogenous, rhs_set);
rhs.push_back(rhs_set);
rhs.push_back(rhs_set);
if (i == 1)
if (i == 1)
...
@@ -3695,7 +3695,7 @@ DynamicModel::updateVarAndTrendModel() const
...
@@ -3695,7 +3695,7 @@ DynamicModel::updateVarAndTrendModel() const
catch (...)
catch (...)
{
{
}
}
int trend_var_symb_id = equations[eqn]->
get_
arg2
()
->findTargetVariable(lhs_symb_id);
int trend_var_symb_id = equations[eqn]->arg2->findTargetVariable(lhs_symb_id);
if (trend_var_symb_id >= 0)
if (trend_var_symb_id >= 0)
{
{
if (symbol_table.isAuxiliaryVariable(trend_var_symb_id))
if (symbol_table.isAuxiliaryVariable(trend_var_symb_id))
...
@@ -3764,9 +3764,9 @@ DynamicModel::fillVarModelTable() const
...
@@ -3764,9 +3764,9 @@ DynamicModel::fillVarModelTable() const
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
}
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::endogenous, lhs_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::endogenous, lhs_set);
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::exogenous, lhs_tmp_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::exogenous, lhs_tmp_set);
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::parameter, lhs_tmp_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::parameter, lhs_tmp_set);
if (lhs_set.size() != 1 || !lhs_tmp_set.empty())
if (lhs_set.size() != 1 || !lhs_tmp_set.empty())
{
{
...
@@ -3788,10 +3788,10 @@ DynamicModel::fillVarModelTable() const
...
@@ -3788,10 +3788,10 @@ DynamicModel::fillVarModelTable() const
lhs.push_back(itlhs->first);
lhs.push_back(itlhs->first);
lhs_set.clear();
lhs_set.clear();
set<expr_t> lhs_expr_t_set;
set<expr_t> lhs_expr_t_set;
equations[eqn]->
get_
arg1
()
->collectVARLHSVariable(lhs_expr_t_set);
equations[eqn]->arg1->collectVARLHSVariable(lhs_expr_t_set);
lhs_expr_t.push_back(*(lhs_expr_t_set.begin()));
lhs_expr_t.push_back(*(lhs_expr_t_set.begin()));
equations[eqn]->
get_
arg2
()
->collectDynamicVariables(SymbolType::endogenous, rhs_set);
equations[eqn]->arg2->collectDynamicVariables(SymbolType::endogenous, rhs_set);
for (const auto & itrhs : rhs_set)
for (const auto & itrhs : rhs_set)
if (itrhs.second > 0)
if (itrhs.second > 0)
{
{
...
@@ -3830,7 +3830,7 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
...
@@ -3830,7 +3830,7 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
for (auto eqn : it.second)
for (auto eqn : it.second)
{
{
// ensure no leads in equations
// ensure no leads in equations
if (equations[eqn]->
get_
arg2
()
->VarMinLag() <= 0)
if (equations[eqn]->arg2->VarMinLag() <= 0)
{
{
cerr << "ERROR in VAR model Equation (#" << eqn << "). "
cerr << "ERROR in VAR model Equation (#" << eqn << "). "
<< "Leaded exogenous variables "
<< "Leaded exogenous variables "
...
@@ -3840,14 +3840,14 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
...
@@ -3840,14 +3840,14 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
}
}
// save lhs variables
// save lhs variables
equations[eqn]->
get_
arg1
()
->collectVARLHSVariable(lhs);
equations[eqn]->arg1->collectVARLHSVariable(lhs);
equations[eqn]->
get_
arg1
()
->countDiffs() > 0 ?
equations[eqn]->arg1->countDiffs() > 0 ?
diff_vec.push_back(true) : diff_vec.push_back(false);
diff_vec.push_back(true) : diff_vec.push_back(false);
if (diff_vec.back())
if (diff_vec.back())
{
{
set<pair<int, int>> diff_set;
set<pair<int, int>> diff_set;
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::endogenous, diff_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::endogenous, diff_set);
if (diff_set.size() != 1)
if (diff_set.size() != 1)
{
{
...
@@ -3874,7 +3874,7 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
...
@@ -3874,7 +3874,7 @@ DynamicModel::fillVarModelTableFromOrigModel(StaticModel &static_model) const
vector<int> max_lag;
vector<int> max_lag;
for (auto eqn : it.second)
for (auto eqn : it.second)
max_lag.push_back(equations[eqn]->
get_
arg2
()
->VarMaxLag(static_model, lhs_static));
max_lag.push_back(equations[eqn]->arg2->VarMaxLag(static_model, lhs_static));
lags[it.first] = max_lag;
lags[it.first] = max_lag;
diff[it.first] = diff_vec;
diff[it.first] = diff_vec;
orig_diff_var[it.first] = orig_diff_var_vec;
orig_diff_var[it.first] = orig_diff_var_vec;
...
@@ -3896,7 +3896,7 @@ DynamicModel::fillAutoregressiveMatrix(map<string, map<tuple<int, int, int>, exp
...
@@ -3896,7 +3896,7 @@ DynamicModel::fillAutoregressiveMatrix(map<string, map<tuple<int, int, int>, exp
vector<int> lhs = is_trend_component_model ?
vector<int> lhs = is_trend_component_model ?
trend_component_model_table.getLhs(it.first) : var_model_table.getLhs(it.first);
trend_component_model_table.getLhs(it.first) : var_model_table.getLhs(it.first);
for (auto eqn : it.second)
for (auto eqn : it.second)
equations[eqn]->
get_
arg2
()
->fillAutoregressiveRow(i++, lhs, AR);
equations[eqn]->arg2->fillAutoregressiveRow(i++, lhs, AR);
ARr[it.first] = AR;
ARr[it.first] = AR;
}
}
}
}
...
@@ -3957,9 +3957,9 @@ DynamicModel::fillTrendComponentModelTable() const
...
@@ -3957,9 +3957,9 @@ DynamicModel::fillTrendComponentModelTable() const
exit(EXIT_FAILURE);
exit(EXIT_FAILURE);
}
}
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::endogenous, lhs_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::endogenous, lhs_set);
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::exogenous, lhs_tmp_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::exogenous, lhs_tmp_set);
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::parameter, lhs_tmp_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::parameter, lhs_tmp_set);
if (lhs_set.size() != 1 || !lhs_tmp_set.empty())
if (lhs_set.size() != 1 || !lhs_tmp_set.empty())
{
{
...
@@ -3981,10 +3981,10 @@ DynamicModel::fillTrendComponentModelTable() const
...
@@ -3981,10 +3981,10 @@ DynamicModel::fillTrendComponentModelTable() const
lhs.push_back(itlhs->first);
lhs.push_back(itlhs->first);
lhs_set.clear();
lhs_set.clear();
set<expr_t> lhs_expr_t_set;
set<expr_t> lhs_expr_t_set;
equations[eqn]->
get_
arg1
()
->collectVARLHSVariable(lhs_expr_t_set);
equations[eqn]->arg1->collectVARLHSVariable(lhs_expr_t_set);
lhs_expr_t.push_back(*(lhs_expr_t_set.begin()));
lhs_expr_t.push_back(*(lhs_expr_t_set.begin()));
equations[eqn]->
get_
arg2
()
->collectDynamicVariables(SymbolType::endogenous, rhs_set);
equations[eqn]->arg2->collectDynamicVariables(SymbolType::endogenous, rhs_set);
for (const auto & itrhs : rhs_set)
for (const auto & itrhs : rhs_set)
if (itrhs.second > 0)
if (itrhs.second > 0)
{
{
...
@@ -4026,7 +4026,7 @@ DynamicModel::fillErrorComponentMatrix(map<string, map<tuple<int, int, int>, exp
...
@@ -4026,7 +4026,7 @@ DynamicModel::fillErrorComponentMatrix(map<string, map<tuple<int, int, int>, exp
i = 0;
i = 0;
for (auto eqn : it.second)
for (auto eqn : it.second)
if (find(nontrend_eqnums.begin(), nontrend_eqnums.end(), eqn) != nontrend_eqnums.end())
if (find(nontrend_eqnums.begin(), nontrend_eqnums.end(), eqn) != nontrend_eqnums.end())
equations[eqn]->
get_
arg2
()
->fillErrorCorrectionRow(i++, parsed_undiff_nontrend_lhs, trend_lhs, EC);
equations[eqn]->arg2->fillErrorCorrectionRow(i++, parsed_undiff_nontrend_lhs, trend_lhs, EC);
ECr[it.first] = EC;
ECr[it.first] = EC;
}
}
}
}
...
@@ -4044,7 +4044,7 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
...
@@ -4044,7 +4044,7 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
for (auto eqn : it.second)
for (auto eqn : it.second)
{
{
// ensure no leads in equations
// ensure no leads in equations
if (equations[eqn]->
get_
arg2
()
->VarMinLag() <= 0)
if (equations[eqn]->arg2->VarMinLag() <= 0)
{
{
cerr << "ERROR in trend component model Equation (#" << eqn << "). "
cerr << "ERROR in trend component model Equation (#" << eqn << "). "
<< "Leaded exogenous variables "
<< "Leaded exogenous variables "
...
@@ -4054,14 +4054,14 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
...
@@ -4054,14 +4054,14 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
}
}
// save lhs variables
// save lhs variables
equations[eqn]->
get_
arg1
()
->collectVARLHSVariable(lhs);
equations[eqn]->arg1->collectVARLHSVariable(lhs);
equations[eqn]->
get_
arg1
()
->countDiffs() > 0 ?
equations[eqn]->arg1->countDiffs() > 0 ?
diff_vec.push_back(true) : diff_vec.push_back(false);
diff_vec.push_back(true) : diff_vec.push_back(false);
if (diff_vec.back())
if (diff_vec.back())
{
{
set<pair<int, int>> diff_set;
set<pair<int, int>> diff_set;
equations[eqn]->
get_
arg1
()
->collectDynamicVariables(SymbolType::endogenous, diff_set);
equations[eqn]->arg1->collectDynamicVariables(SymbolType::endogenous, diff_set);
if (diff_set.size() != 1)
if (diff_set.size() != 1)
{
{
...
@@ -4088,7 +4088,7 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
...
@@ -4088,7 +4088,7 @@ DynamicModel::fillTrendComponentModelTableFromOrigModel(StaticModel &static_mode
vector<int> max_lag;
vector<int> max_lag;
for (auto eqn : it.second)
for (auto eqn : it.second)
max_lag.push_back(equations[eqn]->
get_
arg2
()
->VarMaxLag(static_model, lhs_static));
max_lag.push_back(equations[eqn]->arg2->VarMaxLag(static_model, lhs_static));
lags[it.first] = max_lag;
lags[it.first] = max_lag;
diff[it.first] = diff_vec;
diff[it.first] = diff_vec;
orig_diff_var[it.first] = orig_diff_var_vec;
orig_diff_var[it.first] = orig_diff_var_vec;
...
@@ -4224,12 +4224,12 @@ DynamicModel::getUndiffLHSForPac(const string &aux_model_name,
...
@@ -4224,12 +4224,12 @@ DynamicModel::getUndiffLHSForPac(const string &aux_model_name,
if (printerr)
if (printerr)
{ // we have undiffed something like diff(x), hence x is not in diff_subst_table
{ // we have undiffed something like diff(x), hence x is not in diff_subst_table
lhs_expr_t.at(i) = node;
lhs_expr_t.at(i) = node;
lhs.at(i) = dynamic_cast<VariableNode *>(node)->
get_
symb_id
()
;
lhs.at(i) = dynamic_cast<VariableNode *>(node)->symb_id;
}
}
else
else
{
{
lhs_expr_t.at(i) = const_cast<expr_t>(it1->first);
lhs_expr_t.at(i) = const_cast<expr_t>(it1->first);
lhs.at(i) = const_cast<VariableNode *>(it1->second)->
get_
symb_id
()
;
lhs.at(i) = const_cast<VariableNode *>(it1->second)->symb_id;
}
}
}
}
return lhs;
return lhs;
...
@@ -4262,11 +4262,11 @@ DynamicModel::walkPacParameters()
...
@@ -4262,11 +4262,11 @@ DynamicModel::walkPacParameters()
{
{
}
}
equation->
get_
arg2
()
->getPacOptimizingShareAndExprNodes(optim_share,
equation->arg2->getPacOptimizingShareAndExprNodes(optim_share,
optim_part,
optim_part,
non_optim_part);
non_optim_part);
if (optim_part == nullptr)
if (optim_part == nullptr)
equation->
get_
arg2
()
->getPacOptimizingPart(lhs_orig_symb_id, ec_params_and_vars, ar_params_and_vars);
equation->arg2->getPacOptimizingPart(lhs_orig_symb_id, ec_params_and_vars, ar_params_and_vars);
else
else
{
{
optim_share_index = *(optim_share.begin());
optim_share_index = *(optim_share.begin());
...
@@ -4288,7 +4288,7 @@ DynamicModel::getPacMaxLag(const string &pac_model_name) const
...
@@ -4288,7 +4288,7 @@ DynamicModel::getPacMaxLag(const string &pac_model_name) const
if (equation->containsPacExpectation(pac_model_name))
if (equation->containsPacExpectation(pac_model_name))
{
{
set<pair<int, int>> endogs;
set<pair<int, int>> endogs;
equation->
get_
arg1
()
->collectDynamicVariables(SymbolType::endogenous, endogs);
equation->arg1->collectDynamicVariables(SymbolType::endogenous, endogs);
if (endogs.size() != 1)
if (endogs.size() != 1)
{
{
cerr << "The LHS of the PAC equation may only be comprised of one endogenous variable"
cerr << "The LHS of the PAC equation may only be comprised of one endogenous variable"
...
@@ -5296,8 +5296,8 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context
...
@@ -5296,8 +5296,8 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context
|| symbol_table.getType(it->first.first) == SymbolType::logTrend)
|| symbol_table.getType(it->first.first) == SymbolType::logTrend)
for (int eq = 0; eq < (int) equations.size(); eq++)
for (int eq = 0; eq < (int) equations.size(); eq++)
{
{
expr_t homogeneq = AddMinus(equations[eq]->
get_
arg1
()
,
expr_t homogeneq = AddMinus(equations[eq]->arg1,
equations[eq]->
get_
arg2
()
);
equations[eq]->arg2);
// Do not run the test if the term inside the log is zero
// Do not run the test if the term inside the log is zero
if (fabs(homogeneq->eval(eval_context)) > zero_band)
if (fabs(homogeneq->eval(eval_context)) > zero_band)
...
@@ -6007,13 +6007,13 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const
...
@@ -6007,13 +6007,13 @@ DynamicModel::fillEvalContext(eval_context_t &eval_context) const
// First, auxiliary variables
// First, auxiliary variables
for (auto aux_equation : aux_equations)
for (auto aux_equation : aux_equations)
{
{
assert(aux_equation->
get_
op_code
()
== BinaryOpcode::equal);
assert(aux_equation->op_code == BinaryOpcode::equal);
auto *auxvar = dynamic_cast<VariableNode *>(aux_equation->
get_
arg1
()
);
auto *auxvar = dynamic_cast<VariableNode *>(aux_equation->arg1);
assert(auxvar != nullptr);
assert(auxvar != nullptr);
try
try
{
{
double val = aux_equation->
get_
arg2
()
->eval(eval_context);
double val = aux_equation->arg2->eval(eval_context);
eval_context[auxvar->
get_
symb_id
()
] = val;
eval_context[auxvar->symb_id] = val;
}
}
catch (ExprNode::EvalException &e)
catch (ExprNode::EvalException &e)
{
{
...
@@ -6060,7 +6060,7 @@ void
...
@@ -6060,7 +6060,7 @@ void
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno, const vector<pair<string, string>> &eq_tags)
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno, const vector<pair<string, string>> &eq_tags)
{
{
auto *beq = dynamic_cast<BinaryOpNode *>(eq);
auto *beq = dynamic_cast<BinaryOpNode *>(eq);
assert(beq != nullptr && beq->
get_
op_code
()
== BinaryOpcode::equal);
assert(beq != nullptr && beq->op_code == BinaryOpcode::equal);
vector<pair<string, string>> soe_eq_tags;
vector<pair<string, string>> soe_eq_tags;
for (const auto & eq_tag : eq_tags)
for (const auto & eq_tag : eq_tags)
...
@@ -6107,8 +6107,8 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const
...
@@ -6107,8 +6107,8 @@ DynamicModel::isChecksumMatching(const string &basename, bool block) const
for (int eq = 0; eq < (int) equations.size(); eq++)
for (int eq = 0; eq < (int) equations.size(); eq++)
{
{
BinaryOpNode *eq_node = equations[eq];
BinaryOpNode *eq_node = equations[eq];
expr_t lhs = eq_node->
get_
arg1
()
;
expr_t lhs = eq_node->arg1;
expr_t rhs = eq_node->
get_
arg2
()
;
expr_t rhs = eq_node->arg2;
// Test if the right hand side of the equation is empty.
// Test if the right hand side of the equation is empty.
double vrhs = 1.0;
double vrhs = 1.0;
...
...
src/ExprNode.cc
View file @
b88e0de5
...
@@ -1863,22 +1863,22 @@ VariableNode::replaceTrendVar() const
...
@@ -1863,22 +1863,22 @@ VariableNode::replaceTrendVar() const
expr_t
expr_t
VariableNode::detrend(int symb_id, bool log_trend, expr_t trend) const
VariableNode::detrend(int symb_id, bool log_trend, expr_t trend) const
{
{
if (
get_
symb_id
()
!= symb_id)
if (
this->
symb_id != symb_id)
return const_cast<VariableNode *>(this);
return const_cast<VariableNode *>(this);
if (log_trend)
if (log_trend)
{
{
if (
get_
lag
()
== 0)
if (lag == 0)
return datatree.AddPlus(const_cast<VariableNode *>(this), trend);
return datatree.AddPlus(const_cast<VariableNode *>(this), trend);
else
else
return datatree.AddPlus(const_cast<VariableNode *>(this), trend->decreaseLeadsLags(-
1*get_
lag
()
));
return datatree.AddPlus(const_cast<VariableNode *>(this), trend->decreaseLeadsLags(-lag));
}
}
else
else
{
{
if (
get_
lag
()
== 0)
if (lag == 0)
return datatree.AddTimes(const_cast<VariableNode *>(this), trend);
return datatree.AddTimes(const_cast<VariableNode *>(this), trend);
else
else
return datatree.AddTimes(const_cast<VariableNode *>(this), trend->decreaseLeadsLags(-
1*get_
lag
()
));
return datatree.AddTimes(const_cast<VariableNode *>(this), trend->decreaseLeadsLags(-lag));
}
}
}
}
...
@@ -1891,7 +1891,7 @@ VariableNode::countDiffs() const
...
@@ -1891,7 +1891,7 @@ VariableNode::countDiffs() const
expr_t
expr_t
VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
{
{
if ((get_type() != SymbolType::trend && get_type() != SymbolType::logTrend) ||
get_
lag
()
== 0)
if ((get_type() != SymbolType::trend && get_type() != SymbolType::logTrend) || lag == 0)
return const_cast<VariableNode *>(this);
return const_cast<VariableNode *>(this);
map<int, expr_t>::const_iterator it = trend_symbols_map.find(symb_id);
map<int, expr_t>::const_iterator it = trend_symbols_map.find(symb_id);
...
@@ -1899,18 +1899,18 @@ VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
...
@@ -1899,18 +1899,18 @@ VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
bool log_trend = get_type() == SymbolType::logTrend;
bool log_trend = get_type() == SymbolType::logTrend;
expr_t trend = it->second;
expr_t trend = it->second;
if (
get_
lag
()
> 0)
if (lag > 0)
{
{
expr_t growthFactorSequence = trend->decreaseLeadsLags(-1);
expr_t growthFactorSequence = trend->decreaseLeadsLags(-1);
if (log_trend)
if (log_trend)
{
{
for (int i = 1; i <
get_
lag
()
; i++)
for (int i = 1; i < lag; i++)
growthFactorSequence = datatree.AddPlus(growthFactorSequence, trend->decreaseLeadsLags(-1*(i+1)));
growthFactorSequence = datatree.AddPlus(growthFactorSequence, trend->decreaseLeadsLags(-1*(i+1)));
return datatree.AddPlus(noTrendLeadLagNode, growthFactorSequence);
return datatree.AddPlus(noTrendLeadLagNode, growthFactorSequence);
}
}
else
else
{
{
for (int i = 1; i <
get_
lag
()
; i++)
for (int i = 1; i < lag; i++)
growthFactorSequence = datatree.AddTimes(growthFactorSequence, trend->decreaseLeadsLags(-1*(i+1)));
growthFactorSequence = datatree.AddTimes(growthFactorSequence, trend->decreaseLeadsLags(-1*(i+1)));
return datatree.AddTimes(noTrendLeadLagNode, growthFactorSequence);
return datatree.AddTimes(noTrendLeadLagNode, growthFactorSequence);
}
}
...
@@ -1920,13 +1920,13 @@ VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
...
@@ -1920,13 +1920,13 @@ VariableNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
expr_t growthFactorSequence = trend;
expr_t growthFactorSequence = trend;
if (log_trend)
if (log_trend)
{
{
for (int i = 1; i < abs(
get_
lag
()
); i++)
for (int i = 1; i < abs(lag); i++)
growthFactorSequence = datatree.AddPlus(growthFactorSequence, trend->decreaseLeadsLags(i));
growthFactorSequence = datatree.AddPlus(growthFactorSequence, trend->decreaseLeadsLags(i));
return datatree.AddMinus(noTrendLeadLagNode, growthFactorSequence);
return datatree.AddMinus(noTrendLeadLagNode, growthFactorSequence);
}
}
else
else
{
{
for (int i = 1; i < abs(
get_
lag
()
); i++)
for (int i = 1; i < abs(lag); i++)
growthFactorSequence = datatree.AddTimes(growthFactorSequence, trend->decreaseLeadsLags(i));
growthFactorSequence = datatree.AddTimes(growthFactorSequence, trend->decreaseLeadsLags(i));
return datatree.AddDivide(noTrendLeadLagNode, growthFactorSequence);
return datatree.AddDivide(noTrendLeadLagNode, growthFactorSequence);
}
}
...
@@ -3411,12 +3411,12 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table,
...
@@ -3411,12 +3411,12 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table,
rit != it->second.rend(); rit++)
rit != it->second.rend(); rit++)
{
{
expr_t argsubst = dynamic_cast<UnaryOpNode *>(rit->second)->
expr_t argsubst = dynamic_cast<UnaryOpNode *>(rit->second)->
get_
arg
()
->substituteDiff(static_datatree, diff_table, subst_table, neweqs);
arg->substituteDiff(static_datatree, diff_table, subst_table, neweqs);
auto *vn = dynamic_cast<VariableNode *>(argsubst);
auto *vn = dynamic_cast<VariableNode *>(argsubst);
if (rit == it->second.rbegin())
if (rit == it->second.rbegin())
{
{
if (vn != nullptr)
if (vn != nullptr)
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst, vn->
get_
symb_id
()
, vn->
get_
lag
()
);
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst, vn->symb_id, vn->lag);
else
else
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst);
symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst);
...
@@ -3437,10 +3437,10 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table,
...
@@ -3437,10 +3437,10 @@ UnaryOpNode::substituteDiff(DataTree &static_datatree, diff_table_t &diff_table,
{
{
if (i == last_arg_max_lag)
if (i == last_arg_max_lag)
symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(argsubst->idx, argsubst,
symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(argsubst->idx, argsubst,
last_aux_var->
get_
symb_id
()
, last_aux_var->
get_
lag
()
);
last_aux_var->symb_id, last_aux_var->lag);
else
else
symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(new_aux_var->idx, new_aux_var,
symb_id = datatree.symbol_table.addDiffLagAuxiliaryVar(new_aux_var->idx, new_aux_var,
last_aux_var->
get_
symb_id
()
, last_aux_var->
get_
lag
()
);
last_aux_var->symb_id, last_aux_var->lag);
new_aux_var = datatree.AddVariable(symb_id, 0);
new_aux_var = datatree.AddVariable(symb_id, 0);
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(new_aux_var,
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(new_aux_var,
...
@@ -3545,7 +3545,7 @@ UnaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nod
...
@@ -3545,7 +3545,7 @@ UnaryOpNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nod
symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op);
symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op);
else
else
symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op,
symb_id = datatree.symbol_table.addUnaryOpAuxiliaryVar(this->idx, dynamic_cast<UnaryOpNode *>(rit->second), unary_op,
vn->
get_
symb_id
()
, vn->
get_
lag
()
);
vn->symb_id, vn->lag);
aux_var = datatree.AddVariable(symb_id, 0);
aux_var = datatree.AddVariable(symb_id, 0);
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(aux_var,
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(aux_var,
dynamic_cast<UnaryOpNode *>(rit->second))));
dynamic_cast<UnaryOpNode *>(rit->second))));
...
@@ -5450,10 +5450,10 @@ BinaryOpNode::findTargetVariableHelper(const expr_t arg1, const expr_t arg2,
...
@@ -5450,10 +5450,10 @@ BinaryOpNode::findTargetVariableHelper(const expr_t arg1, const expr_t arg2,
if (endogs.size() == 2)