Port to C++11 range-based for loops

Performed using modernize-loop-convert from clang-tidy.

Manual intervention was needed in MacroValue.cc because of a variable name
capture issue.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-loop-convert.html
issue#70
Sébastien Villemot 2018-06-04 12:26:16 +02:00
parent 80d1e1e1fd
commit 6cf4e6dc0c
18 changed files with 1189 additions and 1432 deletions

View File

@ -1047,17 +1047,16 @@ RamseyPolicyStatement::checkPass(ModFileStructure &mod_file_struct, WarningConso
void void
RamseyPolicyStatement::checkRamseyPolicyList() RamseyPolicyStatement::checkRamseyPolicyList()
{ {
for (vector<string>::const_iterator it = ramsey_policy_list.begin(); for (const auto & it : ramsey_policy_list)
it != ramsey_policy_list.end(); it++)
{ {
if (!symbol_table.exists(*it)) if (!symbol_table.exists(it))
{ {
cerr << "ERROR: ramsey_policy: " << *it << " was not declared." << endl; cerr << "ERROR: ramsey_policy: " << it << " was not declared." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (symbol_table.getType(*it) != eEndogenous) if (symbol_table.getType(it) != eEndogenous)
{ {
cerr << "ERROR: ramsey_policy: " << *it << " is not endogenous." << endl; cerr << "ERROR: ramsey_policy: " << it << " is not endogenous." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -1449,18 +1448,17 @@ EstimatedParamsStatement::EstimatedParamsStatement(const vector<EstimationParams
void void
EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{ {
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin(); for (const auto & it : estim_params_list)
it != estim_params_list.end(); it++)
{ {
if (it->name == "dsge_prior_weight") if (it.name == "dsge_prior_weight")
mod_file_struct.dsge_prior_weight_in_estimated_params = true; mod_file_struct.dsge_prior_weight_in_estimated_params = true;
// Handle case of degenerate beta prior // Handle case of degenerate beta prior
if (it->prior == eBeta) if (it.prior == eBeta)
try try
{ {
if (it->mean->eval(eval_context_t()) == 0.5 if (it.mean->eval(eval_context_t()) == 0.5
&& it->std->eval(eval_context_t()) == 0.5) && it.std->eval(eval_context_t()) == 0.5)
{ {
cerr << "ERROR: The prior density is not defined for the beta distribution when the mean = standard deviation = 0.5." << endl; cerr << "ERROR: The prior density is not defined for the beta distribution when the mean = standard deviation = 0.5." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
@ -1475,39 +1473,37 @@ EstimatedParamsStatement::checkPass(ModFileStructure &mod_file_struct, WarningCo
// Check that no parameter/endogenous is declared twice in the block // Check that no parameter/endogenous is declared twice in the block
set<string> already_declared; set<string> already_declared;
set<pair<string, string> > already_declared_corr; set<pair<string, string> > already_declared_corr;
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin(); for (const auto & it : estim_params_list)
it != estim_params_list.end(); it++)
{ {
if (it->type == 3) // Correlation if (it.type == 3) // Correlation
{ {
// Use lexical ordering for the pair of symbols // Use lexical ordering for the pair of symbols
pair<string, string> x = it->name < it->name2 ? make_pair(it->name, it->name2) : make_pair(it->name2, it->name); pair<string, string> x = it.name < it.name2 ? make_pair(it.name, it.name2) : make_pair(it.name2, it.name);
if (already_declared_corr.find(x) == already_declared_corr.end()) if (already_declared_corr.find(x) == already_declared_corr.end())
already_declared_corr.insert(x); already_declared_corr.insert(x);
else else
{ {
cerr << "ERROR: in `estimated_params' block, the correlation between " << it->name << " and " << it->name2 << " is declared twice." << endl; cerr << "ERROR: in `estimated_params' block, the correlation between " << it.name << " and " << it.name2 << " is declared twice." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
else else
{ {
if (already_declared.find(it->name) == already_declared.end()) if (already_declared.find(it.name) == already_declared.end())
already_declared.insert(it->name); already_declared.insert(it.name);
else else
{ {
cerr << "ERROR: in `estimated_params' block, the symbol " << it->name << " is declared twice." << endl; cerr << "ERROR: in `estimated_params' block, the symbol " << it.name << " is declared twice." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
} }
// Fill in mod_file_struct.estimated_parameters (related to #469) // Fill in mod_file_struct.estimated_parameters (related to #469)
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin(); for (const auto & it : estim_params_list)
it != estim_params_list.end(); it++) if (it.type == 2 && it.name != "dsge_prior_weight")
if (it->type == 2 && it->name != "dsge_prior_weight") mod_file_struct.estimated_parameters.insert(symbol_table.getID(it.name));
mod_file_struct.estimated_parameters.insert(symbol_table.getID(it->name));
} }
void void
@ -1519,12 +1515,12 @@ EstimatedParamsStatement::writeOutput(ostream &output, const string &basename, b
<< "estim_params_.corrn = [];" << endl << "estim_params_.corrn = [];" << endl
<< "estim_params_.param_vals = [];" << endl; << "estim_params_.param_vals = [];" << endl;
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin(); it != estim_params_list.end(); it++) for (const auto & it : estim_params_list)
{ {
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1; int symb_id = symbol_table.getTypeSpecificID(it.name) + 1;
SymbolType symb_type = symbol_table.getType(it->name); SymbolType symb_type = symbol_table.getType(it.name);
switch (it->type) switch (it.type)
{ {
case 1: case 1:
if (symb_type == eExogenous) if (symb_type == eExogenous)
@ -1542,26 +1538,26 @@ EstimatedParamsStatement::writeOutput(ostream &output, const string &basename, b
output << "estim_params_.corrx = [estim_params_.corrx; "; output << "estim_params_.corrx = [estim_params_.corrx; ";
else if (symb_type == eEndogenous) else if (symb_type == eEndogenous)
output << "estim_params_.corrn = [estim_params_.corrn; "; output << "estim_params_.corrn = [estim_params_.corrn; ";
output << symb_id << " " << symbol_table.getTypeSpecificID(it->name2)+1; output << symb_id << " " << symbol_table.getTypeSpecificID(it.name2)+1;
break; break;
} }
output << ", "; output << ", ";
it->init_val->writeOutput(output); it.init_val->writeOutput(output);
output << ", "; output << ", ";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ", "; output << ", ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << ", " output << ", "
<< it->prior << ", "; << it.prior << ", ";
it->mean->writeOutput(output); it.mean->writeOutput(output);
output << ", "; output << ", ";
it->std->writeOutput(output); it.std->writeOutput(output);
output << ", "; output << ", ";
it->p3->writeOutput(output); it.p3->writeOutput(output);
output << ", "; output << ", ";
it->p4->writeOutput(output); it.p4->writeOutput(output);
output << ", "; output << ", ";
it->jscale->writeOutput(output); it.jscale->writeOutput(output);
output << " ];" << endl; output << " ];" << endl;
} }
} }
@ -1636,32 +1632,32 @@ EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basenam
if (use_calibration) if (use_calibration)
output << "options_.use_calibration_initialization = 1;" << endl; output << "options_.use_calibration_initialization = 1;" << endl;
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin(); it != estim_params_list.end(); it++) for (const auto & it : estim_params_list)
{ {
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1; int symb_id = symbol_table.getTypeSpecificID(it.name) + 1;
SymbolType symb_type = symbol_table.getType(it->name); SymbolType symb_type = symbol_table.getType(it.name);
if (it->type < 3) if (it.type < 3)
{ {
if (symb_type == eExogenous) if (symb_type == eExogenous)
{ {
output << "tmp1 = find(estim_params_.var_exo(:,1)==" << symb_id << ");" << endl; output << "tmp1 = find(estim_params_.var_exo(:,1)==" << symb_id << ");" << endl;
output << "estim_params_.var_exo(tmp1,2) = "; output << "estim_params_.var_exo(tmp1,2) = ";
it->init_val->writeOutput(output); it.init_val->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
else if (symb_type == eEndogenous) else if (symb_type == eEndogenous)
{ {
output << "tmp1 = find(estim_params_.var_endo(:,1)==" << symb_id << ");" << endl; output << "tmp1 = find(estim_params_.var_endo(:,1)==" << symb_id << ");" << endl;
output << "estim_params_.var_endo(tmp1,2) = "; output << "estim_params_.var_endo(tmp1,2) = ";
it->init_val->writeOutput(output); it.init_val->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
else if (symb_type == eParameter) else if (symb_type == eParameter)
{ {
output << "tmp1 = find(estim_params_.param_vals(:,1)==" << symb_id << ");" << endl; output << "tmp1 = find(estim_params_.param_vals(:,1)==" << symb_id << ");" << endl;
output << "estim_params_.param_vals(tmp1,2) = "; output << "estim_params_.param_vals(tmp1,2) = ";
it->init_val->writeOutput(output); it.init_val->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -1669,18 +1665,18 @@ EstimatedParamsInitStatement::writeOutput(ostream &output, const string &basenam
{ {
if (symb_type == eExogenous) if (symb_type == eExogenous)
{ {
output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " & estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " & estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it.name2)+1 << ") | "
<< "(estim_params_.corrx(:,2)==" << symb_id << " & estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; << "(estim_params_.corrx(:,2)==" << symb_id << " & estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it.name2)+1 << "));" << endl;
output << "estim_params_.corrx(tmp1,3) = "; output << "estim_params_.corrx(tmp1,3) = ";
it->init_val->writeOutput(output); it.init_val->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
else if (symb_type == eEndogenous) else if (symb_type == eEndogenous)
{ {
output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " & estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " & estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it.name2)+1 << ") | "
<< "(estim_params_.corrn(:,2)==" << symb_id << " & estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; << "(estim_params_.corrn(:,2)==" << symb_id << " & estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it.name2)+1 << "));" << endl;
output << "estim_params_.corrn(tmp1,3) = "; output << "estim_params_.corrn(tmp1,3) = ";
it->init_val->writeOutput(output); it.init_val->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -1732,23 +1728,23 @@ EstimatedParamsBoundsStatement::EstimatedParamsBoundsStatement(const vector<Esti
void void
EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{ {
for (vector<EstimationParams>::const_iterator it = estim_params_list.begin(); it != estim_params_list.end(); it++) for (const auto & it : estim_params_list)
{ {
int symb_id = symbol_table.getTypeSpecificID(it->name) + 1; int symb_id = symbol_table.getTypeSpecificID(it.name) + 1;
SymbolType symb_type = symbol_table.getType(it->name); SymbolType symb_type = symbol_table.getType(it.name);
if (it->type < 3) if (it.type < 3)
{ {
if (symb_type == eExogenous) if (symb_type == eExogenous)
{ {
output << "tmp1 = find(estim_params_.var_exo(:,1)==" << symb_id << ");" << endl; output << "tmp1 = find(estim_params_.var_exo(:,1)==" << symb_id << ");" << endl;
output << "estim_params_.var_exo(tmp1,3) = "; output << "estim_params_.var_exo(tmp1,3) = ";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
output << "estim_params_.var_exo(tmp1,4) = "; output << "estim_params_.var_exo(tmp1,4) = ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
else if (symb_type == eEndogenous) else if (symb_type == eEndogenous)
@ -1756,11 +1752,11 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
output << "tmp1 = find(estim_params_.var_endo(:,1)==" << symb_id << ");" << endl; output << "tmp1 = find(estim_params_.var_endo(:,1)==" << symb_id << ");" << endl;
output << "estim_params_.var_endo(tmp1,3) = "; output << "estim_params_.var_endo(tmp1,3) = ";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
output << "estim_params_.var_endo(tmp1,4) = "; output << "estim_params_.var_endo(tmp1,4) = ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
else if (symb_type == eParameter) else if (symb_type == eParameter)
@ -1768,11 +1764,11 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
output << "tmp1 = find(estim_params_.param_vals(:,1)==" << symb_id << ");" << endl; output << "tmp1 = find(estim_params_.param_vals(:,1)==" << symb_id << ");" << endl;
output << "estim_params_.param_vals(tmp1,3) = "; output << "estim_params_.param_vals(tmp1,3) = ";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
output << "estim_params_.param_vals(tmp1,4) = "; output << "estim_params_.param_vals(tmp1,4) = ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -1780,28 +1776,28 @@ EstimatedParamsBoundsStatement::writeOutput(ostream &output, const string &basen
{ {
if (symb_type == eExogenous) if (symb_type == eExogenous)
{ {
output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " & estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " output << "tmp1 = find((estim_params_.corrx(:,1)==" << symb_id << " & estim_params_.corrx(:,2)==" << symbol_table.getTypeSpecificID(it.name2)+1 << ") | "
<< "(estim_params_.corrx(:,2)==" << symb_id << " & estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; << "(estim_params_.corrx(:,2)==" << symb_id << " & estim_params_.corrx(:,1)==" << symbol_table.getTypeSpecificID(it.name2)+1 << "));" << endl;
output << "estim_params_.corrx(tmp1,4) = "; output << "estim_params_.corrx(tmp1,4) = ";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
output << "estim_params_.corrx(tmp1,5) = "; output << "estim_params_.corrx(tmp1,5) = ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
else if (symb_type == eEndogenous) else if (symb_type == eEndogenous)
{ {
output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " & estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it->name2)+1 << ") | " output << "tmp1 = find((estim_params_.corrn(:,1)==" << symb_id << " & estim_params_.corrn(:,2)==" << symbol_table.getTypeSpecificID(it.name2)+1 << ") | "
<< "(estim_params_.corrn(:,2)==" << symb_id << " & estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it->name2)+1 << "));" << endl; << "(estim_params_.corrn(:,2)==" << symb_id << " & estim_params_.corrn(:,1)==" << symbol_table.getTypeSpecificID(it.name2)+1 << "));" << endl;
output << "estim_params_.corrn(tmp1,4) = "; output << "estim_params_.corrn(tmp1,4) = ";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
output << "estim_params_.corrn(tmp1,5) = "; output << "estim_params_.corrn(tmp1,5) = ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -1852,18 +1848,18 @@ void
ObservationTrendsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const ObservationTrendsStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{ {
output << "options_.trend_coeff = {};" << endl; output << "options_.trend_coeff = {};" << endl;
for (trend_elements_t::const_iterator it = trend_elements.begin(); it != trend_elements.end(); it++) for (const auto & trend_element : trend_elements)
{ {
SymbolType type = symbol_table.getType(it->first); SymbolType type = symbol_table.getType(trend_element.first);
if (type == eEndogenous) if (type == eEndogenous)
{ {
output << "tmp1 = strmatch('" << it->first << "',options_.varobs,'exact');" << endl; output << "tmp1 = strmatch('" << trend_element.first << "',options_.varobs,'exact');" << endl;
output << "options_.trend_coeffs{tmp1} = '"; output << "options_.trend_coeffs{tmp1} = '";
it->second->writeOutput(output); trend_element.second->writeOutput(output);
output << "';" << endl; output << "';" << endl;
} }
else else
cerr << "Warning : Non-variable symbol used in observation_trends: " << it->first << endl; cerr << "Warning : Non-variable symbol used in observation_trends: " << trend_element.first << endl;
} }
} }
@ -1873,20 +1869,19 @@ ObservationTrendsStatement::writeJsonOutput(ostream &output) const
output << "{\"statementName\": \"observation_trends\", " output << "{\"statementName\": \"observation_trends\", "
<< "\"trends\" : {"; << "\"trends\" : {";
bool printed = false; bool printed = false;
for (trend_elements_t::const_iterator it = trend_elements.begin(); for (const auto & trend_element : trend_elements)
it != trend_elements.end(); it++)
{ {
if (symbol_table.getType(it->first) == eEndogenous) if (symbol_table.getType(trend_element.first) == eEndogenous)
{ {
if (printed) if (printed)
output << ", "; output << ", ";
output << "\"" << it->first << "\": \""; output << "\"" << trend_element.first << "\": \"";
it->second->writeJsonOutput(output, {}, {}); trend_element.second->writeJsonOutput(output, {}, {});
output << "\"" << endl; output << "\"" << endl;
printed = true; printed = true;
} }
else else
cerr << "Warning : Non-variable symbol used in observation_trends: " << it->first << endl; cerr << "Warning : Non-variable symbol used in observation_trends: " << trend_element.first << endl;
} }
output << "}" output << "}"
<< "}"; << "}";
@ -1958,13 +1953,12 @@ OsrParamsBoundsStatement::writeOutput(ostream &output, const string &basename, b
output << "M_.osr.param_bounds = [-inf(length(M_.osr.param_names), 1), inf(length(M_.osr.param_names), 1)];" << endl; output << "M_.osr.param_bounds = [-inf(length(M_.osr.param_names), 1), inf(length(M_.osr.param_names), 1)];" << endl;
for (vector<OsrParams>::const_iterator it = osr_params_list.begin(); for (const auto & it : osr_params_list)
it != osr_params_list.end(); it++)
{ {
output << "M_.osr.param_bounds(strcmp(M_.osr.param_names, '" << it->name << "'), :) = ["; output << "M_.osr.param_bounds(strcmp(M_.osr.param_names, '" << it.name << "'), :) = [";
it->low_bound->writeOutput(output); it.low_bound->writeOutput(output);
output << ", "; output << ", ";
it->up_bound->writeOutput(output); it.up_bound->writeOutput(output);
output << "];" << endl; output << "];" << endl;
} }
} }
@ -2069,11 +2063,10 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename, bool
<< "M_.osr.variable_weights = sparse(M_.endo_nbr,M_.endo_nbr);" << endl << "M_.osr.variable_weights = sparse(M_.endo_nbr,M_.endo_nbr);" << endl
<< "M_.osr.variable_indices = [];" << endl << endl; << "M_.osr.variable_indices = [];" << endl << endl;
for (var_weights_t::const_iterator it = var_weights.begin(); for (const auto & var_weight : var_weights)
it != var_weights.end(); it++)
{ {
const string &name = it->first; const string &name = var_weight.first;
const expr_t value = it->second; const expr_t value = var_weight.second;
int id = symbol_table.getTypeSpecificID(name) + 1; int id = symbol_table.getTypeSpecificID(name) + 1;
output << "M_.osr.variable_weights(" << id << "," << id << ") = "; output << "M_.osr.variable_weights(" << id << "," << id << ") = ";
value->writeOutput(output); value->writeOutput(output);
@ -2081,12 +2074,11 @@ OptimWeightsStatement::writeOutput(ostream &output, const string &basename, bool
output << "M_.osr.variable_indices = [M_.osr.variable_indices; " << id << "];" << endl; output << "M_.osr.variable_indices = [M_.osr.variable_indices; " << id << "];" << endl;
} }
for (covar_weights_t::const_iterator it = covar_weights.begin(); for (const auto & covar_weight : covar_weights)
it != covar_weights.end(); it++)
{ {
const string &name1 = it->first.first; const string &name1 = covar_weight.first.first;
const string &name2 = it->first.second; const string &name2 = covar_weight.first.second;
const expr_t value = it->second; const expr_t value = covar_weight.second;
int id1 = symbol_table.getTypeSpecificID(name1) + 1; int id1 = symbol_table.getTypeSpecificID(name1) + 1;
int id2 = symbol_table.getTypeSpecificID(name2) + 1; int id2 = symbol_table.getTypeSpecificID(name2) + 1;
output << "M_.osr.variable_weights(" << id1 << "," << id2 << ") = "; output << "M_.osr.variable_weights(" << id1 << "," << id2 << ") = ";
@ -2198,11 +2190,10 @@ ModelComparisonStatement::writeOutput(ostream &output, const string &basename, b
output << "ModelNames_ = {};" << endl; output << "ModelNames_ = {};" << endl;
output << "ModelPriors_ = [];" << endl; output << "ModelPriors_ = [];" << endl;
for (filename_list_t::const_iterator it = filename_list.begin(); for (const auto & it : filename_list)
it != filename_list.end(); it++)
{ {
output << "ModelNames_ = { ModelNames_{:} '" << (*it).first << "'};" << endl; output << "ModelNames_ = { ModelNames_{:} '" << it.first << "'};" << endl;
output << "ModelPriors_ = [ ModelPriors_ ; " << (*it).second << "];" << endl; output << "ModelPriors_ = [ ModelPriors_ ; " << it.second << "];" << endl;
} }
output << "oo_ = model_comparison(ModelNames_,ModelPriors_,oo_,options_,M_.fname);" << endl; output << "oo_ = model_comparison(ModelNames_,ModelPriors_,oo_,options_,M_.fname);" << endl;
} }
@ -2970,9 +2961,9 @@ int
SvarIdentificationStatement::getMaxLag() const SvarIdentificationStatement::getMaxLag() const
{ {
int max_lag = 0; int max_lag = 0;
for (svar_identification_restrictions_t::const_iterator it = restrictions.begin(); it != restrictions.end(); it++) for (const auto & restriction : restrictions)
if (it->lag > max_lag) if (restriction.lag > max_lag)
max_lag = it->lag; max_lag = restriction.lag;
return max_lag; return max_lag;
} }
@ -3113,12 +3104,11 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(const OptionsList &options_li
vector<string> tokenizedRestrictions; vector<string> tokenizedRestrictions;
split(tokenizedRestrictions, it_num->second, is_any_of("["), token_compress_on); split(tokenizedRestrictions, it_num->second, is_any_of("["), token_compress_on);
for (vector<string>::iterator it = tokenizedRestrictions.begin(); for (auto & tokenizedRestriction : tokenizedRestrictions)
it != tokenizedRestrictions.end(); it++) if (tokenizedRestriction.size() > 0)
if (it->size() > 0)
{ {
vector<string> restriction; vector<string> restriction;
split(restriction, *it, is_any_of("], ")); split(restriction, tokenizedRestriction, is_any_of("], "));
for (vector<string>::iterator it1 = restriction.begin(); for (vector<string>::iterator it1 = restriction.begin();
it1 != restriction.end();) it1 != restriction.end();)
if (it1->empty()) if (it1->empty())
@ -3165,7 +3155,7 @@ MarkovSwitchingStatement::MarkovSwitchingStatement(const OptionsList &options_li
{ {
cerr << "ERROR: The first two arguments for a restriction must be integers " cerr << "ERROR: The first two arguments for a restriction must be integers "
<< "specifying the regime and the last must be a double specifying the " << "specifying the regime and the last must be a double specifying the "
<< "transition probability. You wrote [" << *it << endl; << "transition probability. You wrote [" << tokenizedRestriction << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -3314,25 +3304,22 @@ MarkovSwitchingStatement::writeCOutput(ostream &output, const string &basename)
using namespace boost; using namespace boost;
vector<string> tokenizedDomain; vector<string> tokenizedDomain;
split(tokenizedDomain, it->second, is_any_of("[ ]"), token_compress_on); split(tokenizedDomain, it->second, is_any_of("[ ]"), token_compress_on);
for (vector<string>::iterator itvs = tokenizedDomain.begin(); for (auto & itvs : tokenizedDomain)
itvs != tokenizedDomain.end(); itvs++) if (!itvs.empty())
if (!itvs->empty()) output << "duration.push_back(" << itvs << ");" << endl;
output << "duration.push_back(" << *itvs << ");" << endl;
OptionsList::symbol_list_options_t::const_iterator itsl OptionsList::symbol_list_options_t::const_iterator itsl
= options_list.symbol_list_options.find("ms.parameters"); = options_list.symbol_list_options.find("ms.parameters");
assert(itsl != options_list.symbol_list_options.end()); assert(itsl != options_list.symbol_list_options.end());
vector<string> parameters = itsl->second.get_symbols(); vector<string> parameters = itsl->second.get_symbols();
output << "parameters.clear();" << endl; output << "parameters.clear();" << endl;
for (vector<string>::iterator itp = parameters.begin(); for (auto & parameter : parameters)
itp != parameters.end(); itp++) output << "parameters.push_back(param_names[\"" << parameter << "\"]);" << endl;
output << "parameters.push_back(param_names[\"" << *itp << "\"]);" << endl;
output << "restriction_map.clear();" << endl; output << "restriction_map.clear();" << endl;
for (map <pair<int, int >, double >::iterator itrm = restriction_map.begin(); for (auto & itrm : restriction_map)
itrm != restriction_map.end(); itrm++) output << "restriction_map[make_pair(" << itrm.first.first << ","
output << "restriction_map[make_pair(" << itrm->first.first << "," << itrm.first.second << ")] = " << itrm.second << ";" << endl;
<< itrm->first.second << ")] = " << itrm->second << ";" << endl;
output << "msdsgeinfo->addMarkovSwitching(new MarkovSwitching(" << endl output << "msdsgeinfo->addMarkovSwitching(new MarkovSwitching(" << endl
<< " chain, number_of_regimes, number_of_lags, number_of_lags_was_passed, parameters, duration, restriction_map));" << endl; << " chain, number_of_regimes, number_of_lags, number_of_lags_was_passed, parameters, duration, restriction_map));" << endl;
@ -3417,9 +3404,8 @@ SvarStatement::writeOutput(ostream &output, const string &basename, bool minimal
if (itv->second.size() > 1) if (itv->second.size() > 1)
{ {
output << "["; output << "[";
for (vector<int>::const_iterator viit = itv->second.begin(); for (int viit : itv->second)
viit != itv->second.end(); viit++) output << viit << ";";
output << *viit << ";";
output << "];" << endl; output << "];" << endl;
} }
else else
@ -3751,14 +3737,14 @@ JointPriorStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsoli
void void
JointPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const JointPriorStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{ {
for (vector<string>::const_iterator it = joint_parameters.begin(); it != joint_parameters.end(); it++) for (const auto & joint_parameter : joint_parameters)
output << "eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', '" output << "eifind = get_new_or_existing_ei_index('joint_parameter_prior_index', '"
<< *it << "', '');" << endl << joint_parameter << "', '');" << endl
<< "estimation_info.joint_parameter_prior_index(eifind) = {'" << *it << "'};" << endl; << "estimation_info.joint_parameter_prior_index(eifind) = {'" << joint_parameter << "'};" << endl;
output << "key = {["; output << "key = {[";
for (vector<string>::const_iterator it = joint_parameters.begin(); it != joint_parameters.end(); it++) for (const auto & joint_parameter : joint_parameters)
output << "get_new_or_existing_ei_index('joint_parameter_prior_index', '" << *it << "', '') ..." output << "get_new_or_existing_ei_index('joint_parameter_prior_index', '" << joint_parameter << "', '') ..."
<< endl << " "; << endl << " ";
output << "]};" << endl; output << "]};" << endl;
@ -4023,10 +4009,9 @@ BasicPriorStatement::writeCDomain(ostream &output) const
using namespace boost; using namespace boost;
vector<string> tokenizedDomain; vector<string> tokenizedDomain;
split(tokenizedDomain, it_num->second, is_any_of("[ ]"), token_compress_on); split(tokenizedDomain, it_num->second, is_any_of("[ ]"), token_compress_on);
for (vector<string>::iterator it = tokenizedDomain.begin(); for (auto & it : tokenizedDomain)
it != tokenizedDomain.end(); it++) if (!it.empty())
if (!it->empty()) output << "domain.push_back(" << it << ");" << endl;
output << "domain.push_back(" << *it << ");" << endl;
} }
} }
@ -4841,10 +4826,9 @@ ExtendedPathStatement::writeOutput(ostream &output, const string &basename, bool
{ {
// Beware: options do not have the same name in the interface and in the M code... // Beware: options do not have the same name in the interface and in the M code...
for (OptionsList::num_options_t::const_iterator it = options_list.num_options.begin(); for (const auto & num_option : options_list.num_options)
it != options_list.num_options.end(); ++it) if (num_option.first != string("periods"))
if (it->first != string("periods")) output << "options_." << num_option.first << " = " << num_option.second << ";" << endl;
output << "options_." << it->first << " = " << it->second << ";" << endl;
output << "extended_path([], " << options_list.num_options.find("periods")->second output << "extended_path([], " << options_list.num_options.find("periods")->second
<< ", [], options_, M_, oo_);" << endl; << ", [], options_, M_, oo_);" << endl;
@ -4986,9 +4970,8 @@ GenerateIRFsStatement::writeOutput(ostream &output, const string &basename, bool
return; return;
output << "options_.irf_opt.irf_shock_graphtitles = { "; output << "options_.irf_opt.irf_shock_graphtitles = { ";
for (vector<string>::const_iterator it = generate_irf_names.begin(); for (const auto & generate_irf_name : generate_irf_names)
it != generate_irf_names.end(); it++) output << "'" << generate_irf_name << "'; ";
output << "'" << *it << "'; ";
output << "};" << endl; output << "};" << endl;
output << "options_.irf_opt.irf_shocks = zeros(M_.exo_nbr, " output << "options_.irf_opt.irf_shocks = zeros(M_.exo_nbr, "

View File

@ -269,12 +269,11 @@ ConfigFile::getConfigFileInfo(const string &config_file)
{ {
vector<string> tokenizedPath; vector<string> tokenizedPath;
split(tokenizedPath, tokenizedLine.back(), is_any_of(":"), token_compress_on); split(tokenizedPath, tokenizedLine.back(), is_any_of(":"), token_compress_on);
for (vector<string>::iterator it = tokenizedPath.begin(); for (auto & it : tokenizedPath)
it != tokenizedPath.end(); it++) if (!it.empty())
if (!it->empty())
{ {
trim(*it); trim(it);
includepath.push_back(*it); includepath.push_back(it);
} }
} }
else else
@ -524,11 +523,11 @@ void
ConfigFile::checkPass(WarningConsolidation &warnings) const ConfigFile::checkPass(WarningConsolidation &warnings) const
{ {
bool global_init_file_declared = false; bool global_init_file_declared = false;
for (vector<Hook *>::const_iterator it = hooks.begin(); it != hooks.end(); it++) for (auto hook : hooks)
{ {
const map <string, string> hookmap = (*it)->get_hooks(); const map <string, string> hookmap = hook->get_hooks();
for (map <string, string>::const_iterator mapit = hookmap.begin(); mapit != hookmap.end(); mapit++) for (const auto & mapit : hookmap)
if (mapit->first.compare("global_init_file") == 0) if (mapit.first.compare("global_init_file") == 0)
if (global_init_file_declared == true) if (global_init_file_declared == true)
{ {
cerr << "ERROR: Only one global initialization file may be provided." << endl; cerr << "ERROR: Only one global initialization file may be provided." << endl;
@ -548,56 +547,55 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (map<string, SlaveNode *>::const_iterator it = slave_nodes.begin(); for (const auto & slave_node : slave_nodes)
it != slave_nodes.end(); it++)
{ {
#if !defined(_WIN32) && !defined(__CYGWIN32__) #if !defined(_WIN32) && !defined(__CYGWIN32__)
//For Linux/Mac, check that cpuNbr starts at 0 //For Linux/Mac, check that cpuNbr starts at 0
if (it->second->minCpuNbr != 0) if (slave_node.second->minCpuNbr != 0)
warnings << "WARNING: On Unix-based operating systems, you cannot specify the CPU that is " warnings << "WARNING: On Unix-based operating systems, you cannot specify the CPU that is "
<< "used in parallel processing. This will be adjusted for you such that the " << "used in parallel processing. This will be adjusted for you such that the "
<< "same number of CPUs are used." << endl; << "same number of CPUs are used." << endl;
#endif #endif
if (!it->second->port.empty()) if (!slave_node.second->port.empty())
try try
{ {
boost::lexical_cast< int >(it->second->port); boost::lexical_cast< int >(slave_node.second->port);
} }
catch (const boost::bad_lexical_cast &) catch (const boost::bad_lexical_cast &)
{ {
cerr << "ERROR (node " << it->first << "): the port must be an integer." << endl; cerr << "ERROR (node " << slave_node.first << "): the port must be an integer." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!it->second->computerName.compare("localhost")) // We are working locally if (!slave_node.second->computerName.compare("localhost")) // We are working locally
{ {
if (!it->second->remoteDrive.empty()) if (!slave_node.second->remoteDrive.empty())
{ {
cerr << "ERROR (node " << it->first << "): the RemoteDrive option may not be passed for a local node." << endl; cerr << "ERROR (node " << slave_node.first << "): the RemoteDrive option may not be passed for a local node." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (!it->second->remoteDirectory.empty()) if (!slave_node.second->remoteDirectory.empty())
{ {
cerr << "ERROR (node " << it->first << "): the RemoteDirectory option may not be passed for a local node." << endl; cerr << "ERROR (node " << slave_node.first << "): the RemoteDirectory option may not be passed for a local node." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
else else
{ {
if (it->second->userName.empty()) if (slave_node.second->userName.empty())
{ {
cerr << "ERROR (node " << it->first << "): the UserName option must be passed for every remote node." << endl; cerr << "ERROR (node " << slave_node.first << "): the UserName option must be passed for every remote node." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (it->second->operatingSystem.compare("windows") == 0) if (slave_node.second->operatingSystem.compare("windows") == 0)
{ {
if (it->second->password.empty()) if (slave_node.second->password.empty())
{ {
cerr << "ERROR (node " << it->first << "): the Password option must be passed under Windows for every remote node." << endl; cerr << "ERROR (node " << slave_node.first << "): the Password option must be passed under Windows for every remote node." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (it->second->remoteDrive.empty()) if (slave_node.second->remoteDrive.empty())
{ {
cerr << "ERROR (node " << it->first << "): the RemoteDrive option must be passed under Windows for every remote node." << endl; cerr << "ERROR (node " << slave_node.first << "): the RemoteDrive option must be passed under Windows for every remote node." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -616,9 +614,9 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const
} }
} }
#endif #endif
if (it->second->remoteDirectory.empty()) if (slave_node.second->remoteDirectory.empty())
{ {
cerr << "ERROR (node " << it->first << "): the RemoteDirectory must be specified for every remote node." << endl; cerr << "ERROR (node " << slave_node.first << "): the RemoteDirectory must be specified for every remote node." << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -637,13 +635,12 @@ ConfigFile::checkPass(WarningConsolidation &warnings) const
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
for (map<string, Cluster *>::const_iterator it = clusters.begin(); for (const auto & cluster : clusters)
it != clusters.end(); it++) for (member_nodes_t::const_iterator itmn = cluster.second->member_nodes.begin();
for (member_nodes_t::const_iterator itmn = it->second->member_nodes.begin(); itmn != cluster.second->member_nodes.end(); itmn++)
itmn != it->second->member_nodes.end(); itmn++)
if (slave_nodes.find(itmn->first) == slave_nodes.end()) if (slave_nodes.find(itmn->first) == slave_nodes.end())
{ {
cerr << "Error: node " << itmn->first << " specified in cluster " << it->first << " was not found" << endl; cerr << "Error: node " << itmn->first << " specified in cluster " << cluster.first << " was not found" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -676,21 +673,20 @@ ConfigFile::transformPass()
it != cluster_it->second->member_nodes.end(); it++) it != cluster_it->second->member_nodes.end(); it++)
weight_denominator += it->second; weight_denominator += it->second;
for (member_nodes_t::iterator it = cluster_it->second->member_nodes.begin(); for (auto & member_node : cluster_it->second->member_nodes)
it != cluster_it->second->member_nodes.end(); it++) member_node.second /= weight_denominator;
it->second /= weight_denominator;
} }
vector<string> vector<string>
ConfigFile::getIncludePaths() const ConfigFile::getIncludePaths() const
{ {
vector<string> include_paths; vector<string> include_paths;
for (vector<Path *>::const_iterator it = paths.begin(); it != paths.end(); it++) for (auto path : paths)
{ {
map <string, vector<string> > pathmap = (*it)->get_paths(); map <string, vector<string> > pathmap = path->get_paths();
for (map <string, vector<string> >::const_iterator mapit = pathmap.begin(); mapit != pathmap.end(); mapit++) for (map <string, vector<string> >::const_iterator mapit = pathmap.begin(); mapit != pathmap.end(); mapit++)
for (vector<string>::const_iterator vecit = mapit->second.begin(); vecit != mapit->second.end(); vecit++) for (const auto & vecit : mapit->second)
include_paths.push_back(*vecit); include_paths.push_back(vecit);
} }
return include_paths; return include_paths;
} }
@ -698,9 +694,9 @@ ConfigFile::getIncludePaths() const
void void
ConfigFile::writeHooks(ostream &output) const ConfigFile::writeHooks(ostream &output) const
{ {
for (vector<Hook *>::const_iterator it = hooks.begin(); it != hooks.end(); it++) for (auto hook : hooks)
{ {
map <string, string> hookmap = (*it)->get_hooks(); map <string, string> hookmap = hook->get_hooks();
for (map <string, string>::const_iterator mapit = hookmap.begin(); mapit != hookmap.end(); mapit++) for (map <string, string>::const_iterator mapit = hookmap.begin(); mapit != hookmap.end(); mapit++)
output << "options_." << mapit->first << " = '" << mapit->second << "';" << endl; output << "options_." << mapit->first << " = '" << mapit->second << "';" << endl;
} }
@ -719,13 +715,12 @@ ConfigFile::writeCluster(ostream &output) const
cluster_it = clusters.find(cluster_name); cluster_it = clusters.find(cluster_name);
int i = 1; int i = 1;
for (map<string, SlaveNode *>::const_iterator it = slave_nodes.begin(); for (const auto & slave_node : slave_nodes)
it != slave_nodes.end(); it++)
{ {
bool slave_node_in_member_nodes = false; bool slave_node_in_member_nodes = false;
for (member_nodes_t::const_iterator itmn = cluster_it->second->member_nodes.begin(); for (member_nodes_t::const_iterator itmn = cluster_it->second->member_nodes.begin();
itmn != cluster_it->second->member_nodes.end(); itmn++) itmn != cluster_it->second->member_nodes.end(); itmn++)
if (!it->first.compare(itmn->first)) if (!slave_node.first.compare(itmn->first))
slave_node_in_member_nodes = true; slave_node_in_member_nodes = true;
if (!slave_node_in_member_nodes) if (!slave_node_in_member_nodes)
@ -736,25 +731,25 @@ ConfigFile::writeCluster(ostream &output) const
output << "(" << i << ")"; output << "(" << i << ")";
i++; i++;
output << " = struct('Local', "; output << " = struct('Local', ";
if (it->second->computerName.compare("localhost")) if (slave_node.second->computerName.compare("localhost"))
output << "0, "; output << "0, ";
else else
output << "1, "; output << "1, ";
output << "'ComputerName', '" << it->second->computerName << "', " output << "'ComputerName', '" << slave_node.second->computerName << "', "
<< "'Port', '" << it->second->port << "', " << "'Port', '" << slave_node.second->port << "', "
<< "'CPUnbr', [" << it->second->minCpuNbr << ":" << it->second->maxCpuNbr << "], " << "'CPUnbr', [" << slave_node.second->minCpuNbr << ":" << slave_node.second->maxCpuNbr << "], "
<< "'UserName', '" << it->second->userName << "', " << "'UserName', '" << slave_node.second->userName << "', "
<< "'Password', '" << it->second->password << "', " << "'Password', '" << slave_node.second->password << "', "
<< "'RemoteDrive', '" << it->second->remoteDrive << "', " << "'RemoteDrive', '" << slave_node.second->remoteDrive << "', "
<< "'RemoteDirectory', '" << it->second->remoteDirectory << "', " << "'RemoteDirectory', '" << slave_node.second->remoteDirectory << "', "
<< "'DynarePath', '" << it->second->dynarePath << "', " << "'DynarePath', '" << slave_node.second->dynarePath << "', "
<< "'MatlabOctavePath', '" << it->second->matlabOctavePath << "', " << "'MatlabOctavePath', '" << slave_node.second->matlabOctavePath << "', "
<< "'OperatingSystem', '" << it->second->operatingSystem << "', " << "'OperatingSystem', '" << slave_node.second->operatingSystem << "', "
<< "'NodeWeight', '" << (cluster_it->second->member_nodes.find(it->first))->second << "', " << "'NodeWeight', '" << (cluster_it->second->member_nodes.find(slave_node.first))->second << "', "
<< "'NumberOfThreadsPerJob', " << it->second->numberOfThreadsPerJob << ", "; << "'NumberOfThreadsPerJob', " << slave_node.second->numberOfThreadsPerJob << ", ";
if (it->second->singleCompThread) if (slave_node.second->singleCompThread)
output << "'SingleCompThread', 'true');" << endl; output << "'SingleCompThread', 'true');" << endl;
else else
output << "'SingleCompThread', 'false');" << endl; output << "'SingleCompThread', 'false');" << endl;

View File

@ -46,8 +46,8 @@ DataTree::DataTree(SymbolTable &symbol_table_arg,
DataTree::~DataTree() DataTree::~DataTree()
{ {
for (node_list_t::iterator it = node_list.begin(); it != node_list.end(); it++) for (auto & it : node_list)
delete *it; delete it;
} }
expr_t expr_t
@ -75,9 +75,8 @@ DataTree::AddVariableInternal(int symb_id, int lag)
bool bool
DataTree::ParamUsedWithLeadLagInternal() const DataTree::ParamUsedWithLeadLagInternal() const
{ {
for (variable_node_map_t::const_iterator it = variable_node_map.begin(); for (const auto & it : variable_node_map)
it != variable_node_map.end(); it++) if (symbol_table.getType(it.first.first) == eParameter && it.first.second != 0)
if (symbol_table.getType(it->first.first) == eParameter && it->first.second != 0)
return true; return true;
return false; return false;
} }
@ -588,9 +587,8 @@ DataTree::AddSecondDerivExternalFunction(int top_level_symb_id, const vector<exp
bool bool
DataTree::isSymbolUsed(int symb_id) const DataTree::isSymbolUsed(int symb_id) const
{ {
for (variable_node_map_t::const_iterator it = variable_node_map.begin(); for (const auto & it : variable_node_map)
it != variable_node_map.end(); it++) if (it.first.first == symb_id)
if (it->first.first == symb_id)
return true; return true;
if (local_variables_table.find(symb_id) != local_variables_table.end()) if (local_variables_table.find(symb_id) != local_variables_table.end())
@ -637,9 +635,8 @@ DataTree::getDynJacobianCol(int deriv_id) const throw (UnknownDerivIDException)
bool bool
DataTree::isUnaryOpUsed(UnaryOpcode opcode) const DataTree::isUnaryOpUsed(UnaryOpcode opcode) const
{ {
for (unary_op_node_map_t::const_iterator it = unary_op_node_map.begin(); for (const auto & it : unary_op_node_map)
it != unary_op_node_map.end(); it++) if (it.first.first.second == opcode)
if (it->first.first.second == opcode)
return true; return true;
return false; return false;
@ -648,9 +645,8 @@ DataTree::isUnaryOpUsed(UnaryOpcode opcode) const
bool bool
DataTree::isBinaryOpUsed(BinaryOpcode opcode) const DataTree::isBinaryOpUsed(BinaryOpcode opcode) const
{ {
for (binary_op_node_map_t::const_iterator it = binary_op_node_map.begin(); for (const auto & it : binary_op_node_map)
it != binary_op_node_map.end(); it++) if (it.first.second == opcode)
if (it->first.second == opcode)
return true; return true;
return false; return false;
@ -659,9 +655,8 @@ DataTree::isBinaryOpUsed(BinaryOpcode opcode) const
bool bool
DataTree::isTrinaryOpUsed(TrinaryOpcode opcode) const DataTree::isTrinaryOpUsed(TrinaryOpcode opcode) const
{ {
for (trinary_op_node_map_t::const_iterator it = trinary_op_node_map.begin(); for (const auto & it : trinary_op_node_map)
it != trinary_op_node_map.end(); it++) if (it.first.second == opcode)
if (it->first.second == opcode)
return true; return true;
return false; return false;
@ -670,9 +665,8 @@ DataTree::isTrinaryOpUsed(TrinaryOpcode opcode) const
bool bool
DataTree::isExternalFunctionUsed(int symb_id) const DataTree::isExternalFunctionUsed(int symb_id) const
{ {
for (external_function_node_map_t::const_iterator it = external_function_node_map.begin(); for (const auto & it : external_function_node_map)
it != external_function_node_map.end(); it++) if (it.first.second == symb_id)
if (it->first.second == symb_id)
return true; return true;
return false; return false;
@ -681,9 +675,8 @@ DataTree::isExternalFunctionUsed(int symb_id) const
bool bool
DataTree::isFirstDerivExternalFunctionUsed(int symb_id) const DataTree::isFirstDerivExternalFunctionUsed(int symb_id) const
{ {
for (first_deriv_external_function_node_map_t::const_iterator it = first_deriv_external_function_node_map.begin(); for (const auto & it : first_deriv_external_function_node_map)
it != first_deriv_external_function_node_map.end(); it++) if (it.first.second == symb_id)
if (it->first.second == symb_id)
return true; return true;
return false; return false;
@ -692,9 +685,8 @@ DataTree::isFirstDerivExternalFunctionUsed(int symb_id) const
bool bool
DataTree::isSecondDerivExternalFunctionUsed(int symb_id) const DataTree::isSecondDerivExternalFunctionUsed(int symb_id) const
{ {
for (second_deriv_external_function_node_map_t::const_iterator it = second_deriv_external_function_node_map.begin(); for (const auto & it : second_deriv_external_function_node_map)
it != second_deriv_external_function_node_map.end(); it++) if (it.first.second == symb_id)
if (it->first.second == symb_id)
return true; return true;
return false; return false;
@ -704,10 +696,9 @@ int
DataTree::minLagForSymbol(int symb_id) const DataTree::minLagForSymbol(int symb_id) const
{ {
int r = 0; int r = 0;
for (variable_node_map_t::const_iterator it = variable_node_map.begin(); for (const auto & it : variable_node_map)
it != variable_node_map.end(); ++it) if (it.first.first == symb_id && it.first.second < r)
if (it->first.first == symb_id && it->first.second < r) r = it.first.second;
r = it->first.second;
return r; return r;
} }

File diff suppressed because it is too large Load Diff

View File

@ -141,9 +141,8 @@ ExprNode::collectEndogenous(set<pair<int, int> > &result) const
{ {
set<pair<int, int> > symb_ids; set<pair<int, int> > symb_ids;
collectDynamicVariables(eEndogenous, symb_ids); collectDynamicVariables(eEndogenous, symb_ids);
for (set<pair<int, int> >::const_iterator it = symb_ids.begin(); for (const auto & symb_id : symb_ids)
it != symb_ids.end(); it++) result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(symb_id.first), symb_id.second));
result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(it->first), it->second));
} }
void void
@ -151,9 +150,8 @@ ExprNode::collectExogenous(set<pair<int, int> > &result) const
{ {
set<pair<int, int> > symb_ids; set<pair<int, int> > symb_ids;
collectDynamicVariables(eExogenous, symb_ids); collectDynamicVariables(eExogenous, symb_ids);
for (set<pair<int, int> >::const_iterator it = symb_ids.begin(); for (const auto & symb_id : symb_ids)
it != symb_ids.end(); it++) result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(symb_id.first), symb_id.second));
result.insert(make_pair(datatree.symbol_table.getTypeSpecificID(it->first), it->second));
} }
void void
@ -2015,9 +2013,8 @@ int
UnaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const UnaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const
{ {
// For a temporary term, the cost is null // For a temporary term, the cost is null
for (map<NodeTreeReference, temporary_terms_t>::const_iterator it = temp_terms_map.begin(); for (const auto & it : temp_terms_map)
it != temp_terms_map.end(); it++) if (it.second.find(const_cast<UnaryOpNode *>(this)) != it.second.end())
if (it->second.find(const_cast<UnaryOpNode *>(this)) != it->second.end())
return 0; return 0;
return cost(arg->cost(temp_terms_map, is_matlab), is_matlab); return cost(arg->cost(temp_terms_map, is_matlab), is_matlab);
@ -3717,9 +3714,8 @@ int
BinaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const BinaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const
{ {
// For a temporary term, the cost is null // For a temporary term, the cost is null
for (map<NodeTreeReference, temporary_terms_t>::const_iterator it = temp_terms_map.begin(); for (const auto & it : temp_terms_map)
it != temp_terms_map.end(); it++) if (it.second.find(const_cast<BinaryOpNode *>(this)) != it.second.end())
if (it->second.find(const_cast<BinaryOpNode *>(this)) != it->second.end())
return 0; return 0;
int arg_cost = arg1->cost(temp_terms_map, is_matlab) + arg2->cost(temp_terms_map, is_matlab); int arg_cost = arg1->cost(temp_terms_map, is_matlab) + arg2->cost(temp_terms_map, is_matlab);
@ -5254,9 +5250,8 @@ int
TrinaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const TrinaryOpNode::cost(const map<NodeTreeReference, temporary_terms_t> &temp_terms_map, bool is_matlab) const
{ {
// For a temporary term, the cost is null // For a temporary term, the cost is null
for (map<NodeTreeReference, temporary_terms_t>::const_iterator it = temp_terms_map.begin(); for (const auto & it : temp_terms_map)
it != temp_terms_map.end(); it++) if (it.second.find(const_cast<TrinaryOpNode *>(this)) != it.second.end())
if (it->second.find(const_cast<TrinaryOpNode *>(this)) != it->second.end())
return 0; return 0;
int arg_cost = arg1->cost(temp_terms_map, is_matlab) int arg_cost = arg1->cost(temp_terms_map, is_matlab)
@ -5986,8 +5981,8 @@ AbstractExternalFunctionNode::prepareForDerivation()
if (preparedForDerivation) if (preparedForDerivation)
return; return;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->prepareForDerivation(); argument->prepareForDerivation();
non_null_derivatives = arguments.at(0)->non_null_derivatives; non_null_derivatives = arguments.at(0)->non_null_derivatives;
for (int i = 1; i < (int) arguments.size(); i++) for (int i = 1; i < (int) arguments.size(); i++)
@ -6005,8 +6000,8 @@ AbstractExternalFunctionNode::computeDerivative(int deriv_id)
{ {
assert(datatree.external_functions_table.getNargs(symb_id) > 0); assert(datatree.external_functions_table.getNargs(symb_id) > 0);
vector<expr_t> dargs; vector<expr_t> dargs;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
dargs.push_back((*it)->getDerivative(deriv_id)); dargs.push_back(argument->getDerivative(deriv_id));
return composeDerivatives(dargs); return composeDerivatives(dargs);
} }
@ -6015,9 +6010,8 @@ AbstractExternalFunctionNode::getChainRuleDerivative(int deriv_id, const map<int
{ {
assert(datatree.external_functions_table.getNargs(symb_id) > 0); assert(datatree.external_functions_table.getNargs(symb_id) > 0);
vector<expr_t> dargs; vector<expr_t> dargs;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) dargs.push_back(argument->getChainRuleDerivative(deriv_id, recursive_variables));
dargs.push_back((*it)->getChainRuleDerivative(deriv_id, recursive_variables));
return composeDerivatives(dargs); return composeDerivatives(dargs);
} }
@ -6027,9 +6021,8 @@ AbstractExternalFunctionNode::compileExternalFunctionArguments(ostream &CompileC
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
const deriv_node_temp_terms_t &tef_terms) const const deriv_node_temp_terms_t &tef_terms) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->compile(CompileCode, instruction_number, lhs_rhs, temporary_terms, map_idx,
(*it)->compile(CompileCode, instruction_number, lhs_rhs, temporary_terms, map_idx,
dynamic, steady_dynamic, tef_terms); dynamic, steady_dynamic, tef_terms);
return (arguments.size()); return (arguments.size());
} }
@ -6044,9 +6037,8 @@ AbstractExternalFunctionNode::collectVARLHSVariable(set<expr_t> &result) const
void void
AbstractExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const AbstractExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->collectDynamicVariables(type_arg, result);
(*it)->collectDynamicVariables(type_arg, result);
} }
void void
@ -6057,9 +6049,8 @@ AbstractExternalFunctionNode::collectTemporary_terms(const temporary_terms_t &te
temporary_terms_inuse.insert(idx); temporary_terms_inuse.insert(idx);
else else
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block);
(*it)->collectTemporary_terms(temporary_terms, temporary_terms_inuse, Curr_Block);
} }
} }
@ -6073,9 +6064,8 @@ int
AbstractExternalFunctionNode::maxEndoLead() const AbstractExternalFunctionNode::maxEndoLead() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->maxEndoLead());
val = max(val, (*it)->maxEndoLead());
return val; return val;
} }
@ -6083,9 +6073,8 @@ int
AbstractExternalFunctionNode::maxExoLead() const AbstractExternalFunctionNode::maxExoLead() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->maxExoLead());
val = max(val, (*it)->maxExoLead());
return val; return val;
} }
@ -6093,9 +6082,8 @@ int
AbstractExternalFunctionNode::maxEndoLag() const AbstractExternalFunctionNode::maxEndoLag() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->maxEndoLag());
val = max(val, (*it)->maxEndoLag());
return val; return val;
} }
@ -6103,9 +6091,8 @@ int
AbstractExternalFunctionNode::maxExoLag() const AbstractExternalFunctionNode::maxExoLag() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->maxExoLag());
val = max(val, (*it)->maxExoLag());
return val; return val;
} }
@ -6113,9 +6100,8 @@ int
AbstractExternalFunctionNode::maxLead() const AbstractExternalFunctionNode::maxLead() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->maxLead());
val = max(val, (*it)->maxLead());
return val; return val;
} }
@ -6123,9 +6109,8 @@ int
AbstractExternalFunctionNode::maxLag() const AbstractExternalFunctionNode::maxLag() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->maxLag());
val = max(val, (*it)->maxLag());
return val; return val;
} }
@ -6133,8 +6118,8 @@ expr_t
AbstractExternalFunctionNode::undiff() const AbstractExternalFunctionNode::undiff() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->undiff()); arguments_subst.push_back(argument->undiff());
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6142,27 +6127,24 @@ int
AbstractExternalFunctionNode::VarMinLag() const AbstractExternalFunctionNode::VarMinLag() const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = min(val, argument->VarMinLag());
val = min(val, (*it)->VarMinLag());
return val; return val;
} }
void void
AbstractExternalFunctionNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const AbstractExternalFunctionNode::VarMaxLag(DataTree &static_datatree, set<expr_t> &static_lhs, int &max_lag) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->VarMaxLag(static_datatree, static_lhs, max_lag);
(*it)->VarMaxLag(static_datatree, static_lhs, max_lag);
} }
int int
AbstractExternalFunctionNode::PacMaxLag(vector<int> &lhs) const AbstractExternalFunctionNode::PacMaxLag(vector<int> &lhs) const
{ {
int val = 0; int val = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) val = max(val, argument->PacMaxLag(lhs));
val = max(val, (*it)->PacMaxLag(lhs));
return val; return val;
} }
@ -6170,8 +6152,8 @@ expr_t
AbstractExternalFunctionNode::decreaseLeadsLags(int n) const AbstractExternalFunctionNode::decreaseLeadsLags(int n) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->decreaseLeadsLags(n)); arguments_subst.push_back(argument->decreaseLeadsLags(n));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6179,8 +6161,8 @@ expr_t
AbstractExternalFunctionNode::decreaseLeadsLagsPredeterminedVariables() const AbstractExternalFunctionNode::decreaseLeadsLagsPredeterminedVariables() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->decreaseLeadsLagsPredeterminedVariables()); arguments_subst.push_back(argument->decreaseLeadsLagsPredeterminedVariables());
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6188,8 +6170,8 @@ expr_t
AbstractExternalFunctionNode::substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const AbstractExternalFunctionNode::substituteEndoLeadGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteEndoLeadGreaterThanTwo(subst_table, neweqs, deterministic_model)); arguments_subst.push_back(argument->substituteEndoLeadGreaterThanTwo(subst_table, neweqs, deterministic_model));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6197,8 +6179,8 @@ expr_t
AbstractExternalFunctionNode::substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::substituteEndoLagGreaterThanTwo(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteEndoLagGreaterThanTwo(subst_table, neweqs)); arguments_subst.push_back(argument->substituteEndoLagGreaterThanTwo(subst_table, neweqs));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6206,8 +6188,8 @@ expr_t
AbstractExternalFunctionNode::substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const AbstractExternalFunctionNode::substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteExoLead(subst_table, neweqs, deterministic_model)); arguments_subst.push_back(argument->substituteExoLead(subst_table, neweqs, deterministic_model));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6215,8 +6197,8 @@ expr_t
AbstractExternalFunctionNode::substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteExoLag(subst_table, neweqs)); arguments_subst.push_back(argument->substituteExoLag(subst_table, neweqs));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6224,8 +6206,8 @@ expr_t
AbstractExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const AbstractExternalFunctionNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteExpectation(subst_table, neweqs, partial_information_model)); arguments_subst.push_back(argument->substituteExpectation(subst_table, neweqs, partial_information_model));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6233,23 +6215,23 @@ expr_t
AbstractExternalFunctionNode::substituteAdl() const AbstractExternalFunctionNode::substituteAdl() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteAdl()); arguments_subst.push_back(argument->substituteAdl());
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
void void
AbstractExternalFunctionNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const AbstractExternalFunctionNode::findDiffNodes(DataTree &static_datatree, diff_table_t &diff_table) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->findDiffNodes(static_datatree, diff_table); argument->findDiffNodes(static_datatree, diff_table);
} }
void void
AbstractExternalFunctionNode::findUnaryOpNodesForAuxVarCreation(DataTree &static_datatree, diff_table_t &nodes) const AbstractExternalFunctionNode::findUnaryOpNodesForAuxVarCreation(DataTree &static_datatree, diff_table_t &nodes) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->findUnaryOpNodesForAuxVarCreation(static_datatree, nodes); argument->findUnaryOpNodesForAuxVarCreation(static_datatree, nodes);
} }
expr_t expr_t
@ -6257,8 +6239,8 @@ AbstractExternalFunctionNode::substituteDiff(DataTree &static_datatree, diff_tab
vector<BinaryOpNode *> &neweqs) const vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteDiff(static_datatree, diff_table, subst_table, neweqs)); arguments_subst.push_back(argument->substituteDiff(static_datatree, diff_table, subst_table, neweqs));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6266,8 +6248,8 @@ expr_t
AbstractExternalFunctionNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nodes, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nodes, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteUnaryOpNodes(static_datatree, nodes, subst_table, neweqs)); arguments_subst.push_back(argument->substituteUnaryOpNodes(static_datatree, nodes, subst_table, neweqs));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6275,8 +6257,8 @@ int
AbstractExternalFunctionNode::countDiffs() const AbstractExternalFunctionNode::countDiffs() const
{ {
int ndiffs = 0; int ndiffs = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
ndiffs += (*it)->countDiffs(); ndiffs += argument->countDiffs();
return ndiffs; return ndiffs;
} }
@ -6284,8 +6266,8 @@ expr_t
AbstractExternalFunctionNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table) AbstractExternalFunctionNode::substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table)
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substitutePacExpectation(subst_table)); arguments_subst.push_back(argument->substitutePacExpectation(subst_table));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6293,8 +6275,8 @@ expr_t
AbstractExternalFunctionNode::differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const AbstractExternalFunctionNode::differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->differentiateForwardVars(subset, subst_table, neweqs)); arguments_subst.push_back(argument->differentiateForwardVars(subset, subst_table, neweqs));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6362,17 +6344,16 @@ bool
AbstractExternalFunctionNode::containsEndogenous(void) const AbstractExternalFunctionNode::containsEndogenous(void) const
{ {
bool result = false; bool result = false;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
result = result || (*it)->containsEndogenous(); result = result || argument->containsEndogenous();
return result; return result;
} }
bool bool
AbstractExternalFunctionNode::containsExogenous() const AbstractExternalFunctionNode::containsExogenous() const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) if (argument->containsExogenous())
if ((*it)->containsExogenous())
return true; return true;
return false; return false;
} }
@ -6381,8 +6362,8 @@ expr_t
AbstractExternalFunctionNode::replaceTrendVar() const AbstractExternalFunctionNode::replaceTrendVar() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->replaceTrendVar()); arguments_subst.push_back(argument->replaceTrendVar());
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6390,8 +6371,8 @@ expr_t
AbstractExternalFunctionNode::detrend(int symb_id, bool log_trend, expr_t trend) const AbstractExternalFunctionNode::detrend(int symb_id, bool log_trend, expr_t trend) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->detrend(symb_id, log_trend, trend)); arguments_subst.push_back(argument->detrend(symb_id, log_trend, trend));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6399,16 +6380,16 @@ expr_t
AbstractExternalFunctionNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const AbstractExternalFunctionNode::removeTrendLeadLag(map<int, expr_t> trend_symbols_map) const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->removeTrendLeadLag(trend_symbols_map)); arguments_subst.push_back(argument->removeTrendLeadLag(trend_symbols_map));
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
bool bool
AbstractExternalFunctionNode::isInStaticForm() const AbstractExternalFunctionNode::isInStaticForm() const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); ++it) for (auto argument : arguments)
if (!(*it)->isInStaticForm()) if (!argument->isInStaticForm())
return false; return false;
return true; return true;
} }
@ -6416,36 +6397,36 @@ AbstractExternalFunctionNode::isInStaticForm() const
void void
AbstractExternalFunctionNode::setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info) AbstractExternalFunctionNode::setVarExpectationIndex(map<string, pair<SymbolList, int> > &var_model_info)
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->setVarExpectationIndex(var_model_info); argument->setVarExpectationIndex(var_model_info);
} }
void void
AbstractExternalFunctionNode::walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &ec_params_and_vars, set<pair<int, pair<int, int> > > &ar_params_and_vars) const AbstractExternalFunctionNode::walkPacParameters(bool &pac_encountered, pair<int, int> &lhs, set<pair<int, pair<int, int> > > &ec_params_and_vars, set<pair<int, pair<int, int> > > &ar_params_and_vars) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->walkPacParameters(pac_encountered, lhs, ec_params_and_vars, ar_params_and_vars); argument->walkPacParameters(pac_encountered, lhs, ec_params_and_vars, ar_params_and_vars);
} }
void void
AbstractExternalFunctionNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &ec_params_and_vars_arg, set<pair<int, pair<int, int> > > &ar_params_and_vars_arg) AbstractExternalFunctionNode::addParamInfoToPac(pair<int, int> &lhs_arg, set<pair<int, pair<int, int> > > &ec_params_and_vars_arg, set<pair<int, pair<int, int> > > &ar_params_and_vars_arg)
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->addParamInfoToPac(lhs_arg, ec_params_and_vars_arg, ar_params_and_vars_arg); argument->addParamInfoToPac(lhs_arg, ec_params_and_vars_arg, ar_params_and_vars_arg);
} }
void void
AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg) AbstractExternalFunctionNode::fillPacExpectationVarInfo(string &model_name_arg, vector<int> &lhs_arg, int max_lag_arg, vector<bool> &nonstationary_arg, int growth_symb_id_arg, int equation_number_arg)
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
(*it)->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg); argument->fillPacExpectationVarInfo(model_name_arg, lhs_arg, max_lag_arg, nonstationary_arg, growth_symb_id_arg, equation_number_arg);
} }
bool bool
AbstractExternalFunctionNode::isVarModelReferenced(const string &model_info_name) const AbstractExternalFunctionNode::isVarModelReferenced(const string &model_info_name) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); ++it) for (auto argument : arguments)
if (!(*it)->isVarModelReferenced(model_info_name)) if (!argument->isVarModelReferenced(model_info_name))
return true; return true;
return false; return false;
} }
@ -6453,8 +6434,8 @@ AbstractExternalFunctionNode::isVarModelReferenced(const string &model_info_name
void void
AbstractExternalFunctionNode::getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const AbstractExternalFunctionNode::getEndosAndMaxLags(map<string, int> &model_endos_and_lags) const
{ {
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); ++it) for (auto argument : arguments)
(*it)->getEndosAndMaxLags(model_endos_and_lags); argument->getEndosAndMaxLags(model_endos_and_lags);
} }
pair<int, expr_t> pair<int, expr_t>
@ -6463,10 +6444,9 @@ AbstractExternalFunctionNode::normalizeEquation(int var_endo, vector<pair<int, p
vector<pair<bool, expr_t> > V_arguments; vector<pair<bool, expr_t> > V_arguments;
vector<expr_t> V_expr_t; vector<expr_t> V_expr_t;
bool present = false; bool present = false;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++)
{ {
V_arguments.push_back((*it)->normalizeEquation(var_endo, List_of_Op_RHS)); V_arguments.push_back(argument->normalizeEquation(var_endo, List_of_Op_RHS));
present = present || V_arguments[V_arguments.size()-1].first; present = present || V_arguments[V_arguments.size()-1].first;
V_expr_t.push_back(V_arguments[V_arguments.size()-1].second); V_expr_t.push_back(V_arguments[V_arguments.size()-1].second);
} }
@ -6516,11 +6496,10 @@ AbstractExternalFunctionNode::writePrhs(ostream &output, ExprNodeOutputType outp
{ {
output << "mxArray *prhs"<< ending << "[nrhs"<< ending << "];" << endl; output << "mxArray *prhs"<< ending << "[nrhs"<< ending << "];" << endl;
int i = 0; int i = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++)
{ {
output << "prhs" << ending << "[" << i++ << "] = mxCreateDoubleScalar("; // All external_function arguments are scalars output << "prhs" << ending << "[" << i++ << "] = mxCreateDoubleScalar("; // All external_function arguments are scalars
(*it)->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); argument->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << ");" << endl; output << ");" << endl;
} }
} }
@ -6535,8 +6514,8 @@ expr_t
AbstractExternalFunctionNode::substituteStaticAuxiliaryVariable() const AbstractExternalFunctionNode::substituteStaticAuxiliaryVariable() const
{ {
vector<expr_t> arguments_subst; vector<expr_t> arguments_subst;
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++) for (auto argument : arguments)
arguments_subst.push_back((*it)->substituteStaticAuxiliaryVariable()); arguments_subst.push_back(argument->substituteStaticAuxiliaryVariable());
return buildSimilarExternalFunctionNode(arguments_subst, datatree); return buildSimilarExternalFunctionNode(arguments_subst, datatree);
} }
@ -6622,9 +6601,8 @@ ExternalFunctionNode::compileExternalFunctionOutput(ostream &CompileCode, unsign
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->compileExternalFunctionOutput(CompileCode, instruction_number, lhs_rhs, temporary_terms,
(*it)->compileExternalFunctionOutput(CompileCode, instruction_number, lhs_rhs, temporary_terms,
map_idx, dynamic, steady_dynamic, tef_terms); map_idx, dynamic, steady_dynamic, tef_terms);
if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) if (!alreadyWrittenAsTefTerm(symb_id, tef_terms))
@ -6717,9 +6695,8 @@ ExternalFunctionNode::writeExternalFunctionOutput(ostream &output, ExprNodeOutpu
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->writeExternalFunctionOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
(*it)->writeExternalFunctionOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) if (!alreadyWrittenAsTefTerm(symb_id, tef_terms))
{ {
@ -6795,9 +6772,8 @@ ExternalFunctionNode::writeJsonExternalFunctionOutput(vector<string> &efout,
int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id); int first_deriv_symb_id = datatree.external_functions_table.getFirstDerivSymbID(symb_id);
assert(first_deriv_symb_id != eExtFunSetButNoNameProvided); assert(first_deriv_symb_id != eExtFunSetButNoNameProvided);
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
(*it)->writeJsonExternalFunctionOutput(efout, temporary_terms, tef_terms, isdynamic);
if (!alreadyWrittenAsTefTerm(symb_id, tef_terms)) if (!alreadyWrittenAsTefTerm(symb_id, tef_terms))
{ {
@ -6827,9 +6803,8 @@ expr_t
ExternalFunctionNode::toStatic(DataTree &static_datatree) const ExternalFunctionNode::toStatic(DataTree &static_datatree) const
{ {
vector<expr_t> static_arguments; vector<expr_t> static_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) static_arguments.push_back(argument->toStatic(static_datatree));
static_arguments.push_back((*it)->toStatic(static_datatree));
return static_datatree.AddExternalFunction(symb_id, static_arguments); return static_datatree.AddExternalFunction(symb_id, static_arguments);
} }
@ -6837,18 +6812,16 @@ void
ExternalFunctionNode::computeXrefs(EquationInfo &ei) const ExternalFunctionNode::computeXrefs(EquationInfo &ei) const
{ {
vector<expr_t> dynamic_arguments; vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->computeXrefs(ei);
(*it)->computeXrefs(ei);
} }
expr_t expr_t
ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const ExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
{ {
vector<expr_t> dynamic_arguments; vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) dynamic_arguments.push_back(argument->cloneDynamic(dynamic_datatree));
dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree));
return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments); return dynamic_datatree.AddExternalFunction(symb_id, dynamic_arguments);
} }
@ -7054,13 +7027,12 @@ FirstDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Exp
<< "prhs" << ending.str() << "[2] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl; << "prhs" << ending.str() << "[2] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl;
int i = 0; int i = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++)
{ {
output << "mxSetCell(prhs" << ending.str() << "[2], " output << "mxSetCell(prhs" << ending.str() << "[2], "
<< i++ << ", " << i++ << ", "
<< "mxCreateDoubleScalar("; // All external_function arguments are scalars << "mxCreateDoubleScalar("; // All external_function arguments are scalars
(*it)->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); argument->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << "));" << endl; output << "));" << endl;
} }
@ -7206,9 +7178,8 @@ expr_t
FirstDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const FirstDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
{ {
vector<expr_t> dynamic_arguments; vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) dynamic_arguments.push_back(argument->cloneDynamic(dynamic_datatree));
dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree));
return dynamic_datatree.AddFirstDerivExternalFunction(symb_id, dynamic_arguments, return dynamic_datatree.AddFirstDerivExternalFunction(symb_id, dynamic_arguments,
inputIndex); inputIndex);
} }
@ -7223,9 +7194,8 @@ expr_t
FirstDerivExternalFunctionNode::toStatic(DataTree &static_datatree) const FirstDerivExternalFunctionNode::toStatic(DataTree &static_datatree) const
{ {
vector<expr_t> static_arguments; vector<expr_t> static_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) static_arguments.push_back(argument->toStatic(static_datatree));
static_arguments.push_back((*it)->toStatic(static_datatree));
return static_datatree.AddFirstDerivExternalFunction(symb_id, static_arguments, return static_datatree.AddFirstDerivExternalFunction(symb_id, static_arguments,
inputIndex); inputIndex);
} }
@ -7234,9 +7204,8 @@ void
FirstDerivExternalFunctionNode::computeXrefs(EquationInfo &ei) const FirstDerivExternalFunctionNode::computeXrefs(EquationInfo &ei) const
{ {
vector<expr_t> dynamic_arguments; vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->computeXrefs(ei);
(*it)->computeXrefs(ei);
} }
function<bool (expr_t)> function<bool (expr_t)>
@ -7415,13 +7384,12 @@ SecondDerivExternalFunctionNode::writeExternalFunctionOutput(ostream &output, Ex
<< "prhs" << ending.str() << "[3] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl; << "prhs" << ending.str() << "[3] = mxCreateCellArray(2, dims" << ending.str() << ");"<< endl;
int i = 0; int i = 0;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++)
{ {
output << "mxSetCell(prhs" << ending.str() << "[3], " output << "mxSetCell(prhs" << ending.str() << "[3], "
<< i++ << ", " << i++ << ", "
<< "mxCreateDoubleScalar("; // All external_function arguments are scalars << "mxCreateDoubleScalar("; // All external_function arguments are scalars
(*it)->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms); argument->writeOutput(output, output_type, temporary_terms, temporary_terms_idxs, tef_terms);
output << "));" << endl; output << "));" << endl;
} }
@ -7525,9 +7493,8 @@ expr_t
SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const SecondDerivExternalFunctionNode::cloneDynamic(DataTree &dynamic_datatree) const
{ {
vector<expr_t> dynamic_arguments; vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) dynamic_arguments.push_back(argument->cloneDynamic(dynamic_datatree));
dynamic_arguments.push_back((*it)->cloneDynamic(dynamic_datatree));
return dynamic_datatree.AddSecondDerivExternalFunction(symb_id, dynamic_arguments, return dynamic_datatree.AddSecondDerivExternalFunction(symb_id, dynamic_arguments,
inputIndex1, inputIndex2); inputIndex1, inputIndex2);
} }
@ -7542,9 +7509,8 @@ expr_t
SecondDerivExternalFunctionNode::toStatic(DataTree &static_datatree) const SecondDerivExternalFunctionNode::toStatic(DataTree &static_datatree) const
{ {
vector<expr_t> static_arguments; vector<expr_t> static_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) static_arguments.push_back(argument->toStatic(static_datatree));
static_arguments.push_back((*it)->toStatic(static_datatree));
return static_datatree.AddSecondDerivExternalFunction(symb_id, static_arguments, return static_datatree.AddSecondDerivExternalFunction(symb_id, static_arguments,
inputIndex1, inputIndex2); inputIndex1, inputIndex2);
} }
@ -7553,9 +7519,8 @@ void
SecondDerivExternalFunctionNode::computeXrefs(EquationInfo &ei) const SecondDerivExternalFunctionNode::computeXrefs(EquationInfo &ei) const
{ {
vector<expr_t> dynamic_arguments; vector<expr_t> dynamic_arguments;
for (vector<expr_t>::const_iterator it = arguments.begin(); for (auto argument : arguments)
it != arguments.end(); it++) argument->computeXrefs(ei);
(*it)->computeXrefs(ei);
} }
void void

View File

@ -116,9 +116,8 @@ inline int
ExternalFunctionsTable::get_total_number_of_unique_model_block_external_functions() const ExternalFunctionsTable::get_total_number_of_unique_model_block_external_functions() const
{ {
int number_of_unique_model_block_external_functions = 0; int number_of_unique_model_block_external_functions = 0;
for (external_function_table_type::const_iterator it = externalFunctionTable.begin(); for (auto it : externalFunctionTable)
it != externalFunctionTable.end(); it++) if (it.second.nargs > 0)
if (it->second.nargs > 0)
number_of_unique_model_block_external_functions++; number_of_unique_model_block_external_functions++;
return number_of_unique_model_block_external_functions; return number_of_unique_model_block_external_functions;

View File

@ -48,9 +48,8 @@ ModFile::ModFile(WarningConsolidation &warnings_arg)
ModFile::~ModFile() ModFile::~ModFile()
{ {
for (vector<Statement *>::iterator it = statements.begin(); for (auto & statement : statements)
it != statements.end(); it++) delete statement;
delete (*it);
} }
void void
@ -112,9 +111,8 @@ ModFile::addStatementAtFront(Statement *st)
void void
ModFile::checkPass(bool nostrict, bool stochastic) ModFile::checkPass(bool nostrict, bool stochastic)
{ {
for (vector<Statement *>::iterator it = statements.begin(); for (auto & statement : statements)
it != statements.end(); it++) statement->checkPass(mod_file_struct, warnings);
(*it)->checkPass(mod_file_struct, warnings);
// Check the steady state block // Check the steady state block
steady_state_model.checkPass(mod_file_struct, warnings); steady_state_model.checkPass(mod_file_struct, warnings);
@ -332,8 +330,8 @@ ModFile::checkPass(bool nostrict, bool stochastic)
if (unusedExo.size() > 0) if (unusedExo.size() > 0)
{ {
ostringstream unused_exos; ostringstream unused_exos;
for (set<int>::iterator it = unusedExo.begin(); it != unusedExo.end(); it++) for (int it : unusedExo)
unused_exos << symbol_table.getName(*it) << " "; unused_exos << symbol_table.getName(it) << " ";
if (nostrict) if (nostrict)
warnings << "WARNING: " << unused_exos.str() warnings << "WARNING: " << unused_exos.str()
@ -358,10 +356,10 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
if (nostrict) if (nostrict)
{ {
set<int> unusedEndogs = dynamic_model.findUnusedEndogenous(); set<int> unusedEndogs = dynamic_model.findUnusedEndogenous();
for (set<int>::iterator it = unusedEndogs.begin(); it != unusedEndogs.end(); it++) for (int unusedEndog : unusedEndogs)
{ {
symbol_table.changeType(*it, eUnusedEndogenous); symbol_table.changeType(unusedEndog, eUnusedEndogenous);
warnings << "WARNING: '" << symbol_table.getName(*it) warnings << "WARNING: '" << symbol_table.getName(unusedEndog)
<< "' not used in model block, removed by nostrict command-line option" << endl; << "' not used in model block, removed by nostrict command-line option" << endl;
} }
} }
@ -462,9 +460,9 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
if (mod_file_struct.ramsey_model_present) if (mod_file_struct.ramsey_model_present)
{ {
StaticModel *planner_objective = NULL; StaticModel *planner_objective = NULL;
for (vector<Statement *>::iterator it = statements.begin(); it != statements.end(); it++) for (auto & statement : statements)
{ {
PlannerObjectiveStatement *pos = dynamic_cast<PlannerObjectiveStatement *>(*it); PlannerObjectiveStatement *pos = dynamic_cast<PlannerObjectiveStatement *>(statement);
if (pos != NULL) if (pos != NULL)
planner_objective = pos->getPlannerObjective(); planner_objective = pos->getPlannerObjective();
} }
@ -597,9 +595,9 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
} }
if (mod_file_struct.ramsey_policy_present) if (mod_file_struct.ramsey_policy_present)
for (vector<Statement *>::iterator it = statements.begin(); it != statements.end(); it++) for (auto & statement : statements)
{ {
RamseyPolicyStatement *rps = dynamic_cast<RamseyPolicyStatement *>(*it); RamseyPolicyStatement *rps = dynamic_cast<RamseyPolicyStatement *>(statement);
if (rps != NULL) if (rps != NULL)
rps->checkRamseyPolicyList(); rps->checkRamseyPolicyList();
} }
@ -727,9 +725,8 @@ ModFile::computingPass(bool no_tmp_terms, FileOutputType output, int params_deri
} }
} }
for (vector<Statement *>::iterator it = statements.begin(); for (auto & statement : statements)
it != statements.end(); it++) statement->computingPass();
(*it)->computingPass();
} }
void void
@ -848,14 +845,14 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
if (parallel_local_files.size() > 0) if (parallel_local_files.size() > 0)
{ {
mOutputFile << "options_.parallel_info.local_files = {" << endl; mOutputFile << "options_.parallel_info.local_files = {" << endl;
for (size_t i = 0; i < parallel_local_files.size(); i++) for (const auto & parallel_local_file : parallel_local_files)
{ {
size_t j = parallel_local_files[i].find_last_of("/\\"); size_t j = parallel_local_file.find_last_of("/\\");
if (j == string::npos) if (j == string::npos)
mOutputFile << "'', '" << parallel_local_files[i] << "';" << endl; mOutputFile << "'', '" << parallel_local_file << "';" << endl;
else else
mOutputFile << "'" << parallel_local_files[i].substr(0, j+1) << "', '" mOutputFile << "'" << parallel_local_file.substr(0, j+1) << "', '"
<< parallel_local_files[i].substr(j+1, string::npos) << "';" << endl; << parallel_local_file.substr(j+1, string::npos) << "';" << endl;
} }
mOutputFile << "};" << endl; mOutputFile << "};" << endl;
} }
@ -985,14 +982,13 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
// (*it)->writeOutput(mOutputFile, basename, minimal_workspace); // (*it)->writeOutput(mOutputFile, basename, minimal_workspace);
// dynamic_model.writeVarExpectationFunctions(mOutputFile); // dynamic_model.writeVarExpectationFunctions(mOutputFile);
for (vector<Statement *>::const_iterator it = statements.begin(); for (auto statement : statements)
it != statements.end(); it++)
{ {
(*it)->writeOutput(mOutputFile, basename, minimal_workspace); statement->writeOutput(mOutputFile, basename, minimal_workspace);
/* Special treatment for initval block: insert initial values for the /* Special treatment for initval block: insert initial values for the
auxiliary variables and initialize exo det */ auxiliary variables and initialize exo det */
InitValStatement *ivs = dynamic_cast<InitValStatement *>(*it); InitValStatement *ivs = dynamic_cast<InitValStatement *>(statement);
if (ivs != NULL) if (ivs != NULL)
{ {
static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel); static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel);
@ -1000,17 +996,17 @@ ModFile::writeOutputFiles(const string &basename, bool clear_all, bool clear_glo
} }
// Special treatment for endval block: insert initial values for the auxiliary variables // Special treatment for endval block: insert initial values for the auxiliary variables
EndValStatement *evs = dynamic_cast<EndValStatement *>(*it); EndValStatement *evs = dynamic_cast<EndValStatement *>(statement);
if (evs != NULL) if (evs != NULL)
static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel); static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel);
// Special treatment for load params and steady state statement: insert initial values for the auxiliary variables // Special treatment for load params and steady state statement: insert initial values for the auxiliary variables
LoadParamsAndSteadyStateStatement *lpass = dynamic_cast<LoadParamsAndSteadyStateStatement *>(*it); LoadParamsAndSteadyStateStatement *lpass = dynamic_cast<LoadParamsAndSteadyStateStatement *>(statement);
if (lpass && !no_static) if (lpass && !no_static)
static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel); static_model.writeAuxVarInitval(mOutputFile, oMatlabOutsideModel);
// Special treatement for Var Models // Special treatement for Var Models
VarModelStatement *vms = dynamic_cast<VarModelStatement *>(*it); VarModelStatement *vms = dynamic_cast<VarModelStatement *>(statement);
if (vms != NULL) if (vms != NULL)
vms->createVarModelMFunction(mOutputFile, dynamic_model.getVarExpectationFunctionsToWrite()); vms->createVarModelMFunction(mOutputFile, dynamic_model.getVarExpectationFunctionsToWrite());
} }
@ -1162,9 +1158,8 @@ ModFile::writeModelC(const string &basename) const
} }
// Print statements // Print statements
for (vector<Statement *>::const_iterator it = statements.begin(); for (auto statement : statements)
it != statements.end(); it++) statement->writeCOutput(mDriverCFile, basename);
(*it)->writeCOutput(mDriverCFile, basename);
mDriverCFile << "} DynareInfo;" << endl; mDriverCFile << "} DynareInfo;" << endl;
mDriverCFile.close(); mDriverCFile.close();
@ -1267,9 +1262,8 @@ ModFile::writeModelCC(const string &basename) const
} }
// Print statements // Print statements
for (vector<Statement *>::const_iterator it = statements.begin(); for (auto statement : statements)
it != statements.end(); it++) statement->writeCOutput(mDriverCFile, basename);
(*it)->writeCOutput(mDriverCFile, basename);
mDriverCFile << "};" << endl; mDriverCFile << "};" << endl;
mDriverCFile.close(); mDriverCFile.close();
@ -1404,9 +1398,8 @@ ModFile::writeExternalFilesJulia(const string &basename, FileOutputType output,
steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, true); steady_state_model.writeSteadyStateFile(basename, mod_file_struct.ramsey_model_present, true);
// Print statements (includes parameter values) // Print statements (includes parameter values)
for (vector<Statement *>::const_iterator it = statements.begin(); for (auto statement : statements)
it != statements.end(); it++) statement->writeJuliaOutput(jlOutputFile, basename);
(*it)->writeJuliaOutput(jlOutputFile, basename);
jlOutputFile << "model_.static = " << basename << "Static.static!" << endl jlOutputFile << "model_.static = " << basename << "Static.static!" << endl
<< "model_.dynamic = " << basename << "Dynamic.dynamic!" << endl << "model_.dynamic = " << basename << "Dynamic.dynamic!" << endl

