Commit a08ce3de authored by Sébastien Villemot's avatar Sébastien Villemot

Yet more simplifactions using std::tuple

parent 571b5d08
......@@ -109,7 +109,7 @@ ConfigFile::getConfigFileInfo(const string &config_file)
string defaultConfigFile;
// Test OS and try to open default file
#if defined(_WIN32) || defined(__CYGWIN32__)
if (getenv("APPDATA") == NULL)
if (getenv("APPDATA") == nullptr)
{
if (parallel || parallel_test)
cerr << "ERROR: ";
......
This diff is collapsed.
......@@ -386,7 +386,7 @@ class ExprNode
// virtual void computeXrefs(set<int> &param, set<int> &endo, set<int> &exo, set<int> &exo_det) const = 0;
virtual void computeXrefs(EquationInfo &ei) const = 0;
//! Try to normalize an equation linear in its endogenous variable
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const = 0;
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const = 0;
//! Returns the maximum lead of endogenous in this expression
/*! Always returns a non-negative value */
......@@ -675,7 +675,7 @@ public:
void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const deriv_node_temp_terms_t &tef_terms) const override;
expr_t toStatic(DataTree &static_datatree) const override;
void computeXrefs(EquationInfo &ei) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) override;
int maxEndoLead() const override;
int maxExoLead() const override;
......@@ -763,7 +763,7 @@ public:
expr_t toStatic(DataTree &static_datatree) const override;
void computeXrefs(EquationInfo &ei) const override;
SymbolType get_type() const;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) override;
int maxEndoLead() const override;
int maxExoLead() const override;
......@@ -876,7 +876,7 @@ public:
void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const deriv_node_temp_terms_t &tef_terms) const override;
expr_t toStatic(DataTree &static_datatree) const override;
void computeXrefs(EquationInfo &ei) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) override;
int maxEndoLead() const override;
int maxExoLead() const override;
......@@ -998,7 +998,7 @@ public:
void getPacLHS(pair<int, int> &lhs);
expr_t toStatic(DataTree &static_datatree) const override;
void computeXrefs(EquationInfo &ei) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) override;
int maxEndoLead() const override;
int maxExoLead() const override;
......@@ -1124,7 +1124,7 @@ public:
void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const deriv_node_temp_terms_t &tef_terms) const override;
expr_t toStatic(DataTree &static_datatree) const override;
void computeXrefs(EquationInfo &ei) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) override;
int maxEndoLead() const override;
int maxExoLead() const override;
......@@ -1249,7 +1249,7 @@ public:
void compile(ostream &CompileCode, unsigned int &instruction_number, bool lhs_rhs, const temporary_terms_t &temporary_terms, const map_idx_t &map_idx, bool dynamic, bool steady_dynamic, const deriv_node_temp_terms_t &tef_terms) const override = 0;
expr_t toStatic(DataTree &static_datatree) const override = 0;
void computeXrefs(EquationInfo &ei) const override = 0;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
expr_t getChainRuleDerivative(int deriv_id, const map<int, expr_t> &recursive_variables) override;
int maxEndoLead() const override;
int maxExoLead() const override;
......@@ -1483,7 +1483,7 @@ public:
expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const override;
expr_t substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nodes, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const override;
expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table) override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
void compile(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
......@@ -1582,7 +1582,7 @@ public:
expr_t substituteDiff(DataTree &static_datatree, diff_table_t &diff_table, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const override;
expr_t substituteUnaryOpNodes(DataTree &static_datatree, diff_table_t &nodes, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const override;
expr_t substitutePacExpectation(map<const PacExpectationNode *, const BinaryOpNode *> &subst_table) override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t>>> &List_of_Op_RHS) const override;
pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<tuple<int, expr_t, expr_t>> &List_of_Op_RHS) const override;
void compile(ostream &CompileCode, unsigned int &instruction_number,
bool lhs_rhs, const temporary_terms_t &temporary_terms,
const map_idx_t &map_idx, bool dynamic, bool steady_dynamic,
......
......@@ -684,7 +684,7 @@ ModelTree::equationTypeDetermination(const map<tuple<int, int, int>, expr_t> &fi
Equation_Simulation_Type = E_EVALUATE;
else
{
vector<pair<int, pair<expr_t, expr_t>>> List_of_Op_RHS;
vector<tuple<int, expr_t, expr_t>> List_of_Op_RHS;
res = equations[eq]->normalizeEquation(var, List_of_Op_RHS);
if (mfs == 2)
{
......
......@@ -487,15 +487,15 @@ HomotopyStatement::writeOutput(ostream &output, const string &basename, bool min
for (const auto & homotopy_value : homotopy_values)
{
const int &symb_id = homotopy_value.first;
const expr_t expression1 = homotopy_value.second.first;
const expr_t expression2 = homotopy_value.second.second;
int symb_id;
expr_t expression1, expression2;
tie(symb_id, expression1, expression2) = homotopy_value;
const SymbolType type = symbol_table.getType(symb_id);
const int tsid = symbol_table.getTypeSpecificID(symb_id) + 1;
output << "options_.homotopy_values = vertcat(options_.homotopy_values, [ " << static_cast<int>(type) << ", " << tsid << ", ";
if (expression1 != nullptr)
if (expression1)
expression1->writeOutput(output);
else
output << "NaN";
......@@ -511,18 +511,23 @@ HomotopyStatement::writeJsonOutput(ostream &output) const
output << "{\"statementName\": \"homotopy\", "
<< "\"values\": [";
for (auto it = homotopy_values.begin();
it != homotopy_values.end(); it++)
it != homotopy_values.end(); ++it)
{
if (it != homotopy_values.begin())
output << ", ";
output << "{\"name\": \"" << symbol_table.getName(it->first) << "\""
int symb_id;
expr_t expression1, expression2;
tie(symb_id, expression1, expression2) = *it;
output << "{\"name\": \"" << symbol_table.getName(symb_id) << "\""
<< ", \"initial_value\": \"";
if (it->second.first != NULL)
it->second.first->writeJsonOutput(output, {}, {});
if (expression1)
expression1->writeJsonOutput(output, {}, {});
else
output << "NaN";
output << "\", \"final_value\": \"";
it->second.second->writeJsonOutput(output, {}, {});
expression2->writeJsonOutput(output, {}, {});
output << "\"}";
}
output << "]"
......
......@@ -149,7 +149,7 @@ class HomotopyStatement : public Statement
public:
//! Stores the declarations of homotopy_setup
/*! Order matter so we use a vector. First expr_t can be NULL if no initial value given. */
using homotopy_values_t = vector<pair<int, pair<expr_t, expr_t>>>;
using homotopy_values_t = vector<tuple<int, expr_t, expr_t>>;
private:
const homotopy_values_t homotopy_values;
const SymbolTable &symbol_table;
......
......@@ -706,7 +706,7 @@ ParsingDriver::homotopy_val(const string &name, expr_t val1, expr_t val2)
&& type != SymbolType::exogenousDet)
error("homotopy_val: " + name + " should be a parameter or exogenous variable");
homotopy_values.emplace_back(symb_id, make_pair(val1, val2));
homotopy_values.emplace_back(symb_id, val1, val2);
}
void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment