Commit bb4b5993 authored by Sébastien Villemot's avatar Sébastien Villemot
Browse files

Simplify code for model local variables

parent 164a6f30
......@@ -420,11 +420,6 @@ NumConstNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> >
{
}
void
NumConstNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
}
pair<int, expr_t >
NumConstNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
{
......@@ -1193,16 +1188,6 @@ VariableNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> >
datatree.local_variables_table[symb_id]->collectDynamicVariables(type_arg, result);
}
void
VariableNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
if (type == eModelLocalVariable)
{
result[symb_id] = const_cast<VariableNode *>(this);
datatree.local_variables_table[symb_id]->collectModelLocalVariables(result);
}
}
pair<int, expr_t>
VariableNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
{
......@@ -2736,12 +2721,6 @@ UnaryOpNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &
arg->collectDynamicVariables(type_arg, result);
}
void
UnaryOpNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
arg->collectModelLocalVariables(result);
}
pair<int, expr_t>
UnaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
{
......@@ -4404,13 +4383,6 @@ BinaryOpNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> >
arg2->collectDynamicVariables(type_arg, result);
}
void
BinaryOpNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
arg1->collectModelLocalVariables(result);
arg2->collectModelLocalVariables(result);
}
expr_t
BinaryOpNode::Compute_RHS(expr_t arg1, expr_t arg2, int op, int op_type) const
{
......@@ -5660,14 +5632,6 @@ TrinaryOpNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, int> >
arg3->collectDynamicVariables(type_arg, result);
}
void
TrinaryOpNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
arg1->collectModelLocalVariables(result);
arg2->collectModelLocalVariables(result);
arg3->collectModelLocalVariables(result);
}
pair<int, expr_t>
TrinaryOpNode::normalizeEquation(int var_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const
{
......@@ -6121,14 +6085,6 @@ AbstractExternalFunctionNode::collectDynamicVariables(SymbolType type_arg, set<p
(*it)->collectDynamicVariables(type_arg, result);
}
void
AbstractExternalFunctionNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
for (vector<expr_t>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
(*it)->collectModelLocalVariables(result);
}
void
AbstractExternalFunctionNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const
{
......@@ -7887,11 +7843,6 @@ VarExpectationNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, i
{
}
void
VarExpectationNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
}
void
VarExpectationNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const
{
......@@ -8329,11 +8280,6 @@ PacExpectationNode::collectDynamicVariables(SymbolType type_arg, set<pair<int, i
{
}
void
PacExpectationNode::collectModelLocalVariables(map<int, expr_t> &result) const
{
}
void
PacExpectationNode::collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const
{
......
......@@ -269,9 +269,6 @@ class ExprNode
*/
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const = 0;
//! Used in the collection of Model Local Variables for writing as Temporary Terms in Static and Dynamic files
virtual void collectModelLocalVariables(map<int, expr_t> &result) const = 0;
//! Find lowest lag for VAR
virtual int VarMinLag() const = 0;
......@@ -568,7 +565,6 @@ public:
virtual bool containsExternalFunction() const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
virtual 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, deriv_node_temp_terms_t &tef_terms) const;
......@@ -637,7 +633,6 @@ public:
virtual bool containsExternalFunction() const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual void computeTemporaryTerms(map<expr_t, int > &reference_count,
temporary_terms_t &temporary_terms,
map<expr_t, pair<int, int> > &first_occurence,
......@@ -756,7 +751,6 @@ public:
int equation) const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException, EvalExternalFunctionException);
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
......@@ -871,7 +865,6 @@ public:
int equation) const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
static double eval_opcode(double v1, BinaryOpcode op_code, double v2, int derivOrder) throw (EvalException, EvalExternalFunctionException);
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
......@@ -1005,7 +998,6 @@ public:
int equation) const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException, EvalExternalFunctionException);
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
......@@ -1109,7 +1101,6 @@ public:
int equation) const = 0;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
virtual double eval(const eval_context_t &eval_context) const throw (EvalException, EvalExternalFunctionException);
unsigned int compileExternalFunctionArguments(ostream &CompileCode, unsigned int &instruction_number,
......@@ -1350,7 +1341,6 @@ public:
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual bool containsEndogenous(void) const;
virtual bool containsExogenous() const;
virtual bool isDiffPresent(void) const;
......@@ -1435,7 +1425,6 @@ public:
virtual void collectTemporary_terms(const temporary_terms_t &temporary_terms, temporary_terms_inuse_t &temporary_terms_inuse, int Curr_Block) const;
virtual void collectVARLHSVariable(set<expr_t> &result) const;
virtual void collectDynamicVariables(SymbolType type_arg, set<pair<int, int> > &result) const;
virtual void collectModelLocalVariables(map<int, expr_t> &result) const;
virtual bool containsEndogenous(void) const;
virtual bool containsExogenous() const;
virtual bool isDiffPresent(void) const;
......
......@@ -1128,15 +1128,16 @@ ModelTree::computeTemporaryTerms(bool is_matlab)
// Collect all model local variables appearing in equations. See #101
// All used model local variables are automatically set as temporary variables
map<int, expr_t> used_local_vars;
set<int> used_local_vars;
for (size_t i = 0; i < equations.size(); i++)
equations[i]->collectModelLocalVariables(used_local_vars);
equations[i]->collectVariables(eModelLocalVariable, used_local_vars);
for (map<int, expr_t>::const_iterator it = used_local_vars.begin();
for (set<int>::const_iterator it = used_local_vars.begin();
it != used_local_vars.end(); it++)
{
temporary_terms_mlv[it->second] = local_variables_table.find(it->first)->second;
reference_count[it->second] = make_pair(MIN_COST(is_matlab)+1, eResiduals);
VariableNode *v = AddVariable(*it);
temporary_terms_mlv[v] = local_variables_table.find(*it)->second;
reference_count[v] = make_pair(MIN_COST(is_matlab)+1, eResiduals);
}
map<NodeTreeReference, temporary_terms_t> temp_terms_map;
......
Supports Markdown
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