v4 preprocessor: rewrote ExprNode::collectEndogenous()

git-svn-id: https://www.dynare.org/svn/dynare/dynare_v4@1778 ac1d8469-bf42-47a9-8791-bf33cf982152
issue#70
sebastien 2008-04-03 14:47:39 +00:00
parent ed15887221
commit 924e340624
3 changed files with 34 additions and 47 deletions

View File

@ -73,18 +73,6 @@ ExprNode::cost(const temporary_terms_type &temporary_terms, bool is_matlab) cons
return 0;
}
int
ExprNode::present_endogenous_size() const
{
return(present_endogenous.size());
}
int
ExprNode::present_endogenous_find(int var, int lag) const
{
return(present_endogenous.find(make_pair(var,lag))!=present_endogenous.end());
}
void
ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
@ -172,7 +160,7 @@ NumConstNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
void
NumConstNode::collectEndogenous(NodeID &Id)
NumConstNode::collectEndogenous(set<pair<int, int> > &result) const
{
}
@ -479,10 +467,10 @@ VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType ou
}
void
VariableNode::collectEndogenous(NodeID &Id)
VariableNode::collectEndogenous(set<pair<int, int> > &result) const
{
if (type == eEndogenous)
Id->present_endogenous.insert(make_pair(symb_id, lag));
result.insert(make_pair(symb_id, lag));
}
UnaryOpNode::UnaryOpNode(DataTree &datatree_arg, UnaryOpcode op_code_arg, const NodeID arg_arg) :
@ -871,9 +859,9 @@ UnaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType out
}
void
UnaryOpNode::collectEndogenous(NodeID &Id)
UnaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
{
arg->collectEndogenous(Id);
arg->collectEndogenous(result);
}
BinaryOpNode::BinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
@ -1328,10 +1316,10 @@ BinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
}
void
BinaryOpNode::collectEndogenous(NodeID &Id)
BinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
{
arg1->collectEndogenous(Id);
arg2->collectEndogenous(Id);
arg1->collectEndogenous(result);
arg2->collectEndogenous(result);
}
TrinaryOpNode::TrinaryOpNode(DataTree &datatree_arg, const NodeID arg1_arg,
@ -1595,11 +1583,11 @@ TrinaryOpNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
}
void
TrinaryOpNode::collectEndogenous(NodeID &Id)
TrinaryOpNode::collectEndogenous(set<pair<int, int> > &result) const
{
arg1->collectEndogenous(Id);
arg2->collectEndogenous(Id);
arg3->collectEndogenous(Id);
arg1->collectEndogenous(result);
arg2->collectEndogenous(result);
arg3->collectEndogenous(result);
}
UnknownFunctionNode::UnknownFunctionNode(DataTree &datatree_arg,
@ -1655,10 +1643,11 @@ UnknownFunctionNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
}
void
UnknownFunctionNode::collectEndogenous(NodeID &Id)
UnknownFunctionNode::collectEndogenous(set<pair<int, int> > &result) const
{
cerr << "UnknownFunctionNode::collectEndogenous: not implemented" << endl;
exit(-1);
for(vector<NodeID>::const_iterator it = arguments.begin();
it != arguments.end(); it++)
(*it)->collectEndogenous(result);
}
double

View File