View File

@ -51,8 +51,8 @@ ModelTree::computeNormalization(const jacob_map_t &contemporaneous_jacobian, boo
// Fill in the graph // Fill in the graph
set<pair<int, int> > endo; set<pair<int, int> > endo;
for (jacob_map_t::const_iterator it = contemporaneous_jacobian.begin(); it != contemporaneous_jacobian.end(); it++) for (const auto & it : contemporaneous_jacobian)
add_edge(it->first.first + n, it->first.second, g); add_edge(it.first.first + n, it.first.second, g);
// Compute maximum cardinality matching // Compute maximum cardinality matching
vector<int> mate_map(2*n); vector<int> mate_map(2*n);
@ -153,8 +153,8 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian
if (fabs(iter->second) > max_val[iter->first.first]) if (fabs(iter->second) > max_val[iter->first.first])
max_val[iter->first.first] = fabs(iter->second); max_val[iter->first.first] = fabs(iter->second);
for (jacob_map_t::iterator iter = normalized_contemporaneous_jacobian.begin(); iter != normalized_contemporaneous_jacobian.end(); iter++) for (auto & iter : normalized_contemporaneous_jacobian)
iter->second /= max_val[iter->first.first]; iter.second /= max_val[iter.first.first];
//We start with the highest value of the cutoff and try to normalize the model //We start with the highest value of the cutoff and try to normalize the model
double current_cutoff = 0.99999999; double current_cutoff = 0.99999999;
@ -164,9 +164,9 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian
{ {
jacob_map_t tmp_normalized_contemporaneous_jacobian; jacob_map_t tmp_normalized_contemporaneous_jacobian;
int suppress = 0; int suppress = 0;
for (jacob_map_t::iterator iter = normalized_contemporaneous_jacobian.begin(); iter != normalized_contemporaneous_jacobian.end(); iter++) for (auto & iter : normalized_contemporaneous_jacobian)
if (fabs(iter->second) > max(current_cutoff, cutoff)) if (fabs(iter.second) > max(current_cutoff, cutoff))
tmp_normalized_contemporaneous_jacobian[make_pair(iter->first.first, iter->first.second)] = iter->second; tmp_normalized_contemporaneous_jacobian[make_pair(iter.first.first, iter.first.second)] = iter.second;
else else
suppress++; suppress++;
@ -192,8 +192,8 @@ ModelTree::computeNonSingularNormalization(jacob_map_t &contemporaneous_jacobian
{ {
endo.clear(); endo.clear();
equations[i]->collectEndogenous(endo); equations[i]->collectEndogenous(endo);
for (set<pair<int, int> >::const_iterator it = endo.begin(); it != endo.end(); it++) for (const auto & it : endo)
tmp_normalized_contemporaneous_jacobian[make_pair(i, it->first)] = 1; tmp_normalized_contemporaneous_jacobian[make_pair(i, it.first)] = 1;
} }
check = computeNormalization(tmp_normalized_contemporaneous_jacobian, true); check = computeNormalization(tmp_normalized_contemporaneous_jacobian, true);
if (check) if (check)
@ -307,8 +307,8 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, jacob_m
} }
// Get rid of the elements of the Jacobian matrix below the cutoff // Get rid of the elements of the Jacobian matrix below the cutoff
for (set<pair<int, int> >::const_iterator it = jacobian_elements_to_delete.begin(); it != jacobian_elements_to_delete.end(); it++) for (const auto & it : jacobian_elements_to_delete)
first_derivatives.erase(*it); first_derivatives.erase(it);
if (jacobian_elements_to_delete.size() > 0) if (jacobian_elements_to_delete.size() > 0)
{ {
@ -340,13 +340,13 @@ ModelTree::computePrologueAndEpilogue(const jacob_map_t &static_jacobian_arg, ve
{ {
endo.clear(); endo.clear();
equations[i]->collectEndogenous(endo); equations[i]->collectEndogenous(endo);
for (set<pair<int, int> >::const_iterator it = endo.begin(); it != endo.end(); it++) for (const auto & it : endo)
IM[i * n + endo2eq[it->first]] = true; IM[i * n + endo2eq[it.first]] = true;
} }
} }
else else
for (jacob_map_t::const_iterator it = static_jacobian_arg.begin(); it != static_jacobian_arg.end(); it++) for (const auto & it : static_jacobian_arg)
IM[it->first.first * n + endo2eq[it->first.second]] = true; IM[it.first.first * n + endo2eq[it.first.second]] = true;
bool something_has_been_done = true; bool something_has_been_done = true;
prologue = 0; prologue = 0;
int k = 0; int k = 0;
@ -508,11 +508,11 @@ ModelTree::getVariableLeadLagByBlock(const dynamic_jacob_map_t &dynamic_jacobian
equation_blck[equation_reordered[i]] = i- (nb_endo - nb_blck_sim - prologue - epilogue); equation_blck[equation_reordered[i]] = i- (nb_endo - nb_blck_sim - prologue - epilogue);
} }
} }
for (dynamic_jacob_map_t::const_iterator it = dynamic_jacobian.begin(); it != dynamic_jacobian.end(); it++) for (const auto & it : dynamic_jacobian)
{ {
int lag = it->first.first; int lag = it.first.first;
int j_1 = it->first.second.first; int j_1 = it.first.second.first;
int i_1 = it->first.second.second; int i_1 = it.first.second.second;
if (variable_blck[i_1] == equation_blck[j_1]) if (variable_blck[i_1] == equation_blck[j_1])
{ {
if (lag > variable_lead_lag[i_1].second) if (lag > variable_lead_lag[i_1].second)
@ -555,8 +555,8 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob
{ {
endo.clear(); endo.clear();
equations[i]->collectEndogenous(endo); equations[i]->collectEndogenous(endo);
for (set<pair<int, int> >::const_iterator it = endo.begin(); it != endo.end(); it++) for (const auto & it : endo)
tmp_normalized_contemporaneous_jacobian[make_pair(i, it->first)] = 1; tmp_normalized_contemporaneous_jacobian[make_pair(i, it.first)] = 1;
} }
} }
@ -674,33 +674,33 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob
//First we have the recursive equations conditional on feedback variables //First we have the recursive equations conditional on feedback variables
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
for (vector<int>::iterator its = Reordered_Vertice.begin(); its != Reordered_Vertice.end(); its++) for (int & its : Reordered_Vertice)
{ {
bool something_done = false; bool something_done = false;
if (j == 2 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].second != 0) if (j == 2 && variable_lag_lead[tmp_variable_reordered[its +prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[its +prologue]].second != 0)
{ {
n_mixed[prologue+i]++; n_mixed[prologue+i]++;
something_done = true; something_done = true;
} }
else if (j == 3 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].second != 0) else if (j == 3 && variable_lag_lead[tmp_variable_reordered[its +prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[its +prologue]].second != 0)
{ {
n_forward[prologue+i]++; n_forward[prologue+i]++;
something_done = true; something_done = true;
} }
else if (j == 1 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].second == 0) else if (j == 1 && variable_lag_lead[tmp_variable_reordered[its +prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[its +prologue]].second == 0)
{ {
n_backward[prologue+i]++; n_backward[prologue+i]++;
something_done = true; something_done = true;
} }
else if (j == 0 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[*its +prologue]].second == 0) else if (j == 0 && variable_lag_lead[tmp_variable_reordered[its +prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[its +prologue]].second == 0)
{ {
n_static[prologue+i]++; n_static[prologue+i]++;
something_done = true; something_done = true;
} }
if (something_done) if (something_done)
{ {
equation_reordered[order] = tmp_equation_reordered[*its+prologue]; equation_reordered[order] = tmp_equation_reordered[its+prologue];
variable_reordered[order] = tmp_variable_reordered[*its+prologue]; variable_reordered[order] = tmp_variable_reordered[its+prologue];
order++; order++;
} }
} }
@ -709,33 +709,33 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob
//Second we have the equations related to the feedback variables //Second we have the equations related to the feedback variables
for (int j = 0; j < 4; j++) for (int j = 0; j < 4; j++)
{ {
for (set<int>::iterator its = feed_back_vertices.begin(); its != feed_back_vertices.end(); its++) for (int feed_back_vertice : feed_back_vertices)
{ {
bool something_done = false; bool something_done = false;
if (j == 2 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].second != 0) if (j == 2 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].second != 0)
{ {
n_mixed[prologue+i]++; n_mixed[prologue+i]++;
something_done = true; something_done = true;
} }
else if (j == 3 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].second != 0) else if (j == 3 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].second != 0)
{ {
n_forward[prologue+i]++; n_forward[prologue+i]++;
something_done = true; something_done = true;
} }
else if (j == 1 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].second == 0) else if (j == 1 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].first != 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].second == 0)
{ {
n_backward[prologue+i]++; n_backward[prologue+i]++;
something_done = true; something_done = true;
} }
else if (j == 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]].second == 0) else if (j == 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].first == 0 && variable_lag_lead[tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue]].second == 0)
{ {
n_static[prologue+i]++; n_static[prologue+i]++;
something_done = true; something_done = true;
} }
if (something_done) if (something_done)
{ {
equation_reordered[order] = tmp_equation_reordered[v_index[vertex(*its, G)]+prologue]; equation_reordered[order] = tmp_equation_reordered[v_index[vertex(feed_back_vertice, G)]+prologue];
variable_reordered[order] = tmp_variable_reordered[v_index[vertex(*its, G)]+prologue]; variable_reordered[order] = tmp_variable_reordered[v_index[vertex(feed_back_vertice, G)]+prologue];
order++; order++;
} }
} }
@ -832,10 +832,10 @@ ModelTree::reduceBlocksAndTypeDetermination(const dynamic_jacob_map_t &dynamic_j
{ {
endo.clear(); endo.clear();
equations[equation_reordered[count_equ]]->collectEndogenous(endo); equations[equation_reordered[count_equ]]->collectEndogenous(endo);
for (set<pair<int, int> >::const_iterator it = endo.begin(); it != endo.end(); it++) for (const auto & it : endo)
{ {
int curr_variable = it->first; int curr_variable = it.first;
int curr_lag = it->second; int curr_lag = it.second;
vector<int>::const_iterator it1 = find(variable_reordered.begin()+first_count_equ, variable_reordered.begin()+(first_count_equ+Blck_Size), curr_variable); vector<int>::const_iterator it1 = find(variable_reordered.begin()+first_count_equ, variable_reordered.begin()+(first_count_equ+Blck_Size), curr_variable);
if (it1 != variable_reordered.begin()+(first_count_equ+Blck_Size)) if (it1 != variable_reordered.begin()+(first_count_equ+Blck_Size))
if (dynamic_jacobian.find(make_pair(curr_lag, make_pair(equation_reordered[count_equ], curr_variable))) != dynamic_jacobian.end()) if (dynamic_jacobian.find(make_pair(curr_lag, make_pair(equation_reordered[count_equ], curr_variable))) != dynamic_jacobian.end())
@ -1010,8 +1010,8 @@ ModelTree::ModelTree(SymbolTable &symbol_table_arg,
mfs(0) mfs(0)
{ {
for (int i = 0; i < 3; i++) for (int & NNZDerivative : NNZDerivatives)
NNZDerivatives[i] = 0; NNZDerivative = 0;
} }
int int
@ -1035,15 +1035,14 @@ ModelTree::writeDerivative(ostream &output, int eq, int symb_id, int lag,
void void
ModelTree::computeJacobian(const set<int> &vars) ModelTree::computeJacobian(const set<int> &vars)
{ {
for (set<int>::const_iterator it = vars.begin(); for (int var : vars)
it != vars.end(); it++)
{ {
for (int eq = 0; eq < (int) equations.size(); eq++) for (int eq = 0; eq < (int) equations.size(); eq++)
{ {
expr_t d1 = equations[eq]->getDerivative(*it); expr_t d1 = equations[eq]->getDerivative(var);
if (d1 == Zero) if (d1 == Zero)
continue; continue;
first_derivatives[make_pair(eq, *it)] = d1; first_derivatives[make_pair(eq, var)] = d1;
++NNZDerivatives[0]; ++NNZDerivatives[0];
} }
} }
@ -1060,10 +1059,8 @@ ModelTree::computeHessian(const set<int> &vars)
expr_t d1 = it->second; expr_t d1 = it->second;
// Store only second derivatives with var2 <= var1 // Store only second derivatives with var2 <= var1
for (set<int>::const_iterator it2 = vars.begin(); for (int var2 : vars)
it2 != vars.end(); it2++)
{ {
int var2 = *it2;
if (var2 > var1) if (var2 > var1)
continue; continue;
@ -1094,10 +1091,8 @@ ModelTree::computeThirdDerivatives(const set<int> &vars)
expr_t d2 = it->second; expr_t d2 = it->second;
// Store only third derivatives such that var3 <= var2 <= var1 // Store only third derivatives such that var3 <= var2 <= var1
for (set<int>::const_iterator it2 = vars.begin(); for (int var3 : vars)
it2 != vars.end(); it2++)
{ {
int var3 = *it2;
if (var3 > var2) if (var3 > var2)
continue; continue;
@ -1129,14 +1124,13 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
// Collect all model local variables appearing in equations. See #101 // Collect all model local variables appearing in equations. See #101
// All used model local variables are automatically set as temporary variables // All used model local variables are automatically set as temporary variables
set<int> used_local_vars; set<int> used_local_vars;
for (size_t i = 0; i < equations.size(); i++) for (auto & equation : equations)
equations[i]->collectVariables(eModelLocalVariable, used_local_vars); equation->collectVariables(eModelLocalVariable, used_local_vars);
for (set<int>::const_iterator it = used_local_vars.begin(); for (int used_local_var : used_local_vars)
it != used_local_vars.end(); it++)
{ {
VariableNode *v = AddVariable(*it); VariableNode *v = AddVariable(used_local_var);
temporary_terms_mlv[v] = local_variables_table.find(*it)->second; temporary_terms_mlv[v] = local_variables_table.find(used_local_var)->second;
reference_count[v] = make_pair(MIN_COST(is_matlab)+1, eResiduals); reference_count[v] = make_pair(MIN_COST(is_matlab)+1, eResiduals);
} }
@ -1146,27 +1140,23 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
temp_terms_map[eSecondDeriv] = temporary_terms_g2; temp_terms_map[eSecondDeriv] = temporary_terms_g2;
temp_terms_map[eThirdDeriv] = temporary_terms_g3; temp_terms_map[eThirdDeriv] = temporary_terms_g3;
for (vector<BinaryOpNode *>::iterator it = equations.begin(); for (auto & equation : equations)
it != equations.end(); it++) equation->computeTemporaryTerms(reference_count,
(*it)->computeTemporaryTerms(reference_count,
temp_terms_map, temp_terms_map,
is_matlab, eResiduals); is_matlab, eResiduals);
for (first_derivatives_t::iterator it = first_derivatives.begin(); for (auto & first_derivative : first_derivatives)
it != first_derivatives.end(); it++) first_derivative.second->computeTemporaryTerms(reference_count,
it->second->computeTemporaryTerms(reference_count,
temp_terms_map, temp_terms_map,
is_matlab, eFirstDeriv); is_matlab, eFirstDeriv);
for (second_derivatives_t::iterator it = second_derivatives.begin(); for (auto & second_derivative : second_derivatives)
it != second_derivatives.end(); it++) second_derivative.second->computeTemporaryTerms(reference_count,
it->second->computeTemporaryTerms(reference_count,
temp_terms_map, temp_terms_map,
is_matlab, eSecondDeriv); is_matlab, eSecondDeriv);
for (third_derivatives_t::iterator it = third_derivatives.begin(); for (auto & third_derivative : third_derivatives)
it != third_derivatives.end(); it++) third_derivative.second->computeTemporaryTerms(reference_count,
it->second->computeTemporaryTerms(reference_count,
temp_terms_map, temp_terms_map,
is_matlab, eThirdDeriv); is_matlab, eThirdDeriv);
@ -1184,21 +1174,17 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
it != temporary_terms_mlv.end(); it++) it != temporary_terms_mlv.end(); it++)
temporary_terms_idxs[it->first] = idx++; temporary_terms_idxs[it->first] = idx++;
for (temporary_terms_t::const_iterator it = temporary_terms_res.begin(); for (auto temporary_terms_re : temporary_terms_res)
it != temporary_terms_res.end(); it++) temporary_terms_idxs[temporary_terms_re] = idx++;
temporary_terms_idxs[*it] = idx++;
for (temporary_terms_t::const_iterator it = temporary_terms_g1.begin(); for (auto it : temporary_terms_g1)
it != temporary_terms_g1.end(); it++) temporary_terms_idxs[it] = idx++;
temporary_terms_idxs[*it] = idx++;
for (temporary_terms_t::const_iterator it = temporary_terms_g2.begin(); for (auto it : temporary_terms_g2)
it != temporary_terms_g2.end(); it++) temporary_terms_idxs[it] = idx++;
temporary_terms_idxs[*it] = idx++;
for (temporary_terms_t::const_iterator it = temporary_terms_g3.begin(); for (auto it : temporary_terms_g3)
it != temporary_terms_g3.end(); it++) temporary_terms_idxs[it] = idx++;
temporary_terms_idxs[*it] = idx++;
} }
void void
@ -1207,24 +1193,23 @@ ModelTree::writeModelLocalVariableTemporaryTerms(const temporary_terms_t &tto, c
deriv_node_temp_terms_t &tef_terms) const deriv_node_temp_terms_t &tef_terms) const
{ {
temporary_terms_t tt2; temporary_terms_t tt2;
for (map<expr_t, expr_t>::const_iterator it = tt.begin(); for (auto it : tt)
it != tt.end(); it++)
{ {
if (IS_C(output_type)) if (IS_C(output_type))
output << "double "; output << "double ";
else if (IS_JULIA(output_type)) else if (IS_JULIA(output_type))
output << " @inbounds const "; output << " @inbounds const ";
it->first->writeOutput(output, output_type, tto, temporary_terms_idxs, tef_terms); it.first->writeOutput(output, output_type, tto, temporary_terms_idxs, tef_terms);
output << " = "; output << " = ";
it->second->writeOutput(output, output_type, tt2, temporary_terms_idxs, tef_terms); it.second->writeOutput(output, output_type, tt2, temporary_terms_idxs, tef_terms);
if (IS_C(output_type) || IS_MATLAB(output_type)) if (IS_C(output_type) || IS_MATLAB(output_type))
output << ";"; output << ";";
output << endl; output << endl;
// Insert current node into tt2 // Insert current node into tt2
tt2.insert(it->first); tt2.insert(it.first);
} }
} }
@ -1269,16 +1254,15 @@ ModelTree::writeJsonTemporaryTerms(const temporary_terms_t &tt, const temporary_
temporary_terms_t tt2 = ttm1; temporary_terms_t tt2 = ttm1;
output << "\"external_functions_temporary_terms_" << concat << "\": ["; output << "\"external_functions_temporary_terms_" << concat << "\": [";
for (temporary_terms_t::const_iterator it = tt.begin(); for (auto it : tt)
it != tt.end(); it++) if (ttm1.find(it) == ttm1.end())
if (ttm1.find(*it) == ttm1.end())
{ {
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(it) != NULL)
{ {
if (wrote_term) if (wrote_term)
output << ", "; output << ", ";
vector<string> efout; vector<string> efout;
(*it)->writeJsonExternalFunctionOutput(efout, tt2, tef_terms); it->writeJsonExternalFunctionOutput(efout, tt2, tef_terms);
for (vector<string>::const_iterator it1 = efout.begin(); it1 != efout.end(); it1++) for (vector<string>::const_iterator it1 = efout.begin(); it1 != efout.end(); it1++)
{ {
if (it1 != efout.begin()) if (it1 != efout.begin())
@ -1287,7 +1271,7 @@ ModelTree::writeJsonTemporaryTerms(const temporary_terms_t &tt, const temporary_
} }
wrote_term = true; wrote_term = true;
} }
tt2.insert(*it); tt2.insert(it);
} }
tt2 = ttm1; tt2 = ttm1;
@ -1424,11 +1408,11 @@ bool
ModelTree::testNestedParenthesis(const string &str) const ModelTree::testNestedParenthesis(const string &str) const
{ {
int open = 0; int open = 0;
for (size_t i = 0; i < str.length(); i++) for (char i : str)
{ {
if (str.at(i) == '(') if (i == '(')
open++; open++;
else if (str.at(i) == ')') else if (i == ')')
open--; open--;
if (open > 32) if (open > 32)
return true; return true;
@ -1443,29 +1427,28 @@ ModelTree::compileTemporaryTerms(ostream &code_file, unsigned int &instruction_n
temporary_terms_t tt2; temporary_terms_t tt2;
// To store the functions that have already been written in the form TEF* = ext_fun(); // To store the functions that have already been written in the form TEF* = ext_fun();
deriv_node_temp_terms_t tef_terms; deriv_node_temp_terms_t tef_terms;
for (temporary_terms_t::const_iterator it = tt.begin(); for (auto it : tt)
it != tt.end(); it++)
{ {
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(it) != NULL)
{ {
(*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); it->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms);
} }
FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find((*it)->idx)->second)); FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find(it->idx)->second));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
(*it)->compile(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms); it->compile(code_file, instruction_number, false, tt2, map_idx, dynamic, steady_dynamic, tef_terms);
if (dynamic) if (dynamic)
{ {
FSTPT_ fstpt((int)(map_idx.find((*it)->idx)->second)); FSTPT_ fstpt((int)(map_idx.find(it->idx)->second));
fstpt.write(code_file, instruction_number); fstpt.write(code_file, instruction_number);
} }
else else
{ {
FSTPST_ fstpst((int)(map_idx.find((*it)->idx)->second)); FSTPST_ fstpst((int)(map_idx.find(it->idx)->second));
fstpst.write(code_file, instruction_number); fstpst.write(code_file, instruction_number);
} }
// Insert current node into tt2 // Insert current node into tt2
tt2.insert(*it); tt2.insert(it);
} }
} }
@ -1480,21 +1463,20 @@ ModelTree::writeJsonModelLocalVariables(ostream &output, deriv_node_temp_terms_t
// Use an empty set for the temporary terms // Use an empty set for the temporary terms
const temporary_terms_t tt; const temporary_terms_t tt;
for (size_t i = 0; i < equations.size(); i++) for (auto equation : equations)
equations[i]->collectVariables(eModelLocalVariable, used_local_vars); equation->collectVariables(eModelLocalVariable, used_local_vars);
output << "\"model_local_variables\": ["; output << "\"model_local_variables\": [";
bool printed = false; bool printed = false;
for (vector<int>::const_iterator it = local_variables_vector.begin(); for (int it : local_variables_vector)
it != local_variables_vector.end(); it++) if (used_local_vars.find(it) != used_local_vars.end())
if (used_local_vars.find(*it) != used_local_vars.end())
{ {
if (printed) if (printed)
output << ", "; output << ", ";
else else
printed = true; printed = true;
int id = *it; int id = it;
vector<string> efout; vector<string> efout;
expr_t value = local_variables_table.find(id)->second; expr_t value = local_variables_table.find(id)->second;
value->writeJsonExternalFunctionOutput(efout, tt, tef_terms); value->writeJsonExternalFunctionOutput(efout, tt, tef_terms);
@ -1642,12 +1624,12 @@ ModelTree::Write_Inf_To_Bin_File(const string &basename,
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
u_count_int = 0; u_count_int = 0;
for (first_derivatives_t::const_iterator it = first_derivatives.begin(); it != first_derivatives.end(); it++) for (const auto & first_derivative : first_derivatives)
{ {
int deriv_id = it->first.second; int deriv_id = first_derivative.first.second;
if (getTypeByDerivID(deriv_id) == eEndogenous) if (getTypeByDerivID(deriv_id) == eEndogenous)
{ {
int eq = it->first.first; int eq = first_derivative.first.first;
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
int var = symbol_table.getTypeSpecificID(symb); int var = symbol_table.getTypeSpecificID(symb);
int lag = getLagByDerivID(deriv_id); int lag = getLagByDerivID(deriv_id);
@ -1699,10 +1681,8 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
<< "\\footnotesize" << endl; << "\\footnotesize" << endl;
// Write model local variables // Write model local variables
for (vector<int>::const_iterator it = local_variables_vector.begin(); for (int id : local_variables_vector)
it != local_variables_vector.end(); it++)
{ {
int id = *it;
expr_t value = local_variables_table.find(id)->second; expr_t value = local_variables_table.find(id)->second;
content_output << "\\begin{dmath*}" << endl content_output << "\\begin{dmath*}" << endl
@ -1718,19 +1698,18 @@ ModelTree::writeLatexModelFile(const string &basename, ExprNodeOutputType output
bool wrote_eq_tag = false; bool wrote_eq_tag = false;
if (write_equation_tags) if (write_equation_tags)
{ {
for (vector<pair<int, pair<string, string> > >::const_iterator iteqt = equation_tags.begin(); for (const auto & equation_tag : equation_tags)
iteqt != equation_tags.end(); iteqt++) if (equation_tag.first == eq)
if (iteqt->first == eq)
{ {
if (!wrote_eq_tag) if (!wrote_eq_tag)
content_output << "\\noindent["; content_output << "\\noindent[";
else else
content_output << ", "; content_output << ", ";
content_output << iteqt->second.first; content_output << equation_tag.second.first;
if (!(iteqt->second.second.empty())) if (!(equation_tag.second.second.empty()))
content_output << "= `" << iteqt->second.second << "'"; content_output << "= `" << equation_tag.second.second << "'";
wrote_eq_tag = true; wrote_eq_tag = true;
} }
@ -1765,8 +1744,8 @@ void
ModelTree::addEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags) ModelTree::addEquation(expr_t eq, int lineno, const vector<pair<string, string> > &eq_tags)
{ {
int n = equations.size(); int n = equations.size();
for (size_t i = 0; i < eq_tags.size(); i++) for (const auto & eq_tag : eq_tags)
equation_tags.push_back(make_pair(n, eq_tags[i])); equation_tags.push_back(make_pair(n, eq_tag));
addEquation(eq, lineno); addEquation(eq, lineno);
} }
@ -1853,11 +1832,8 @@ ModelTree::computeParamsDerivatives(int paramsDerivsOrder)
set<int> deriv_id_set; set<int> deriv_id_set;
addAllParamDerivId(deriv_id_set); addAllParamDerivId(deriv_id_set);
for (set<int>::const_iterator it = deriv_id_set.begin(); for (int param : deriv_id_set)
it != deriv_id_set.end(); it++)
{ {
const int param = *it;
for (int eq = 0; eq < (int) equations.size(); eq++) for (int eq = 0; eq < (int) equations.size(); eq++)
{ {
expr_t d1 = equations[eq]->getDerivative(param); expr_t d1 = equations[eq]->getDerivative(param);
@ -1938,15 +1914,13 @@ ModelTree::computeParamsDerivativesTemporaryTerms()
temp_terms_map[eJacobianParamsSecondDeriv] = params_derivs_temporary_terms_g12; temp_terms_map[eJacobianParamsSecondDeriv] = params_derivs_temporary_terms_g12;
temp_terms_map[eHessianParamsDeriv] = params_derivs_temporary_terms_g2; temp_terms_map[eHessianParamsDeriv] = params_derivs_temporary_terms_g2;
for (first_derivatives_t::iterator it = residuals_params_derivatives.begin(); for (auto & residuals_params_derivative : residuals_params_derivatives)
it != residuals_params_derivatives.end(); it++) residuals_params_derivative.second->computeTemporaryTerms(reference_count,
it->second->computeTemporaryTerms(reference_count,
temp_terms_map, temp_terms_map,
true, eResidualsParamsDeriv); true, eResidualsParamsDeriv);
for (second_derivatives_t::iterator it = jacobian_params_derivatives.begin(); for (auto & jacobian_params_derivative : jacobian_params_derivatives)
it != jacobian_params_derivatives.end(); it++) jacobian_params_derivative.second->computeTemporaryTerms(reference_count,
it->second->computeTemporaryTerms(reference_count,
temp_terms_map, temp_terms_map,
true, eJacobianParamsDeriv); true, eJacobianParamsDeriv);
@ -2054,10 +2028,9 @@ ModelTree::writeJsonModelEquations(ostream &output, bool residuals) const
output << "\"" output << "\""
<< ", \"line\": " << equations_lineno[eq]; << ", \"line\": " << equations_lineno[eq];
for (vector<pair<int, pair<string, string> > >::const_iterator it = equation_tags.begin(); for (const auto & equation_tag : equation_tags)
it != equation_tags.end(); it++) if (equation_tag.first == eq)
if (it->first == eq) eqtags.push_back(equation_tag.second);
eqtags.push_back(it->second);
if (!eqtags.empty()) if (!eqtags.empty())
{ {

View File

@ -106,12 +106,11 @@ InitOrEndValStatement::InitOrEndValStatement(const init_values_t &init_values_ar
void void
InitOrEndValStatement::fillEvalContext(eval_context_t &eval_context) const InitOrEndValStatement::fillEvalContext(eval_context_t &eval_context) const
{ {
for (init_values_t::const_iterator it = init_values.begin(); for (const auto & init_value : init_values)
it != init_values.end(); it++)
{ {
try try
{ {
eval_context[it->first] = (it->second)->eval(eval_context); eval_context[init_value.first] = (init_value.second)->eval(eval_context);
} }
catch (ExprNode::EvalException &e) catch (ExprNode::EvalException &e)
{ {
@ -138,10 +137,9 @@ InitOrEndValStatement::getUninitializedVariables(SymbolType type)
} }
set<int>::iterator sit; set<int>::iterator sit;
for (init_values_t::const_iterator it = init_values.begin(); for (const auto & init_value : init_values)
it != init_values.end(); it++)
{ {
sit = unused.find(it->first); sit = unused.find(init_value.first);
if (sit != unused.end()) if (sit != unused.end())
unused.erase(sit); unused.erase(sit);
} }
@ -151,11 +149,10 @@ InitOrEndValStatement::getUninitializedVariables(SymbolType type)
void void
InitOrEndValStatement::writeInitValues(ostream &output) const InitOrEndValStatement::writeInitValues(ostream &output) const
{ {
for (init_values_t::const_iterator it = init_values.begin(); for (const auto & init_value : init_values)
it != init_values.end(); it++)
{ {
const int symb_id = it->first; const int symb_id = init_value.first;
const expr_t expression = it->second; const expr_t expression = init_value.second;
SymbolType type = symbol_table.getType(symb_id); SymbolType type = symbol_table.getType(symb_id);
int tsid = symbol_table.getTypeSpecificID(symb_id) + 1; int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
@ -203,16 +200,16 @@ InitValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
if (endogs.size() > 0) if (endogs.size() > 0)
{ {
cerr << "ERROR: You have not set the following endogenous variables in initval:"; cerr << "ERROR: You have not set the following endogenous variables in initval:";
for (set<int>::const_iterator it = endogs.begin(); it != endogs.end(); it++) for (int endog : endogs)
cerr << " " << symbol_table.getName(*it); cerr << " " << symbol_table.getName(endog);
cerr << endl; cerr << endl;
} }
if (exogs.size() > 0) if (exogs.size() > 0)
{ {
cerr << "ERROR: You have not set the following exogenous variables in initval:"; cerr << "ERROR: You have not set the following exogenous variables in initval:";
for (set<int>::const_iterator it = exogs.begin(); it != exogs.end(); it++) for (int exog : exogs)
cerr << " " << symbol_table.getName(*it); cerr << " " << symbol_table.getName(exog);
cerr << endl; cerr << endl;
} }
@ -267,16 +264,16 @@ EndValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati
if (endogs.size() > 0) if (endogs.size() > 0)
{ {
cerr << "ERROR: You have not set the following endogenous variables in endval:"; cerr << "ERROR: You have not set the following endogenous variables in endval:";
for (set<int>::const_iterator it = endogs.begin(); it != endogs.end(); it++) for (int endog : endogs)
cerr << " " << symbol_table.getName(*it); cerr << " " << symbol_table.getName(endog);
cerr << endl; cerr << endl;
} }
if (exogs.size() > 0) if (exogs.size() > 0)
{ {
cerr << "ERROR: You have not set the following exogenous variables in endval:"; cerr << "ERROR: You have not set the following exogenous variables in endval:";
for (set<int>::const_iterator it = exogs.begin(); it != exogs.end(); it++) for (int exog : exogs)
cerr << " " << symbol_table.getName(*it); cerr << " " << symbol_table.getName(exog);
cerr << endl; cerr << endl;
} }
@ -325,14 +322,13 @@ HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
set<int> unused_exo = symbol_table.getExogenous(); set<int> unused_exo = symbol_table.getExogenous();
set<int>::iterator sit; set<int>::iterator sit;
for (hist_values_t::const_iterator it = hist_values.begin(); for (const auto & hist_value : hist_values)
it != hist_values.end(); it++)
{ {
sit = unused_endo.find(it->first.first); sit = unused_endo.find(hist_value.first.first);
if (sit != unused_endo.end()) if (sit != unused_endo.end())
unused_endo.erase(sit); unused_endo.erase(sit);
sit = unused_exo.find(it->first.first); sit = unused_exo.find(hist_value.first.first);
if (sit != unused_exo.end()) if (sit != unused_exo.end())
unused_exo.erase(sit); unused_exo.erase(sit);
} }
@ -340,16 +336,16 @@ HistValStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
if (unused_endo.size() > 0) if (unused_endo.size() > 0)
{ {
cerr << "ERROR: You have not set the following endogenous variables in histval:"; cerr << "ERROR: You have not set the following endogenous variables in histval:";
for (set<int>::const_iterator it = unused_endo.begin(); it != unused_endo.end(); it++) for (int it : unused_endo)
cerr << " " << symbol_table.getName(*it); cerr << " " << symbol_table.getName(it);
cerr << endl; cerr << endl;
} }
if (unused_exo.size() > 0) if (unused_exo.size() > 0)
{ {
cerr << "ERROR: You have not set the following exogenous variables in endval:"; cerr << "ERROR: You have not set the following exogenous variables in endval:";
for (set<int>::const_iterator it = unused_exo.begin(); it != unused_exo.end(); it++) for (int it : unused_exo)
cerr << " " << symbol_table.getName(*it); cerr << " " << symbol_table.getName(it);
cerr << endl; cerr << endl;
} }
@ -369,12 +365,11 @@ HistValStatement::writeOutput(ostream &output, const string &basename, bool mini
<< "M_.exo_histval = zeros(M_.exo_nbr,M_.maximum_lag);" << endl << "M_.exo_histval = zeros(M_.exo_nbr,M_.maximum_lag);" << endl
<< "M_.exo_det_histval = zeros(M_.exo_det_nbr,M_.maximum_lag);" << endl; << "M_.exo_det_histval = zeros(M_.exo_det_nbr,M_.maximum_lag);" << endl;
for (hist_values_t::const_iterator it = hist_values.begin(); for (const auto & hist_value : hist_values)
it != hist_values.end(); it++)
{ {
int symb_id = it->first.first; int symb_id = hist_value.first.first;
int lag = it->first.second; int lag = hist_value.first.second;
const expr_t expression = it->second; const expr_t expression = hist_value.second;
SymbolType type = symbol_table.getType(symb_id); SymbolType type = symbol_table.getType(symb_id);
@ -489,12 +484,11 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename, bool min
<< "%" << endl << "%" << endl
<< "options_.homotopy_values = [];" << endl; << "options_.homotopy_values = [];" << endl;
for (homotopy_values_t::const_iterator it = homotopy_values.begin(); for (const auto & homotopy_value : homotopy_values)
it != homotopy_values.end(); it++)
{ {
const int &symb_id = it->first; const int &symb_id = homotopy_value.first;
const expr_t expression1 = it->second.first; const expr_t expression1 = homotopy_value.second.first;
const expr_t expression2 = it->second.second; const expr_t expression2 = homotopy_value.second.second;
const SymbolType type = symbol_table.getType(symb_id); const SymbolType type = symbol_table.getType(symb_id);
const int tsid = symbol_table.getTypeSpecificID(symb_id) + 1; const int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
@ -591,10 +585,9 @@ LoadParamsAndSteadyStateStatement::LoadParamsAndSteadyStateStatement(const strin
void void
LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{ {
for (map<int, string>::const_iterator it = content.begin(); for (const auto & it : content)
it != content.end(); it++)
{ {
switch (symbol_table.getType(it->first)) switch (symbol_table.getType(it.first))
{ {
case eParameter: case eParameter:
output << "M_.params"; output << "M_.params";
@ -609,12 +602,12 @@ LoadParamsAndSteadyStateStatement::writeOutput(ostream &output, const string &ba
output << "oo_.exo_det_steady_state"; output << "oo_.exo_det_steady_state";
break; break;
default: default:
cerr << "ERROR: Unsupported variable type for " << symbol_table.getName(it->first) << " in load_params_and_steady_state" << endl; cerr << "ERROR: Unsupported variable type for " << symbol_table.getName(it.first) << " in load_params_and_steady_state" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
int tsid = symbol_table.getTypeSpecificID(it->first) + 1; int tsid = symbol_table.getTypeSpecificID(it.first) + 1;
output << "(" << tsid << ") = " << it->second << ";" << endl; output << "(" << tsid << ") = " << it.second << ";" << endl;
} }
} }
@ -638,7 +631,6 @@ LoadParamsAndSteadyStateStatement::writeJsonOutput(ostream &output) const
void void
LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) const LoadParamsAndSteadyStateStatement::fillEvalContext(eval_context_t &eval_context) const
{ {
for (map<int, string>::const_iterator it = content.begin(); for (const auto & it : content)
it != content.end(); it++) eval_context[it.first] = atof(it.second.c_str());
eval_context[it->first] = atof(it->second.c_str());
} }

View File

@ -215,12 +215,11 @@ ParsingDriver::declare_endogenous(string *name, string *tex_name, vector<pair<st
delete tex_name; delete tex_name;
if (partition_value != NULL) if (partition_value != NULL)
{ {
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin(); for (auto & it : *partition_value)
it != partition_value->end(); ++it)
{ {
delete (*it)->first; delete it->first;
delete (*it)->second; delete it->second;
delete (*it); delete it;
} }
delete partition_value; delete partition_value;
} }
@ -252,12 +251,11 @@ ParsingDriver::declare_exogenous(string *name, string *tex_name, vector<pair<str
delete tex_name; delete tex_name;
if (partition_value != NULL) if (partition_value != NULL)
{ {
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin(); for (auto & it : *partition_value)
it != partition_value->end(); ++it)
{ {
delete (*it)->first; delete it->first;
delete (*it)->second; delete it->second;
delete (*it); delete it;
} }
delete partition_value; delete partition_value;
} }
@ -272,12 +270,11 @@ ParsingDriver::declare_exogenous_det(string *name, string *tex_name, vector<pair
delete tex_name; delete tex_name;
if (partition_value != NULL) if (partition_value != NULL)
{ {
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin(); for (auto & it : *partition_value)
it != partition_value->end(); ++it)
{ {
delete (*it)->first; delete it->first;
delete (*it)->second; delete it->second;
delete (*it); delete it;
} }
delete partition_value; delete partition_value;
} }
@ -292,12 +289,11 @@ ParsingDriver::declare_parameter(string *name, string *tex_name, vector<pair<str
delete tex_name; delete tex_name;
if (partition_value != NULL) if (partition_value != NULL)
{ {
for (vector<pair<string *, string *> *>::iterator it = partition_value->begin(); for (auto & it : *partition_value)
it != partition_value->end(); ++it)
{ {
delete (*it)->first; delete it->first;
delete (*it)->second; delete it->second;
delete (*it); delete it;
} }
delete partition_value; delete partition_value;
} }
@ -552,8 +548,8 @@ ParsingDriver::end_nonstationary_var(bool log_deflator, expr_t deflator)
set<int> r; set<int> r;
deflator->collectVariables(eEndogenous, r); deflator->collectVariables(eEndogenous, r);
for (set<int>::const_iterator it = r.begin(); it != r.end(); ++it) for (int it : r)
if (dynamic_model->isNonstationary(*it)) if (dynamic_model->isNonstationary(it))
error("The deflator contains a non-stationary endogenous variable. This is not allowed. Please use only stationary endogenous and/or {log_}trend_vars."); error("The deflator contains a non-stationary endogenous variable. This is not allowed. Please use only stationary endogenous and/or {log_}trend_vars.");
declared_nonstationary_vars.clear(); declared_nonstationary_vars.clear();
@ -2306,9 +2302,8 @@ ParsingDriver::run_identification()
void void
ParsingDriver::add_mc_filename(string *filename, string *prior) ParsingDriver::add_mc_filename(string *filename, string *prior)
{ {
for (ModelComparisonStatement::filename_list_t::iterator it = filename_list.begin(); for (auto & it : filename_list)
it != filename_list.end(); it++) if (it.first == *filename)
if ((*it).first == *filename)
error("model_comparison: filename " + *filename + " declared twice"); error("model_comparison: filename " + *filename + " declared twice");
filename_list.push_back(make_pair(*filename, *prior)); filename_list.push_back(make_pair(*filename, *prior));
delete filename; delete filename;
@ -2505,8 +2500,8 @@ ParsingDriver::svar()
itv = options_list.vector_int_options.find("ms.equations"); itv = options_list.vector_int_options.find("ms.equations");
if (itv != options_list.vector_int_options.end()) if (itv != options_list.vector_int_options.end())
for (vector<int>::const_iterator viit = itv->second.begin(); viit != itv->second.end(); viit++) for (int viit : itv->second)
if (*viit <= 0) if (viit <= 0)
error("The value(s) passed to the equation option must be greater than zero."); error("The value(s) passed to the equation option must be greater than zero.");
mod_file->addStatement(new SvarStatement(options_list)); mod_file->addStatement(new SvarStatement(options_list));
@ -2688,27 +2683,26 @@ ParsingDriver::declare_and_init_model_local_variable(string *name, expr_t rhs)
void void
ParsingDriver::change_type(SymbolType new_type, vector<string *> *var_list) ParsingDriver::change_type(SymbolType new_type, vector<string *> *var_list)
{ {
for (vector<string *>::iterator it = var_list->begin(); for (auto & it : *var_list)
it != var_list->end(); it++)
{ {
int id; int id;
try try
{ {
id = mod_file->symbol_table.getID(**it); id = mod_file->symbol_table.getID(*it);
} }
catch (SymbolTable::UnknownSymbolNameException &e) catch (SymbolTable::UnknownSymbolNameException &e)
{ {
error("Unknown variable " + **it); error("Unknown variable " + *it);
} }
// Check if symbol already used in a VariableNode // Check if symbol already used in a VariableNode
if (mod_file->expressions_tree.isSymbolUsed(id) if (mod_file->expressions_tree.isSymbolUsed(id)
|| mod_file->dynamic_model.isSymbolUsed(id)) || mod_file->dynamic_model.isSymbolUsed(id))
error("You cannot modify the type of symbol " + **it + " after having used it in an expression"); error("You cannot modify the type of symbol " + *it + " after having used it in an expression");
mod_file->symbol_table.changeType(id, new_type); mod_file->symbol_table.changeType(id, new_type);
delete *it; delete it;
} }
delete var_list; delete var_list;
} }
@ -3318,21 +3312,21 @@ ParsingDriver::add_steady_state_model_equal_multiple(expr_t expr)
const vector<string> &symbs = symbol_list.get_symbols(); const vector<string> &symbs = symbol_list.get_symbols();
vector<int> ids; vector<int> ids;
for (size_t i = 0; i < symbs.size(); i++) for (const auto & symb : symbs)
{ {
int id; int id;
try try
{ {
id = mod_file->symbol_table.getID(symbs[i]); id = mod_file->symbol_table.getID(symb);
} }
catch (SymbolTable::UnknownSymbolNameException &e) catch (SymbolTable::UnknownSymbolNameException &e)
{ {
// Unknown symbol, declare it as a ModFileLocalVariable // Unknown symbol, declare it as a ModFileLocalVariable
id = mod_file->symbol_table.addSymbol(symbs[i], eModFileLocalVariable); id = mod_file->symbol_table.addSymbol(symb, eModFileLocalVariable);
} }
SymbolType type = mod_file->symbol_table.getType(id); SymbolType type = mod_file->symbol_table.getType(id);
if (type != eEndogenous && type != eModFileLocalVariable && type != eParameter) if (type != eEndogenous && type != eModFileLocalVariable && type != eParameter)
error(symbs[i] + " has incorrect type"); error(symb + " has incorrect type");
ids.push_back(id); ids.push_back(id);
} }

View File

@ -39,17 +39,16 @@ AbstractShocksStatement::writeDetShocks(ostream &output) const
{ {
int exo_det_length = 0; int exo_det_length = 0;
for (det_shocks_t::const_iterator it = det_shocks.begin(); for (const auto & det_shock : det_shocks)
it != det_shocks.end(); it++)
{ {
int id = symbol_table.getTypeSpecificID(it->first) + 1; int id = symbol_table.getTypeSpecificID(det_shock.first) + 1;
bool exo_det = (symbol_table.getType(it->first) == eExogenousDet); bool exo_det = (symbol_table.getType(det_shock.first) == eExogenousDet);
for (size_t i = 0; i < it->second.size(); i++) for (size_t i = 0; i < det_shock.second.size(); i++)
{ {
const int &period1 = it->second[i].period1; const int &period1 = det_shock.second[i].period1;
const int &period2 = it->second[i].period2; const int &period2 = det_shock.second[i].period2;
const expr_t value = it->second[i].value; const expr_t value = det_shock.second[i].value;
output << "M_.det_shocks = [ M_.det_shocks;" << endl output << "M_.det_shocks = [ M_.det_shocks;" << endl
<< "struct('exo_det'," << (int) exo_det << "struct('exo_det'," << (int) exo_det
@ -317,35 +316,32 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati
/* Error out if variables are not of the right type. This must be done here /* Error out if variables are not of the right type. This must be done here
and not at parsing time (see #448). and not at parsing time (see #448).
Also Determine if there is a calibrated measurement error */ Also Determine if there is a calibrated measurement error */
for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); for (auto var_shock : var_shocks)
it != var_shocks.end(); it++)
{ {
if (symbol_table.getType(it->first) != eExogenous if (symbol_table.getType(var_shock.first) != eExogenous
&& !symbol_table.isObservedVariable(it->first)) && !symbol_table.isObservedVariable(var_shock.first))
{ {
cerr << "shocks: setting a variance on '" cerr << "shocks: setting a variance on '"
<< symbol_table.getName(it->first) << "' is not allowed, because it is neither an exogenous variable nor an observed endogenous variable" << endl; << symbol_table.getName(var_shock.first) << "' is not allowed, because it is neither an exogenous variable nor an observed endogenous variable" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); for (auto std_shock : std_shocks)
it != std_shocks.end(); it++)
{ {
if (symbol_table.getType(it->first) != eExogenous if (symbol_table.getType(std_shock.first) != eExogenous
&& !symbol_table.isObservedVariable(it->first)) && !symbol_table.isObservedVariable(std_shock.first))
{ {
cerr << "shocks: setting a standard error on '" cerr << "shocks: setting a standard error on '"
<< symbol_table.getName(it->first) << "' is not allowed, because it is neither an exogenous variable nor an observed endogenous variable" << endl; << symbol_table.getName(std_shock.first) << "' is not allowed, because it is neither an exogenous variable nor an observed endogenous variable" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); for (const auto & covar_shock : covar_shocks)
it != covar_shocks.end(); it++)
{ {
int symb_id1 = it->first.first; int symb_id1 = covar_shock.first.first;
int symb_id2 = it->first.second; int symb_id2 = covar_shock.first.second;
if (!((symbol_table.getType(symb_id1) == eExogenous if (!((symbol_table.getType(symb_id1) == eExogenous
&& symbol_table.getType(symb_id2) == eExogenous) && symbol_table.getType(symb_id2) == eExogenous)
@ -359,11 +355,10 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati
} }
} }
for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); for (const auto & corr_shock : corr_shocks)
it != corr_shocks.end(); it++)
{ {
int symb_id1 = it->first.first; int symb_id1 = corr_shock.first.first;
int symb_id2 = it->first.second; int symb_id2 = corr_shock.first.second;
if (!((symbol_table.getType(symb_id1) == eExogenous if (!((symbol_table.getType(symb_id1) == eExogenous
&& symbol_table.getType(symb_id2) == eExogenous) && symbol_table.getType(symb_id2) == eExogenous)
@ -381,44 +376,36 @@ ShocksStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidati
mod_file_struct.calibrated_measurement_errors |= has_calibrated_measurement_errors(); mod_file_struct.calibrated_measurement_errors |= has_calibrated_measurement_errors();
// Fill in mod_file_struct.parameters_with_shocks_values (related to #469) // Fill in mod_file_struct.parameters_with_shocks_values (related to #469)
for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); for (auto var_shock : var_shocks)
it != var_shocks.end(); ++it) var_shock.second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values);
it->second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values); for (auto std_shock : std_shocks)
for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); std_shock.second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values);
it != std_shocks.end(); ++it) for (const auto & covar_shock : covar_shocks)
it->second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values); covar_shock.second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values);
for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); for (const auto & corr_shock : corr_shocks)
it != covar_shocks.end(); ++it) corr_shock.second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values);
it->second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values);
for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin();
it != corr_shocks.end(); ++it)
it->second->collectVariables(eParameter, mod_file_struct.parameters_within_shocks_values);
} }
bool bool
ShocksStatement::has_calibrated_measurement_errors() const ShocksStatement::has_calibrated_measurement_errors() const
{ {
for (var_and_std_shocks_t::const_iterator it = var_shocks.begin(); for (auto var_shock : var_shocks)
it != var_shocks.end(); it++) if (symbol_table.isObservedVariable(var_shock.first))
if (symbol_table.isObservedVariable(it->first))
return true; return true;
for (var_and_std_shocks_t::const_iterator it = std_shocks.begin(); for (auto std_shock : std_shocks)
it != std_shocks.end(); it++) if (symbol_table.isObservedVariable(std_shock.first))
if (symbol_table.isObservedVariable(it->first))
return true; return true;
for (covar_and_corr_shocks_t::const_iterator it = covar_shocks.begin(); for (const auto & covar_shock : covar_shocks)
it != covar_shocks.end(); it++) if (symbol_table.isObservedVariable(covar_shock.first.first)
if (symbol_table.isObservedVariable(it->first.first) || symbol_table.isObservedVariable(covar_shock.first.second))
|| symbol_table.isObservedVariable(it->first.second))
return true; return true;
for (covar_and_corr_shocks_t::const_iterator it = corr_shocks.begin(); for (const auto & corr_shock : corr_shocks)
it != corr_shocks.end(); it++) if (symbol_table.isObservedVariable(corr_shock.first.first)
if (symbol_table.isObservedVariable(it->first.first) || symbol_table.isObservedVariable(corr_shock.first.second))
|| symbol_table.isObservedVariable(it->first.second))
return true; return true;
return false; return false;
@ -455,14 +442,13 @@ ConditionalForecastPathsStatement::ConditionalForecastPathsStatement(const Abstr
void void
ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings) ConditionalForecastPathsStatement::checkPass(ModFileStructure &mod_file_struct, WarningConsolidation &warnings)
{ {
for (AbstractShocksStatement::det_shocks_t::const_iterator it = paths.begin(); for (const auto & path : paths)
it != paths.end(); it++)
{ {
int this_path_length = 0; int this_path_length = 0;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second; const vector<AbstractShocksStatement::DetShockElement> &elems = path.second;
for (int i = 0; i < (int) elems.size(); i++) for (auto elem : elems)
// Period1 < Period2, as enforced in ParsingDriver::add_period() // Period1 < Period2, as enforced in ParsingDriver::add_period()
this_path_length = max(this_path_length, elems[i].period2); this_path_length = max(this_path_length, elem.period2);
if (path_length == -1) if (path_length == -1)
path_length = this_path_length; path_length = this_path_length;
else if (path_length != this_path_length) else if (path_length != this_path_length)
@ -490,11 +476,11 @@ ConditionalForecastPathsStatement::writeOutput(ostream &output, const string &ba
output << "constrained_vars_ = [constrained_vars_; " << symbol_table.getTypeSpecificID(it->first) + 1 << "];" << endl; output << "constrained_vars_ = [constrained_vars_; " << symbol_table.getTypeSpecificID(it->first) + 1 << "];" << endl;
const vector<AbstractShocksStatement::DetShockElement> &elems = it->second; const vector<AbstractShocksStatement::DetShockElement> &elems = it->second;
for (int i = 0; i < (int) elems.size(); i++) for (auto elem : elems)
for (int j = elems[i].period1; j <= elems[i].period2; j++) for (int j = elem.period1; j <= elem.period2; j++)
{ {
output << "constrained_paths_(" << k << "," << j << ")="; output << "constrained_paths_(" << k << "," << j << ")=";
elems[i].value->writeOutput(output); elem.value->writeOutput(output);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -510,9 +496,8 @@ void
MomentCalibration::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const MomentCalibration::writeOutput(ostream &output, const string &basename, bool minimal_workspace) const
{ {
output << "options_.endogenous_prior_restrictions.moment = {" << endl; output << "options_.endogenous_prior_restrictions.moment = {" << endl;
for (size_t i = 0; i < constraints.size(); i++) for (const auto & c : constraints)
{ {
const Constraint &c = constraints[i];
output << "'" << symbol_table.getName(c.endo1) << "', " output << "'" << symbol_table.getName(c.endo1) << "', "
<< "'" << symbol_table.getName(c.endo2) << "', " << "'" << symbol_table.getName(c.endo2) << "', "
<< c.lags << ", " << c.lags << ", "
@ -555,9 +540,8 @@ IrfCalibration::writeOutput(ostream &output, const string &basename, bool minima
options_list.writeOutput(output); options_list.writeOutput(output);
output << "options_.endogenous_prior_restrictions.irf = {" << endl; output << "options_.endogenous_prior_restrictions.irf = {" << endl;
for (size_t i = 0; i < constraints.size(); i++) for (const auto & c : constraints)
{ {
const Constraint &c = constraints[i];
output << "'" << symbol_table.getName(c.endo) << "', " output << "'" << symbol_table.getName(c.endo) << "', "
<< "'" << symbol_table.getName(c.exo) << "', " << "'" << symbol_table.getName(c.exo) << "', "
<< c.periods << ", " << c.periods << ", "
@ -620,8 +604,8 @@ ShockGroupsStatement::writeOutput(ostream &output, const string &basename, bool
<< ".group" << i << ".label = '" << it->name << "';" << endl << ".group" << i << ".label = '" << it->name << "';" << endl
<< "M_.shock_groups." << name << "M_.shock_groups." << name
<< ".group" << i << ".shocks = {"; << ".group" << i << ".shocks = {";
for (vector<string>::const_iterator it1 = it->list.begin(); it1 != it->list.end(); it1++) for (const auto & it1 : it->list)
output << " '" << *it1 << "'"; output << " '" << it1 << "'";
output << "};" << endl; output << "};" << endl;
i++; i++;
} }

View File

@ -142,57 +142,50 @@ VerbatimStatement::writeJsonOutput(ostream &output) const
void void
OptionsList::writeOutput(ostream &output) const OptionsList::writeOutput(ostream &output) const
{ {
for (num_options_t::const_iterator it = num_options.begin(); for (const auto & num_option : num_options)
it != num_options.end(); it++) output << "options_." << num_option.first << " = " << num_option.second << ";" << endl;
output << "options_." << it->first << " = " << it->second << ";" << endl;
for (paired_num_options_t::const_iterator it = paired_num_options.begin(); for (const auto & paired_num_option : paired_num_options)
it != paired_num_options.end(); it++) output << "options_." << paired_num_option.first << " = [" << paired_num_option.second.first << "; "
output << "options_." << it->first << " = [" << it->second.first << "; " << paired_num_option.second.second << "];" << endl;
<< it->second.second << "];" << endl;
for (string_options_t::const_iterator it = string_options.begin(); for (const auto & string_option : string_options)
it != string_options.end(); it++) output << "options_." << string_option.first << " = '" << string_option.second << "';" << endl;
output << "options_." << it->first << " = '" << it->second << "';" << endl;
for (date_options_t::const_iterator it = date_options.begin(); for (const auto & date_option : date_options)
it != date_options.end(); it++) output << "options_." << date_option.first << " = " << date_option.second << ";" << endl;
output << "options_." << it->first << " = " << it->second << ";" << endl;
for (symbol_list_options_t::const_iterator it = symbol_list_options.begin(); for (const auto & symbol_list_option : symbol_list_options)
it != symbol_list_options.end(); it++) symbol_list_option.second.writeOutput("options_." + symbol_list_option.first, output);
it->second.writeOutput("options_." + it->first, output);
for (vec_int_options_t::const_iterator it = vector_int_options.begin(); for (const auto & vector_int_option : vector_int_options)
it != vector_int_options.end(); it++)
{ {
output << "options_." << it->first << " = "; output << "options_." << vector_int_option.first << " = ";
if (it->second.size() > 1) if (vector_int_option.second.size() > 1)
{ {
output << "["; output << "[";
for (vector<int>::const_iterator viit = it->second.begin(); for (vector<int>::const_iterator viit = vector_int_option.second.begin();
viit != it->second.end(); viit++) viit != vector_int_option.second.end(); viit++)
output << *viit << ";"; output << *viit << ";";
output << "];" << endl; output << "];" << endl;
} }
else else
output << it->second.front() << ";" << endl; output << vector_int_option.second.front() << ";" << endl;
} }
for (vec_str_options_t::const_iterator it = vector_str_options.begin(); for (const auto & vector_str_option : vector_str_options)
it != vector_str_options.end(); it++)
{ {
output << "options_." << it->first << " = "; output << "options_." << vector_str_option.first << " = ";
if (it->second.size() > 1) if (vector_str_option.second.size() > 1)
{ {
output << "{"; output << "{";
for (vector<string>::const_iterator viit = it->second.begin(); for (vector<string>::const_iterator viit = vector_str_option.second.begin();
viit != it->second.end(); viit++) viit != vector_str_option.second.end(); viit++)
output << "'" << *viit << "';"; output << "'" << *viit << "';";
output << "};" << endl; output << "};" << endl;
} }
else else
output << it->second.front() << ";" << endl; output << vector_str_option.second.front() << ";" << endl;
} }
} }
@ -210,57 +203,50 @@ OptionsList::writeOutput(ostream &output, const string &option_group) const
else else
output << option_group << " = struct();" << endl; output << option_group << " = struct();" << endl;
for (num_options_t::const_iterator it = num_options.begin(); for (const auto & num_option : num_options)
it != num_options.end(); it++) output << option_group << "." << num_option.first << " = " << num_option.second << ";" << endl;
output << option_group << "." << it->first << " = " << it->second << ";" << endl;
for (paired_num_options_t::const_iterator it = paired_num_options.begin(); for (const auto & paired_num_option : paired_num_options)
it != paired_num_options.end(); it++) output << option_group << "." << paired_num_option.first << " = [" << paired_num_option.second.first << "; "
output << option_group << "." << it->first << " = [" << it->second.first << "; " << paired_num_option.second.second << "];" << endl;
<< it->second.second << "];" << endl;
for (string_options_t::const_iterator it = string_options.begin(); for (const auto & string_option : string_options)
it != string_options.end(); it++) output << option_group << "." << string_option.first << " = '" << string_option.second << "';" << endl;
output << option_group << "." << it->first << " = '" << it->second << "';" << endl;
for (date_options_t::const_iterator it = date_options.begin(); for (const auto & date_option : date_options)
it != date_options.end(); it++) output << option_group << "." << date_option.first << " = " << date_option.second << ";" << endl;
output << option_group << "." << it->first << " = " << it->second << ";" << endl;
for (symbol_list_options_t::const_iterator it = symbol_list_options.begin(); for (const auto & symbol_list_option : symbol_list_options)
it != symbol_list_options.end(); it++) symbol_list_option.second.writeOutput(option_group + "." + symbol_list_option.first, output);
it->second.writeOutput(option_group + "." + it->first, output);
for (vec_int_options_t::const_iterator it = vector_int_options.begin(); for (const auto & vector_int_option : vector_int_options)
it != vector_int_options.end(); it++)
{ {
output << option_group << "." << it->first << " = "; output << option_group << "." << vector_int_option.first << " = ";
if (it->second.size() > 1) if (vector_int_option.second.size() > 1)
{ {
output << "["; output << "[";
for (vector<int>::const_iterator viit = it->second.begin(); for (vector<int>::const_iterator viit = vector_int_option.second.begin();
viit != it->second.end(); viit++) viit != vector_int_option.second.end(); viit++)
output << *viit << ";"; output << *viit << ";";
output << "];" << endl; output << "];" << endl;
} }
else else
output << it->second.front() << ";" << endl; output << vector_int_option.second.front() << ";" << endl;
} }
for (vec_str_options_t::const_iterator it = vector_str_options.begin(); for (const auto & vector_str_option : vector_str_options)
it != vector_str_options.end(); it++)
{ {
output << option_group << "." << it->first << " = "; output << option_group << "." << vector_str_option.first << " = ";
if (it->second.size() > 1) if (vector_str_option.second.size() > 1)
{ {
output << "{"; output << "{";
for (vector<string>::const_iterator viit = it->second.begin(); for (vector<string>::const_iterator viit = vector_str_option.second.begin();
viit != it->second.end(); viit++) viit != vector_str_option.second.end(); viit++)
output << "'" << *viit << "';"; output << "'" << *viit << "';";
output << "};" << endl; output << "};" << endl;
} }
else else
output << it->second.front() << ";" << endl; output << vector_str_option.second.front() << ";" << endl;
} }
} }

View File

@ -188,9 +188,8 @@ StaticModel::computeTemporaryTermsMapping(temporary_terms_t &temporary_terms, ma
{ {
// Add a mapping form node ID to temporary terms order // Add a mapping form node ID to temporary terms order
int j = 0; int j = 0;
for (temporary_terms_t::const_iterator it = temporary_terms.begin(); for (auto temporary_term : temporary_terms)
it != temporary_terms.end(); it++) map_idx[temporary_term->idx] = j++;
map_idx[(*it)->idx] = j++;
} }
void void
@ -264,9 +263,8 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
if (v_temporary_terms_inuse[block].size()) if (v_temporary_terms_inuse[block].size())
{ {
tmp_output.str(""); tmp_output.str("");
for (temporary_terms_inuse_t::const_iterator it = v_temporary_terms_inuse[block].begin(); for (int it : v_temporary_terms_inuse[block])
it != v_temporary_terms_inuse[block].end(); it++) tmp_output << " T" << it;
tmp_output << " T" << *it;
output << " global" << tmp_output.str() << ";\n"; output << " global" << tmp_output.str() << ";\n";
} }
@ -284,18 +282,17 @@ StaticModel::writeModelEquationsOrdered_M(const string &static_basename) const
if (v_temporary_terms[block].size()) if (v_temporary_terms[block].size())
{ {
output << " " << "% //Temporary variables" << endl; output << " " << "% //Temporary variables" << endl;
for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin(); for (auto it : v_temporary_terms[block][i])
it != v_temporary_terms[block][i].end(); it++)
{ {
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(it) != NULL)
(*it)->writeExternalFunctionOutput(output, local_output_type, tt2, {}, tef_terms); it->writeExternalFunctionOutput(output, local_output_type, tt2, {}, tef_terms);
output << " " << sps; output << " " << sps;
(*it)->writeOutput(output, local_output_type, local_temporary_terms, {}, tef_terms); it->writeOutput(output, local_output_type, local_temporary_terms, {}, tef_terms);
output << " = "; output << " = ";
(*it)->writeOutput(output, local_output_type, tt2, {}, tef_terms); it->writeOutput(output, local_output_type, tt2, {}, tef_terms);
// Insert current node into tt2 // Insert current node into tt2
tt2.insert(*it); tt2.insert(it);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -442,9 +439,8 @@ StaticModel::writeModelEquationsCode(const string file_name, const string bin_ba
// Add a mapping form node ID to temporary terms order // Add a mapping form node ID to temporary terms order
int j = 0; int j = 0;
for (temporary_terms_t::const_iterator it = temporary_terms.begin(); for (auto temporary_term : temporary_terms)
it != temporary_terms.end(); it++) map_idx[temporary_term->idx] = j++;
map_idx[(*it)->idx] = j++;
compileTemporaryTerms(code_file, instruction_number, temporary_terms, map_idx, false, false); compileTemporaryTerms(code_file, instruction_number, temporary_terms, map_idx, false, false);
compileModelEquations(code_file, instruction_number, temporary_terms, map_idx, false, false); compileModelEquations(code_file, instruction_number, temporary_terms, map_idx, false, false);
@ -461,14 +457,13 @@ StaticModel::writeModelEquationsCode(const string file_name, const string bin_ba
vector<vector<pair<int, int> > > derivatives; vector<vector<pair<int, int> > > derivatives;
derivatives.resize(symbol_table.endo_nbr()); derivatives.resize(symbol_table.endo_nbr());
count_u = symbol_table.endo_nbr(); count_u = symbol_table.endo_nbr();
for (first_derivatives_t::const_iterator it = first_derivatives.begin(); for (const auto & first_derivative : first_derivatives)
it != first_derivatives.end(); it++)
{ {
int deriv_id = it->first.second; int deriv_id = first_derivative.first.second;
if (getTypeByDerivID(deriv_id) == eEndogenous) if (getTypeByDerivID(deriv_id) == eEndogenous)
{ {
expr_t d1 = it->second; expr_t d1 = first_derivative.second;
unsigned int eq = it->first.first; unsigned int eq = first_derivative.first.first;
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
unsigned int var = symbol_table.getTypeSpecificID(symb); unsigned int var = symbol_table.getTypeSpecificID(symb);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var); FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var);
@ -529,14 +524,13 @@ StaticModel::writeModelEquationsCode(const string file_name, const string bin_ba
tt3.clear(); tt3.clear();
// The Jacobian if we have to solve the block determinsitic bloc // The Jacobian if we have to solve the block determinsitic bloc
for (first_derivatives_t::const_iterator it = first_derivatives.begin(); for (const auto & first_derivative : first_derivatives)
it != first_derivatives.end(); it++)
{ {
int deriv_id = it->first.second; int deriv_id = first_derivative.first.second;
if (getTypeByDerivID(deriv_id) == eEndogenous) if (getTypeByDerivID(deriv_id) == eEndogenous)
{ {
expr_t d1 = it->second; expr_t d1 = first_derivative.second;
unsigned int eq = it->first.first; unsigned int eq = first_derivative.first.first;
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
unsigned int var = symbol_table.getTypeSpecificID(symb); unsigned int var = symbol_table.getTypeSpecificID(symb);
FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var); FNUMEXPR_ fnumexpr(FirstEndoDerivative, eq, var);
@ -656,19 +650,18 @@ StaticModel::writeModelEquationsCode_Block(const string file_name, const string
tt2.clear(); tt2.clear();
if (v_temporary_terms[block].size()) if (v_temporary_terms[block].size())
{ {
for (temporary_terms_t::const_iterator it = v_temporary_terms[block][i].begin(); for (auto it : v_temporary_terms[block][i])
it != v_temporary_terms[block][i].end(); it++)
{ {
if (dynamic_cast<AbstractExternalFunctionNode *>(*it) != NULL) if (dynamic_cast<AbstractExternalFunctionNode *>(it) != NULL)
(*it)->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms); it->compileExternalFunctionOutput(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms);
FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find((*it)->idx)->second)); FNUMEXPR_ fnumexpr(TemporaryTerm, (int)(map_idx.find(it->idx)->second));
fnumexpr.write(code_file, instruction_number); fnumexpr.write(code_file, instruction_number);
(*it)->compile(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms); it->compile(code_file, instruction_number, false, tt2, map_idx, false, false, tef_terms);
FSTPST_ fstpst((int)(map_idx.find((*it)->idx)->second)); FSTPST_ fstpst((int)(map_idx.find(it->idx)->second));
fstpst.write(code_file, instruction_number); fstpst.write(code_file, instruction_number);
// Insert current node into tt2 // Insert current node into tt2
tt2.insert(*it); tt2.insert(it);
} }
} }
@ -1033,15 +1026,14 @@ map<pair<int, pair<int, int > >, expr_t>
StaticModel::collect_first_order_derivatives_endogenous() StaticModel::collect_first_order_derivatives_endogenous()
{ {
map<pair<int, pair<int, int > >, expr_t> endo_derivatives; map<pair<int, pair<int, int > >, expr_t> endo_derivatives;
for (first_derivatives_t::iterator it2 = first_derivatives.begin(); for (auto & first_derivative : first_derivatives)
it2 != first_derivatives.end(); it2++)
{ {
if (getTypeByDerivID(it2->first.second) == eEndogenous) if (getTypeByDerivID(first_derivative.first.second) == eEndogenous)
{ {
int eq = it2->first.first; int eq = first_derivative.first.first;
int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(it2->first.second)); int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(first_derivative.first.second));
int lag = 0; int lag = 0;
endo_derivatives[make_pair(eq, make_pair(var, lag))] = it2->second; endo_derivatives[make_pair(eq, make_pair(var, lag))] = first_derivative.second;
} }
} }
return endo_derivatives; return endo_derivatives;
@ -1059,9 +1051,9 @@ StaticModel::computingPass(const eval_context_t &eval_context, bool no_tmp_terms
neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this))); neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this)));
} }
for (unsigned int eq = 0; eq < aux_equations.size(); eq++) for (auto & aux_equation : aux_equations)
{ {
expr_t eq_tmp = aux_equations[eq]->substituteStaticAuxiliaryDefinition(); expr_t eq_tmp = aux_equation->substituteStaticAuxiliaryDefinition();
neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this))); neweqs.push_back(dynamic_cast<BinaryOpNode *>(eq_tmp->toStatic(*this)));
} }
@ -1356,9 +1348,8 @@ StaticModel::writeStaticModel(const string &basename,
deriv_node_temp_terms_t tef_terms; deriv_node_temp_terms_t tef_terms;
temporary_terms_t temp_term_union; temporary_terms_t temp_term_union;
for (map<expr_t, expr_t>::const_iterator it = temporary_terms_mlv.begin(); for (auto it : temporary_terms_mlv)
it != temporary_terms_mlv.end(); it++) temp_term_union.insert(it.first);
temp_term_union.insert(it->first);
writeModelLocalVariableTemporaryTerms(temp_term_union, temporary_terms_mlv, writeModelLocalVariableTemporaryTerms(temp_term_union, temporary_terms_mlv,
model_tt_output, output_type, tef_terms); model_tt_output, output_type, tef_terms);
@ -1383,12 +1374,11 @@ StaticModel::writeStaticModel(const string &basename,
jacobian_tt_output, output_type, tef_terms); jacobian_tt_output, output_type, tef_terms);
temp_term_union.insert(temporary_terms_g1.begin(), temporary_terms_g1.end()); temp_term_union.insert(temporary_terms_g1.begin(), temporary_terms_g1.end());
} }
for (first_derivatives_t::const_iterator it = first_derivatives.begin(); for (const auto & first_derivative : first_derivatives)
it != first_derivatives.end(); it++)
{ {
int eq = it->first.first; int eq = first_derivative.first.first;
int symb_id = getSymbIDByDerivID(it->first.second); int symb_id = getSymbIDByDerivID(first_derivative.first.second);
expr_t d1 = it->second; expr_t d1 = first_derivative.second;
jacobianHelper(jacobian_output, eq, symbol_table.getTypeSpecificID(symb_id), output_type); jacobianHelper(jacobian_output, eq, symbol_table.getTypeSpecificID(symb_id), output_type);
jacobian_output << "="; jacobian_output << "=";
@ -1408,13 +1398,12 @@ StaticModel::writeStaticModel(const string &basename,
temp_term_union.insert(temporary_terms_g2.begin(), temporary_terms_g2.end()); temp_term_union.insert(temporary_terms_g2.begin(), temporary_terms_g2.end());
int k = 0; // Keep the line of a 2nd derivative in v2 int k = 0; // Keep the line of a 2nd derivative in v2
for (second_derivatives_t::const_iterator it = second_derivatives.begin(); for (const auto & second_derivative : second_derivatives)
it != second_derivatives.end(); it++)
{ {
int eq = it->first.first; int eq = second_derivative.first.first;
int symb_id1 = getSymbIDByDerivID(it->first.second.first); int symb_id1 = getSymbIDByDerivID(second_derivative.first.second.first);
int symb_id2 = getSymbIDByDerivID(it->first.second.second); int symb_id2 = getSymbIDByDerivID(second_derivative.first.second.second);
expr_t d2 = it->second; expr_t d2 = second_derivative.second;
int tsid1 = symbol_table.getTypeSpecificID(symb_id1); int tsid1 = symbol_table.getTypeSpecificID(symb_id1);
int tsid2 = symbol_table.getTypeSpecificID(symb_id2); int tsid2 = symbol_table.getTypeSpecificID(symb_id2);
@ -1478,14 +1467,13 @@ StaticModel::writeStaticModel(const string &basename,
temp_term_union.insert(temporary_terms_g3.begin(), temporary_terms_g3.end()); temp_term_union.insert(temporary_terms_g3.begin(), temporary_terms_g3.end());
int k = 0; // Keep the line of a 3rd derivative in v3 int k = 0; // Keep the line of a 3rd derivative in v3
for (third_derivatives_t::const_iterator it = third_derivatives.begin(); for (const auto & third_derivative : third_derivatives)
it != third_derivatives.end(); it++)
{ {
int eq = it->first.first; int eq = third_derivative.first.first;
int var1 = it->first.second.first; int var1 = third_derivative.first.second.first;
int var2 = it->first.second.second.first; int var2 = third_derivative.first.second.second.first;
int var3 = it->first.second.second.second; int var3 = third_derivative.first.second.second.second;
expr_t d3 = it->second; expr_t d3 = third_derivative.second;
int id1 = getSymbIDByDerivID(var1); int id1 = getSymbIDByDerivID(var1);
int id2 = getSymbIDByDerivID(var2); int id2 = getSymbIDByDerivID(var2);
@ -1525,10 +1513,10 @@ StaticModel::writeStaticModel(const string &basename,
cols.insert(id3 * hessianColsNbr + id2 * JacobianColsNbr + id1); cols.insert(id3 * hessianColsNbr + id2 * JacobianColsNbr + id1);
int k2 = 1; // Keeps the offset of the permutation relative to k int k2 = 1; // Keeps the offset of the permutation relative to k
for (set<int>::iterator it2 = cols.begin(); it2 != cols.end(); it2++) for (int col : cols)
if (*it2 != ref_col) if (col != ref_col)
if (output_type == oJuliaStaticModel) if (output_type == oJuliaStaticModel)
third_derivatives_output << " @inbounds g3[" << eq + 1 << "," << *it2 + 1 << "] = " third_derivatives_output << " @inbounds g3[" << eq + 1 << "," << col + 1 << "] = "
<< for_sym.str() << endl; << for_sym.str() << endl;
else else
{ {
@ -1536,7 +1524,7 @@ StaticModel::writeStaticModel(const string &basename,
third_derivatives_output << "=" << eq + 1 << ";" << endl; third_derivatives_output << "=" << eq + 1 << ";" << endl;
sparseHelper(3, third_derivatives_output, k+k2, 1, output_type); sparseHelper(3, third_derivatives_output, k+k2, 1, output_type);
third_derivatives_output << "=" << *it2 + 1 << ";" << endl; third_derivatives_output << "=" << col + 1 << ";" << endl;
sparseHelper(3, third_derivatives_output, k+k2, 2, output_type); sparseHelper(3, third_derivatives_output, k+k2, 2, output_type);
third_derivatives_output << "="; third_derivatives_output << "=";
@ -2042,8 +2030,8 @@ StaticModel::writeStaticFile(const string &basename, bool block, bool bytecode,
bool bool
StaticModel::exoPresentInEqs() const StaticModel::exoPresentInEqs() const
{ {
for (int i = 0; i < (int) equations.size(); i++) for (auto equation : equations)
if (equations[i]->containsExogenous()) if (equation->containsExogenous())
return true; return true;
return false; return false;
} }
@ -2143,13 +2131,12 @@ StaticModel::writeOutput(ostream &output, bool block) const
output << "];\n"; output << "];\n";
map<pair<int, int>, int> row_incidence; map<pair<int, int>, int> row_incidence;
for (first_derivatives_t::const_iterator it = first_derivatives.begin(); for (const auto & first_derivative : first_derivatives)
it != first_derivatives.end(); it++)
{ {
int deriv_id = it->first.second; int deriv_id = first_derivative.first.second;
if (getTypeByDerivID(deriv_id) == eEndogenous) if (getTypeByDerivID(deriv_id) == eEndogenous)
{ {
int eq = it->first.first; int eq = first_derivative.first.first;
int symb = getSymbIDByDerivID(deriv_id); int symb = getSymbIDByDerivID(deriv_id);
int var = symbol_table.getTypeSpecificID(symb); int var = symbol_table.getTypeSpecificID(symb);
//int lag = getLagByDerivID(deriv_id); //int lag = getLagByDerivID(deriv_id);
@ -2360,11 +2347,10 @@ StaticModel::collect_block_first_order_derivatives()
derivative_endo = vector<derivative_t>(nb_blocks); derivative_endo = vector<derivative_t>(nb_blocks);
endo_max_leadlag_block = vector<pair<int, int> >(nb_blocks, make_pair(0, 0)); endo_max_leadlag_block = vector<pair<int, int> >(nb_blocks, make_pair(0, 0));
max_leadlag_block = vector<pair<int, int> >(nb_blocks, make_pair(0, 0)); max_leadlag_block = vector<pair<int, int> >(nb_blocks, make_pair(0, 0));
for (first_derivatives_t::iterator it2 = first_derivatives.begin(); for (auto & first_derivative : first_derivatives)
it2 != first_derivatives.end(); it2++)
{ {
int eq = it2->first.first; int eq = first_derivative.first.first;
int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(it2->first.second)); int var = symbol_table.getTypeSpecificID(getSymbIDByDerivID(first_derivative.first.second));
int lag = 0; int lag = 0;
int block_eq = equation_2_block[eq]; int block_eq = equation_2_block[eq];
int block_var = variable_2_block[var]; int block_var = variable_2_block[var];
@ -2374,7 +2360,7 @@ StaticModel::collect_block_first_order_derivatives()
endo_max_leadlag_block[block_eq] = make_pair(0, 0); endo_max_leadlag_block[block_eq] = make_pair(0, 0);
derivative_t tmp_derivative; derivative_t tmp_derivative;
lag_var_t lag_var; lag_var_t lag_var;
if (getTypeByDerivID(it2->first.second) == eEndogenous && block_eq == block_var) if (getTypeByDerivID(first_derivative.first.second) == eEndogenous && block_eq == block_var)
{ {
tmp_derivative = derivative_endo[block_eq]; tmp_derivative = derivative_endo[block_eq];
tmp_derivative[make_pair(lag, make_pair(eq, var))] = first_derivatives[make_pair(eq, getDerivID(symbol_table.getID(eEndogenous, var), lag))]; tmp_derivative[make_pair(lag, make_pair(eq, var))] = first_derivatives[make_pair(eq, getDerivID(symbol_table.getID(eEndogenous, var), lag))];
@ -2392,9 +2378,9 @@ StaticModel::writeLatexFile(const string &basename, bool write_equation_tags) co
void void
StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const StaticModel::writeAuxVarInitval(ostream &output, ExprNodeOutputType output_type) const
{ {
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
{ {
dynamic_cast<ExprNode *>(aux_equations[i])->writeOutput(output, output_type); dynamic_cast<ExprNode *>(aux_equation)->writeOutput(output, output_type);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -2435,12 +2421,12 @@ void
StaticModel::writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType output_type) const StaticModel::writeAuxVarRecursiveDefinitions(ostream &output, ExprNodeOutputType output_type) const
{ {
deriv_node_temp_terms_t tef_terms; deriv_node_temp_terms_t tef_terms;
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction()) if (dynamic_cast<ExprNode *>(aux_equation)->containsExternalFunction())
dynamic_cast<ExprNode *>(aux_equations[i])->writeExternalFunctionOutput(output, oMatlabStaticModel, {}, {}, tef_terms); dynamic_cast<ExprNode *>(aux_equation)->writeExternalFunctionOutput(output, oMatlabStaticModel, {}, {}, tef_terms);
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
{ {
dynamic_cast<ExprNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->writeOutput(output, output_type); dynamic_cast<ExprNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->writeOutput(output, output_type);
output << ";" << endl; output << ";" << endl;
} }
} }
@ -2451,14 +2437,14 @@ StaticModel::writeLatexAuxVarRecursiveDefinitions(ostream &output) const
deriv_node_temp_terms_t tef_terms; deriv_node_temp_terms_t tef_terms;
temporary_terms_t temporary_terms; temporary_terms_t temporary_terms;
temporary_terms_idxs_t temporary_terms_idxs; temporary_terms_idxs_t temporary_terms_idxs;
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction()) if (dynamic_cast<ExprNode *>(aux_equation)->containsExternalFunction())
dynamic_cast<ExprNode *>(aux_equations[i])->writeExternalFunctionOutput(output, oLatexStaticModel, dynamic_cast<ExprNode *>(aux_equation)->writeExternalFunctionOutput(output, oLatexStaticModel,
temporary_terms, temporary_terms_idxs, tef_terms); temporary_terms, temporary_terms_idxs, tef_terms);
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
{ {
output << "\\begin{dmath}" << endl; output << "\\begin{dmath}" << endl;
dynamic_cast<ExprNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->writeOutput(output, oLatexStaticModel); dynamic_cast<ExprNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->writeOutput(output, oLatexStaticModel);
output << endl << "\\end{dmath}" << endl; output << endl << "\\end{dmath}" << endl;
} }
} }
@ -2469,11 +2455,11 @@ StaticModel::writeJsonAuxVarRecursiveDefinitions(ostream &output) const
deriv_node_temp_terms_t tef_terms; deriv_node_temp_terms_t tef_terms;
temporary_terms_t temporary_terms; temporary_terms_t temporary_terms;
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
if (dynamic_cast<ExprNode *>(aux_equations[i])->containsExternalFunction()) if (dynamic_cast<ExprNode *>(aux_equation)->containsExternalFunction())
{ {
vector<string> efout; vector<string> efout;
dynamic_cast<ExprNode *>(aux_equations[i])->writeJsonExternalFunctionOutput(efout, dynamic_cast<ExprNode *>(aux_equation)->writeJsonExternalFunctionOutput(efout,
temporary_terms, temporary_terms,
tef_terms, tef_terms,
false); false);
@ -2485,12 +2471,12 @@ StaticModel::writeJsonAuxVarRecursiveDefinitions(ostream &output) const
} }
} }
for (int i = 0; i < (int) aux_equations.size(); i++) for (auto aux_equation : aux_equations)
{ {
output << ", {\"lhs\": \""; output << ", {\"lhs\": \"";
aux_equations[i]->get_arg1()->writeJsonOutput(output, temporary_terms, tef_terms, false); aux_equation->get_arg1()->writeJsonOutput(output, temporary_terms, tef_terms, false);
output << "\", \"rhs\": \""; output << "\", \"rhs\": \"";
dynamic_cast<BinaryOpNode *>(aux_equations[i]->substituteStaticAuxiliaryDefinition())->get_arg2()->writeJsonOutput(output, temporary_terms, tef_terms, false); dynamic_cast<BinaryOpNode *>(aux_equation->substituteStaticAuxiliaryDefinition())->get_arg2()->writeJsonOutput(output, temporary_terms, tef_terms, false);
output << "\"}"; output << "\"}";
} }
} }
@ -2519,12 +2505,11 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons
writeTemporaryTerms(params_derivs_temporary_terms, {}, params_derivs_temporary_terms_idxs, model_output, output_type, tef_terms); writeTemporaryTerms(params_derivs_temporary_terms, {}, params_derivs_temporary_terms_idxs, model_output, output_type, tef_terms);
for (first_derivatives_t::const_iterator it = residuals_params_derivatives.begin(); for (const auto & residuals_params_derivative : residuals_params_derivatives)
it != residuals_params_derivatives.end(); it++)
{ {
int eq = it->first.first; int eq = residuals_params_derivative.first.first;
int param = it->first.second; int param = residuals_params_derivative.first.second;
expr_t d1 = it->second; expr_t d1 = residuals_params_derivative.second;
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;
@ -2535,13 +2520,12 @@ StaticModel::writeParamsDerivativesFile(const string &basename, bool julia) cons
jacobian_output << ";" << endl; jacobian_output << ";" << endl;
} }
for (second_derivatives_t::const_iterator it = jacobian_params_derivatives.begin(); for (const auto & jacobian_params_derivative : jacobian_params_derivatives)
it != jacobian_params_derivatives.end(); it++)
{ {
int eq = it->first.first; int eq = jacobian_params_derivative.first.first;
int var = it->first.second.first; int var = jacobian_params_derivative.first.second.first;
int param = it->first.second.second; int param = jacobian_params_derivative.first.second.second;
expr_t d2 = it->second; expr_t d2 = jacobian_params_derivative.second;
int var_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(var)) + 1; int var_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(var)) + 1;
int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1; int param_col = symbol_table.getTypeSpecificID(getSymbIDByDerivID(param)) + 1;

View File

@ -45,12 +45,12 @@ SteadyStateModel::addDefinition(int symb_id, expr_t expr)
void void
SteadyStateModel::addMultipleDefinitions(const vector<int> &symb_ids, expr_t expr) SteadyStateModel::addMultipleDefinitions(const vector<int> &symb_ids, expr_t expr)
{ {
for (size_t i = 0; i < symb_ids.size(); i++) for (int symb_id : symb_ids)
{ {
AddVariable(symb_ids[i]); // Create the variable nodes to be used in write method AddVariable(symb_id); // Create the variable nodes to be used in write method
assert(symbol_table.getType(symb_ids[i]) == eEndogenous assert(symbol_table.getType(symb_id) == eEndogenous
|| symbol_table.getType(symb_ids[i]) == eModFileLocalVariable || symbol_table.getType(symb_id) == eModFileLocalVariable
|| symbol_table.getType(symb_ids[i]) == eParameter); || symbol_table.getType(symb_id) == eParameter);
} }
def_table.push_back(make_pair(symb_ids, expr)); def_table.push_back(make_pair(symb_ids, expr));
} }
@ -64,29 +64,28 @@ SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
mod_file_struct.steady_state_model_present = true; mod_file_struct.steady_state_model_present = true;
vector<int> so_far_defined; vector<int> so_far_defined;
for (size_t i = 0; i < def_table.size(); i++) for (const auto & i : def_table)
{ {
const vector<int> &symb_ids = def_table[i].first; const vector<int> &symb_ids = i.first;
// Check that symbols are not already defined // Check that symbols are not already defined
for (size_t j = 0; j < symb_ids.size(); j++) for (int symb_id : symb_ids)
if (find(so_far_defined.begin(), so_far_defined.end(), symb_ids[j]) if (find(so_far_defined.begin(), so_far_defined.end(), symb_id)
!= so_far_defined.end()) != so_far_defined.end())
warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(symb_ids[j]) << "' is declared twice" << endl; warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(symb_id) << "' is declared twice" << endl;
// Check that expression has no undefined symbol // Check that expression has no undefined symbol
if (!mod_file_struct.ramsey_model_present) if (!mod_file_struct.ramsey_model_present)
{ {
set<int> used_symbols; set<int> used_symbols;
const expr_t &expr = def_table[i].second; const expr_t &expr = i.second;
expr->collectVariables(eEndogenous, used_symbols); expr->collectVariables(eEndogenous, used_symbols);
expr->collectVariables(eModFileLocalVariable, used_symbols); expr->collectVariables(eModFileLocalVariable, used_symbols);
for (set<int>::const_iterator it = used_symbols.begin(); for (int used_symbol : used_symbols)
it != used_symbols.end(); ++it) if (find(so_far_defined.begin(), so_far_defined.end(), used_symbol)
if (find(so_far_defined.begin(), so_far_defined.end(), *it)
== so_far_defined.end()) == so_far_defined.end())
{ {
cerr << "ERROR: in the 'steady_state_model' block, variable '" << symbol_table.getName(*it) cerr << "ERROR: in the 'steady_state_model' block, variable '" << symbol_table.getName(used_symbol)
<< "' is undefined in the declaration of variable '" << symbol_table.getName(symb_ids[0]) << "'" << endl; << "' is undefined in the declaration of variable '" << symbol_table.getName(symb_ids[0]) << "'" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -96,12 +95,11 @@ SteadyStateModel::checkPass(ModFileStructure &mod_file_struct, WarningConsolidat
} }
set<int> orig_endogs = symbol_table.getOrigEndogenous(); set<int> orig_endogs = symbol_table.getOrigEndogenous();
for (set<int>::const_iterator it = orig_endogs.begin(); for (int orig_endog : orig_endogs)
it != orig_endogs.end(); ++it)
{ {
if (find(so_far_defined.begin(), so_far_defined.end(), *it) if (find(so_far_defined.begin(), so_far_defined.end(), orig_endog)
== so_far_defined.end()) == so_far_defined.end())
warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(*it) << "' is not assigned a value" << endl; warnings << "WARNING: in the 'steady_state_model' block, variable '" << symbol_table.getName(orig_endog) << "' is not assigned a value" << endl;
} }
} }
@ -135,12 +133,11 @@ SteadyStateModel::writeLatexSteadyStateFile(const string &basename) const
<< "\\begin{document}" << endl << "\\begin{document}" << endl
<< "\\footnotesize" << endl; << "\\footnotesize" << endl;
for (vector<pair<vector<int>, expr_t> >::const_iterator it = def_table.begin(); for (const auto & it : def_table)
it != def_table.end(); it++) for (vector<int>::const_iterator it1 = it.first.begin(); it1 != it.first.end(); it1++)
for (vector<int>::const_iterator it1 = it->first.begin(); it1 != it->first.end(); it1++)
{ {
int id = *it1; int id = *it1;
expr_t value = it->second; expr_t value = it.second;
content_output << "\\begin{dmath}" << endl content_output << "\\begin{dmath}" << endl
<< symbol_table.getTeXName(id) << " = "; << symbol_table.getTeXName(id) << " = ";
value->writeOutput(content_output, oLatexStaticModel); value->writeOutput(content_output, oLatexStaticModel);
@ -188,9 +185,9 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
<< "function steady_state!(ys_::Vector{Float64}, exo_::Vector{Float64}, " << "function steady_state!(ys_::Vector{Float64}, exo_::Vector{Float64}, "
<< "params::Vector{Float64})" << endl; << "params::Vector{Float64})" << endl;
for (size_t i = 0; i < def_table.size(); i++) for (const auto & i : def_table)
{ {
const vector<int> &symb_ids = def_table[i].first; const vector<int> &symb_ids = i.first;
output << " "; output << " ";
if (symb_ids.size() > 1) if (symb_ids.size() > 1)
output << "["; output << "[";
@ -206,7 +203,7 @@ SteadyStateModel::writeSteadyStateFile(const string &basename, bool ramsey_model
output << "]"; output << "]";
output << "="; output << "=";
def_table[i].second->writeOutput(output, output_type); i.second->writeOutput(output, output_type);
output << ";" << endl; output << ";" << endl;
} }
if (!julia) if (!julia)
@ -251,9 +248,9 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode
return; return;
} }
for (size_t i = 0; i < def_table.size(); i++) for (const auto & i : def_table)
{ {
const vector<int> &symb_ids = def_table[i].first; const vector<int> &symb_ids = i.first;
output << " "; output << " ";
if (symb_ids.size() > 1) if (symb_ids.size() > 1)
std::cout << "Error: in C, multiple returns are not permitted in steady_state_model" << std::endl; std::cout << "Error: in C, multiple returns are not permitted in steady_state_model" << std::endl;
@ -263,7 +260,7 @@ SteadyStateModel::writeSteadyStateFileC(const string &basename, bool ramsey_mode
output << "double "; output << "double ";
dynamic_cast<ExprNode *>(it->second)->writeOutput(output, oCSteadyStateFile); dynamic_cast<ExprNode *>(it->second)->writeOutput(output, oCSteadyStateFile);
output << "="; output << "=";
def_table[i].second->writeOutput(output, oCSteadyStateFile); i.second->writeOutput(output, oCSteadyStateFile);
output << ";" << endl; output << ";" << endl;
} }
output << " // Auxiliary equations" << endl; output << " // Auxiliary equations" << endl;

View File

@ -71,10 +71,9 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
string final_long_name = name; string final_long_name = name;
bool non_long_name_partition_exists = false; bool non_long_name_partition_exists = false;
if (partition_value) if (partition_value)
for (vector<pair<string *, string *> *>::const_iterator it = partition_value->begin(); for (auto it : *partition_value)
it != partition_value->end(); it++) if (*(it->first) == "long_name")
if (*((*it)->first) == "long_name") final_long_name = *(it->second);
final_long_name = *((*it)->second);
else else
non_long_name_partition_exists = true; non_long_name_partition_exists = true;
@ -88,9 +87,8 @@ SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_na
if (non_long_name_partition_exists) if (non_long_name_partition_exists)
{ {
map<string, string> pmv; map<string, string> pmv;
for (vector<pair<string *, string *> *>::const_iterator it = partition_value->begin(); for (auto it : *partition_value)
it != partition_value->end(); it++) pmv[*(it->first)] = *(it->second);
pmv[*((*it)->first)] = *((*it)->second);
partition_value_map[id] = pmv; partition_value_map[id] = pmv;
} }
return id; return id;
@ -198,15 +196,14 @@ map<string, map<int, string> >
SymbolTable::getPartitionsForType(enum SymbolType st) const throw (UnknownSymbolIDException) SymbolTable::getPartitionsForType(enum SymbolType st) const throw (UnknownSymbolIDException)
{ {
map<string, map<int, string> > partitions; map<string, map<int, string> > partitions;
for (map<int, map<string, string> >::const_iterator it = partition_value_map.begin(); for (const auto & it : partition_value_map)
it != partition_value_map.end(); it++) if (getType(it.first) == st)
if (getType(it->first) == st) for (map<string, string>::const_iterator it1 = it.second.begin();
for (map<string, string>::const_iterator it1 = it->second.begin(); it1 != it.second.end(); it1++)
it1 != it->second.end(); it1++)
{ {
if (partitions.find(it1->first) == partitions.end()) if (partitions.find(it1->first) == partitions.end())
partitions[it1->first] = map<int, string> (); partitions[it1->first] = map<int, string> ();
partitions[it1->first][it->first] = it1->second; partitions[it1->first][it.first] = it1->second;
} }
return partitions; return partitions;
} }
@ -387,9 +384,8 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
if (predeterminedNbr() > 0) if (predeterminedNbr() > 0)
{ {
output << "M_.predetermined_variables = [ "; output << "M_.predetermined_variables = [ ";
for (set<int>::const_iterator it = predetermined_variables.begin(); for (int predetermined_variable : predetermined_variables)
it != predetermined_variables.end(); it++) output << getTypeSpecificID(predetermined_variable)+1 << " ";
output << getTypeSpecificID(*it)+1 << " ";
output << "];" << endl; output << "];" << endl;
} }
@ -402,9 +398,8 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
output << "options_.varobs(" << ic << ") = {'" << getName(*it) << "'};" << endl; output << "options_.varobs(" << ic << ") = {'" << getName(*it) << "'};" << endl;
output << "options_.varobs_id = [ "; output << "options_.varobs_id = [ ";
for (vector<int>::const_iterator it = varobs.begin(); for (int varob : varobs)
it != varobs.end(); it++) output << getTypeSpecificID(varob)+1 << " ";
output << getTypeSpecificID(*it)+1 << " ";
output << " ];" << endl; output << " ];" << endl;
} }
@ -417,9 +412,8 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
output << "options_.varexobs(" << ic << ") = {'" << getName(*it) << "'};" << endl; output << "options_.varexobs(" << ic << ") = {'" << getName(*it) << "'};" << endl;
output << "options_.varexobs_id = [ "; output << "options_.varexobs_id = [ ";
for (vector<int>::const_iterator it = varexobs.begin(); for (int varexob : varexobs)
it != varexobs.end(); it++) output << getTypeSpecificID(varexob)+1 << " ";
output << getTypeSpecificID(*it)+1 << " ";
output << " ];" << endl; output << " ];" << endl;
} }
} }
@ -600,17 +594,14 @@ SymbolTable::writeCCOutput(ostream &output) const throw (NotYetFrozenException)
output << "aux_vars.push_back(" << "av" << i << ");" << endl; output << "aux_vars.push_back(" << "av" << i << ");" << endl;
} }
for (set<int>::const_iterator it = predetermined_variables.begin(); for (int predetermined_variable : predetermined_variables)
it != predetermined_variables.end(); it++) output << "predetermined_variables.push_back(" << getTypeSpecificID(predetermined_variable) << ");" << endl;
output << "predetermined_variables.push_back(" << getTypeSpecificID(*it) << ");" << endl;
for (vector<int>::const_iterator it = varobs.begin(); for (int varob : varobs)
it != varobs.end(); it++) output << "varobs.push_back(" << getTypeSpecificID(varob) << ");" << endl;
output << "varobs.push_back(" << getTypeSpecificID(*it) << ");" << endl;
for (vector<int>::const_iterator it = varexobs.begin(); for (int varexob : varexobs)
it != varexobs.end(); it++) output << "varexobs.push_back(" << getTypeSpecificID(varexob) << ");" << endl;
output << "varexobs.push_back(" << getTypeSpecificID(*it) << ");" << endl;
} }
int int
@ -853,20 +844,20 @@ SymbolTable::addDiffForwardAuxiliaryVar(int orig_symb_id, expr_t expr_arg) throw
int int
SymbolTable::searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const throw (SearchFailedException) SymbolTable::searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const throw (SearchFailedException)
{ {
for (size_t i = 0; i < aux_vars.size(); i++) for (const auto & aux_var : aux_vars)
if ((aux_vars[i].get_type() == avEndoLag || aux_vars[i].get_type() == avExoLag) if ((aux_var.get_type() == avEndoLag || aux_var.get_type() == avExoLag)
&& aux_vars[i].get_orig_symb_id() == orig_symb_id && aux_vars[i].get_orig_lead_lag() == orig_lead_lag) && aux_var.get_orig_symb_id() == orig_symb_id && aux_var.get_orig_lead_lag() == orig_lead_lag)
return aux_vars[i].get_symb_id(); return aux_var.get_symb_id();
throw SearchFailedException(orig_symb_id, orig_lead_lag); throw SearchFailedException(orig_symb_id, orig_lead_lag);
} }
int int
SymbolTable::getOrigSymbIdForAuxVar(int aux_var_symb_id) const throw (UnknownSymbolIDException) SymbolTable::getOrigSymbIdForAuxVar(int aux_var_symb_id) const throw (UnknownSymbolIDException)
{ {
for (size_t i = 0; i < aux_vars.size(); i++) for (const auto & aux_var : aux_vars)
if ((aux_vars[i].get_type() == avEndoLag || aux_vars[i].get_type() == avExoLag || aux_vars[i].get_type() == avDiff) if ((aux_var.get_type() == avEndoLag || aux_var.get_type() == avExoLag || aux_var.get_type() == avDiff)
&& aux_vars[i].get_symb_id() == aux_var_symb_id) && aux_var.get_symb_id() == aux_var_symb_id)
return aux_vars[i].get_orig_symb_id(); return aux_var.get_orig_symb_id();
throw UnknownSymbolIDException(aux_var_symb_id); throw UnknownSymbolIDException(aux_var_symb_id);
} }
@ -874,10 +865,10 @@ expr_t
SymbolTable::getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedException) SymbolTable::getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedException)
// throw exception if it is a Lagrange multiplier // throw exception if it is a Lagrange multiplier
{ {
for (size_t i = 0; i < aux_vars.size(); i++) for (const auto & aux_var : aux_vars)
if (aux_vars[i].get_symb_id() == symb_id) if (aux_var.get_symb_id() == symb_id)
{ {
expr_t expr_node = aux_vars[i].get_expr_node(); expr_t expr_node = aux_var.get_expr_node();
if (expr_node != NULL) if (expr_node != NULL)
return expr_node; return expr_node;
else else
@ -972,10 +963,9 @@ vector <int>
SymbolTable::getTrendVarIds() const SymbolTable::getTrendVarIds() const
{ {
vector <int> trendVars; vector <int> trendVars;
for (symbol_table_type::const_iterator it = symbol_table.begin(); for (const auto & it : symbol_table)
it != symbol_table.end(); it++) if (getType(it.second) == eTrend || getType(it.second) == eLogTrend)
if (getType(it->second) == eTrend || getType(it->second) == eLogTrend) trendVars.push_back(it.second);
trendVars.push_back(it->second);
return trendVars; return trendVars;
} }
@ -983,10 +973,9 @@ set<int>
SymbolTable::getExogenous() const SymbolTable::getExogenous() const
{ {
set <int> exogs; set <int> exogs;
for (symbol_table_type::const_iterator it = symbol_table.begin(); for (const auto & it : symbol_table)
it != symbol_table.end(); it++) if (getType(it.second) == eExogenous)
if (getType(it->second) == eExogenous) exogs.insert(it.second);
exogs.insert(it->second);
return exogs; return exogs;
} }
@ -994,11 +983,10 @@ set<int>
SymbolTable::getObservedExogenous() const SymbolTable::getObservedExogenous() const
{ {
set <int> oexogs; set <int> oexogs;
for (symbol_table_type::const_iterator it = symbol_table.begin(); for (const auto & it : symbol_table)
it != symbol_table.end(); it++) if (getType(it.second) == eExogenous)
if (getType(it->second) == eExogenous) if (isObservedExogenousVariable(it.second))
if (isObservedExogenousVariable(it->second)) oexogs.insert(it.second);
oexogs.insert(it->second);
return oexogs; return oexogs;
} }
@ -1006,18 +994,17 @@ set<int>
SymbolTable::getEndogenous() const SymbolTable::getEndogenous() const
{ {
set <int> endogs; set <int> endogs;
for (symbol_table_type::const_iterator it = symbol_table.begin(); for (const auto & it : symbol_table)
it != symbol_table.end(); it++) if (getType(it.second) == eEndogenous)
if (getType(it->second) == eEndogenous) endogs.insert(it.second);
endogs.insert(it->second);
return endogs; return endogs;
} }
bool bool
SymbolTable::isAuxiliaryVariable(int symb_id) const SymbolTable::isAuxiliaryVariable(int symb_id) const
{ {
for (int i = 0; i < (int) aux_vars.size(); i++) for (const auto & aux_var : aux_vars)
if (aux_vars[i].get_symb_id() == symb_id) if (aux_var.get_symb_id() == symb_id)
return true; return true;
return false; return false;
} }
@ -1025,8 +1012,8 @@ SymbolTable::isAuxiliaryVariable(int symb_id) const
bool bool
SymbolTable::isAuxiliaryVariableButNotMultiplier(int symb_id) const SymbolTable::isAuxiliaryVariableButNotMultiplier(int symb_id) const
{ {
for (int i = 0; i < (int) aux_vars.size(); i++) for (const auto & aux_var : aux_vars)
if (aux_vars[i].get_symb_id() == symb_id && aux_vars[i].get_type() != avMultiplier) if (aux_var.get_symb_id() == symb_id && aux_var.get_type() != avMultiplier)
return true; return true;
return false; return false;
} }
@ -1035,10 +1022,9 @@ set<int>
SymbolTable::getOrigEndogenous() const SymbolTable::getOrigEndogenous() const
{ {
set <int> origendogs; set <int> origendogs;
for (symbol_table_type::const_iterator it = symbol_table.begin(); for (const auto & it : symbol_table)
it != symbol_table.end(); it++) if (getType(it.second) == eEndogenous && !isAuxiliaryVariable(it.second))
if (getType(it->second) == eEndogenous && !isAuxiliaryVariable(it->second)) origendogs.insert(it.second);
origendogs.insert(it->second);
return origendogs; return origendogs;
} }
@ -1101,12 +1087,12 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
{ {
output << "# Auxiliary Variables" << endl output << "# Auxiliary Variables" << endl
<< "model_.aux_vars = [" << endl; << "model_.aux_vars = [" << endl;
for (int i = 0; i < (int) aux_vars.size(); i++) for (const auto & aux_var : aux_vars)
{ {
output << " DynareModel.AuxVars(" output << " DynareModel.AuxVars("
<< getTypeSpecificID(aux_vars[i].get_symb_id()) + 1 << ", " << getTypeSpecificID(aux_var.get_symb_id()) + 1 << ", "
<< aux_vars[i].get_type() << ", "; << aux_var.get_type() << ", ";
switch (aux_vars[i].get_type()) switch (aux_var.get_type())
{ {
case avEndoLead: case avEndoLead:
case avExoLead: case avExoLead:
@ -1114,27 +1100,27 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
case avExoLag: case avExoLag:
case avVarModel: case avVarModel:
case avUnaryOp: case avUnaryOp:
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", " output << getTypeSpecificID(aux_var.get_orig_symb_id()) + 1 << ", "
<< aux_vars[i].get_orig_lead_lag() << ", typemin(Int), string()"; << aux_var.get_orig_lead_lag() << ", typemin(Int), string()";
break; break;
case avDiff: case avDiff:
case avDiffLag: case avDiffLag:
if (aux_vars[i].get_orig_symb_id() >= 0) if (aux_var.get_orig_symb_id() >= 0)
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", " output << getTypeSpecificID(aux_var.get_orig_symb_id()) + 1 << ", "
<< aux_vars[i].get_orig_lead_lag() << ", typemin(Int), string()"; << aux_var.get_orig_lead_lag() << ", typemin(Int), string()";
break; break;
case avMultiplier: case avMultiplier:
output << "typemin(Int), typemin(Int), " << aux_vars[i].get_equation_number_for_multiplier() + 1 output << "typemin(Int), typemin(Int), " << aux_var.get_equation_number_for_multiplier() + 1
<< ", string()"; << ", string()";
break; break;
case avDiffForward: case avDiffForward:
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ", typemin(Int), typemin(Int), string()"; output << getTypeSpecificID(aux_var.get_orig_symb_id())+1 << ", typemin(Int), typemin(Int), string()";
break; break;
case avExpectation: case avExpectation:
output << "typemin(Int), typemin(Int), typemin(Int), \"\\mathbb{E}_{t" output << "typemin(Int), typemin(Int), typemin(Int), \"\\mathbb{E}_{t"
<< (aux_vars[i].get_information_set() < 0 ? "" : "+") << (aux_var.get_information_set() < 0 ? "" : "+")
<< aux_vars[i].get_information_set() << "}("; << aux_var.get_information_set() << "}(";
aux_vars[i].get_expr_node()->writeOutput(output, oLatexDynamicModel); aux_var.get_expr_node()->writeOutput(output, oLatexDynamicModel);
output << ")\""; output << ")\"";
break; break;
default: default:
@ -1149,10 +1135,9 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
{ {
output << "# Predetermined Variables" << endl output << "# Predetermined Variables" << endl
<< "model_.pred_vars = [ " << endl; << "model_.pred_vars = [ " << endl;
for (set<int>::const_iterator it = predetermined_variables.begin(); for (int predetermined_variable : predetermined_variables)
it != predetermined_variables.end(); it++)
output << " DynareModel.PredVars(" output << " DynareModel.PredVars("
<< getTypeSpecificID(*it)+1 << ")" << endl; << getTypeSpecificID(predetermined_variable)+1 << ")" << endl;
output << " ]" << endl; output << " ]" << endl;
} }
@ -1160,10 +1145,9 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
{ {
output << "# Observed Variables" << endl output << "# Observed Variables" << endl
<< "options_.obs_vars = [" << endl; << "options_.obs_vars = [" << endl;
for (vector<int>::const_iterator it = varobs.begin(); for (int varob : varobs)
it != varobs.end(); it++)
output << " DynareModel.ObsVars(" output << " DynareModel.ObsVars("
<< getTypeSpecificID(*it)+1 << ")" << endl; << getTypeSpecificID(varob)+1 << ")" << endl;
output << " ]" << endl; output << " ]" << endl;
} }
} }

View File

@ -31,9 +31,8 @@ MacroDriver::MacroDriver()
MacroDriver::~MacroDriver() MacroDriver::~MacroDriver()
{ {
for (set<const MacroValue *>::iterator it = values.begin(); for (auto value : values)
it != values.end(); it++) delete value;
delete *it;
} }
void void
@ -51,20 +50,19 @@ MacroDriver::parse(const string &f, const string &fb, const string &modfiletxt,
an @#endif or an @#endfor - but no newline - no longer trigger an error. an @#endif or an @#endfor - but no newline - no longer trigger an error.
*/ */
stringstream file_with_endl; stringstream file_with_endl;
for (map<string, string>::iterator it = defines.begin(); for (auto & define : defines)
it != defines.end(); it++)
try try
{ {
boost::lexical_cast<int>(it->second); boost::lexical_cast<int>(define.second);
file_with_endl << "@#define " << it->first << " = " << it->second << endl; file_with_endl << "@#define " << define.first << " = " << define.second << endl;
} }
catch (boost::bad_lexical_cast &) catch (boost::bad_lexical_cast &)
{ {
if (!it->second.empty() && it->second.at(0) == '[' && it->second.at(it->second.length()-1) == ']') if (!define.second.empty() && define.second.at(0) == '[' && define.second.at(define.second.length()-1) == ']')
// If the input is an array. Issue #1578 // If the input is an array. Issue #1578
file_with_endl << "@#define " << it->first << " = " << it->second << endl; file_with_endl << "@#define " << define.first << " = " << define.second << endl;
else else
file_with_endl << "@#define " << it->first << " = \"" << it->second << "\"" << endl; file_with_endl << "@#define " << define.first << " = \"" << define.second << "\"" << endl;
} }
file_with_endl << modfiletxt << endl; file_with_endl << modfiletxt << endl;
@ -220,9 +218,8 @@ MacroDriver::printvars(const Macro::parser::location_type &l, const bool tostdou
{ {
cout << "Macroprocessor: Printing macro variable values from " << file cout << "Macroprocessor: Printing macro variable values from " << file
<< " at line " << l.begin.line << endl; << " at line " << l.begin.line << endl;
for (map<string, const MacroValue *>::const_iterator it = env.begin(); for (const auto & it : env)
it != env.end(); it++) cout << " " << it.first << " = " << it.second->print() << endl;
cout << " " << it->first << " = " << it->second->print() << endl;
cout << endl; cout << endl;
return ""; return "";
} }
@ -231,8 +228,7 @@ MacroDriver::printvars(const Macro::parser::location_type &l, const bool tostdou
if (!no_line_macro) if (!no_line_macro)
intomfile << "@#line \"" << file << "\" " << l.begin.line << endl; intomfile << "@#line \"" << file << "\" " << l.begin.line << endl;
for (map<string, const MacroValue *>::const_iterator it = env.begin(); for (const auto & it : env)
it != env.end(); it++) intomfile<< "options_.macrovars_line_" << l.begin.line << "." << it.first << " = " << it.second->print() << ";" << endl;
intomfile<< "options_.macrovars_line_" << l.begin.line << "." << it->first << " = " << it->second->print() << ";" << endl;
return intomfile.str(); return intomfile.str();
} }

View File

@ -314,9 +314,8 @@ IntMV::in(const MacroValue *array) const throw (TypeError)
throw TypeError("Type mismatch for 'in' operator"); throw TypeError("Type mismatch for 'in' operator");
int result = 0; int result = 0;
for (vector<int>::const_iterator it = array2->values.begin(); for (int v : array2->values)
it != array2->values.end(); it++) if (v == value)
if (*it == value)
{ {
result = 1; result = 1;
break; break;
@ -387,12 +386,11 @@ StringMV::operator[](const MacroValue &mv) const throw (TypeError, OutOfBoundsEr
if (mv2 == NULL) if (mv2 == NULL)
throw TypeError("Expression inside [] must be an integer array"); throw TypeError("Expression inside [] must be an integer array");
string result; string result;
for (vector<int>::const_iterator it = mv2->values.begin(); for (int v : mv2->values)
it != mv2->values.end(); it++)
{ {
if (*it < 1 || *it > (int) value.length()) if (v < 1 || v > (int) value.length())
throw OutOfBoundsError(); throw OutOfBoundsError();
char c = value.at(*it - 1); char c = value.at(v - 1);
result.append(1, c); result.append(1, c);
} }
return new StringMV(driver, result); return new StringMV(driver, result);
@ -438,9 +436,8 @@ StringMV::in(const MacroValue *array) const throw (TypeError)
throw TypeError("Type mismatch for 'in' operator"); throw TypeError("Type mismatch for 'in' operator");
int result = 0; int result = 0;
for (vector<string>::const_iterator it = array2->values.begin(); for (const auto &v : array2->values)
it != array2->values.end(); it++) if (v == value)
if (*it == value)
{ {
result = 1; result = 1;
break; break;

View File

@ -316,12 +316,11 @@ ArrayMV<T>::operator[](const MacroValue &mv) const throw (TypeError, OutOfBounds
if (mv2 == NULL) if (mv2 == NULL)
throw TypeError("Expression inside [] must be an integer array"); throw TypeError("Expression inside [] must be an integer array");
vector<T> result; vector<T> result;
for (vector<int>::const_iterator it = mv2->values.begin(); for (int value : mv2->values)
it != mv2->values.end(); it++)
{ {
if (*it < 1 || *it > (int) values.size()) if (value < 1 || value > (int) values.size())
throw OutOfBoundsError(); throw OutOfBoundsError();
result.push_back(values[*it - 1]); result.push_back(values[value - 1]);
} }
if (result.size() > 1 || result.size() == 0) if (result.size() > 1 || result.size() == 0)