@ -3647,12 +3647,13 @@ ModelTree::BlockLinear(Model_Block *ModelBlock)
if (it!= first_derivatives.end())
{
NodeID Id = it->second;
Id->collectEndogenous(Id);
if (Id->present_endogenous_size()>0)
set<pair<int, int> > endogenous;
Id->collectEndogenous(endogenous);
if (endogenous.size() > 0)
{
for(l=0;l<ModelBlock->Block_List[j].Size;l++)
{
if (Id->present_endogenous_find(ModelBlock->Block_List[j].Variable[l],0))
if (endogenous.find(make_pair(ModelBlock->Block_List[j].Variable[l], 0)) != endogenous.end())
{
ModelBlock->Block_List[j].is_linear=false;
goto follow;
@ -3675,12 +3676,13 @@ ModelTree::BlockLinear(Model_Block *ModelBlock)
NodeID Id = it->second;
if (it!= first_derivatives.end())
{
Id->collectEndogenous(Id);
if (Id->present_endogenous_size()>0)
set<pair<int, int> > endogenous;
Id->collectEndogenous(endogenous);
if (endogenous.size() > 0)
{
for(l=0;l<ModelBlock->Block_List[j].Size;l++)
{
if (Id->present_endogenous_find(ModelBlock->Block_List[j].Variable[l],k1))
if (endogenous.find(make_pair(ModelBlock->Block_List[j].Variable[l], k1)) != endogenous.end())
{
ModelBlock->Block_List[j].is_linear=false;
goto follow;

View File

@ -116,10 +116,6 @@ protected:
/*! Nodes included in temporary_terms are considered having a null cost */
virtual int cost(const temporary_terms_type &temporary_terms, bool is_matlab) const;
//! set of endogenous variables in the current expression
//! <symbolID, lag>
set< pair<int,int> > present_endogenous;
public:
ExprNode(DataTree &datatree_arg);
virtual ~ExprNode();
@ -143,16 +139,16 @@ public:
//! Writes output of node (with no temporary terms and with "outside model" output type)
void writeOutput(ostream &output);
//! Collects the Endogenous in a expression
virtual void collectEndogenous(NodeID &Id) = 0;
//! Computes the set of endogenous variables in the expression
/*! Endogenous are stored as integer pairs of the form (symb_id, lag)
They are added to the set given in argument */
virtual void collectEndogenous(set<pair<int, int> > &result) const = 0;
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,
map<NodeID, int> &first_occurence,
int Curr_block,
Model_Block *ModelBlock,
map_idx_type &map_idx) const;
int present_endogenous_size() const;
int present_endogenous_find(int var, int lag) const;
class EvalException
{
@ -182,7 +178,7 @@ private:
public:
NumConstNode(DataTree &datatree_arg, int id_arg);
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const;
virtual void collectEndogenous(NodeID &Id);
virtual void collectEndogenous(set<pair<int, int> > &result) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
};
@ -201,7 +197,7 @@ private:
public:
VariableNode(DataTree &datatree_arg, int symb_id_arg, Type type_arg, int lag_arg);
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms = temporary_terms_type()) const;
virtual void collectEndogenous(NodeID &Id);
virtual void collectEndogenous(set<pair<int, int> > &result) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
};
@ -226,7 +222,7 @@ public:
int Curr_block,
Model_Block *ModelBlock,
map_idx_type &map_idx) const;
virtual void collectEndogenous(NodeID &Id);
virtual void collectEndogenous(set<pair<int, int> > &result) const;
static double eval_opcode(UnaryOpcode op_code, double v) throw (EvalException);
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
@ -253,7 +249,7 @@ public:
int Curr_block,
Model_Block *ModelBlock,
map_idx_type &map_idx) const;
virtual void collectEndogenous(NodeID &Id);
virtual void collectEndogenous(set<pair<int, int> > &result) const;
static double eval_opcode(double v1, BinaryOpcode op_code, double v2) throw (EvalException);
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
@ -285,7 +281,7 @@ public:
int Curr_block,
Model_Block *ModelBlock,
map_idx_type &map_idx) const;
virtual void collectEndogenous(NodeID &Id);
virtual void collectEndogenous(set<pair<int, int> > &result) const;
static double eval_opcode(double v1, TrinaryOpcode op_code, double v2, double v3) throw (EvalException);
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
@ -310,7 +306,7 @@ public:
int Curr_block,
Model_Block *ModelBlock,
map_idx_type &map_idx) const;
virtual void collectEndogenous(NodeID &Id);
virtual void collectEndogenous(set<pair<int, int> > &result) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms, map_idx_type map_idx) const;
};