Commit 479f3340 authored by sebastien's avatar sebastien
Browse files

Preprocessor: various minor changes, including

* moved some declarations from ExprNode.hh to BlockTriangular.hh to which they conceptually belong
* replaced non standard boolean operators (and, or, not) by standard ones (&&, ||, !)


git-svn-id: https://www.dynare.org/svn/dynare/trunk@2812 ac1d8469-bf42-47a9-8791-bf33cf982152
parent 1cde972d
...@@ -42,6 +42,49 @@ typedef vector<pair<EquationType, NodeID > > t_etype; ...@@ -42,6 +42,49 @@ typedef vector<pair<EquationType, NodeID > > t_etype;
//! Vector describing variables: max_lag in the block, max_lead in the block //! Vector describing variables: max_lag in the block, max_lead in the block
typedef vector<pair< int, int> > t_vtype; typedef vector<pair< int, int> > t_vtype;
typedef set<int> temporary_terms_inuse_type;
//! For one lead/lag of one block, stores mapping of information between original model and block-decomposed model
struct IM_compact
{
int size, u_init, u_finish, nb_endo, nb_other_endo, size_exo, size_other_endo;
int *u, *us, *Var, *Equ, *Var_Index, *Equ_Index, *Exogenous, *Exogenous_Index, *Equ_X, *Equ_X_Index;
int *u_other_endo, *Var_other_endo, *Equ_other_endo, *Var_Index_other_endo, *Equ_Index_other_endo;
};
//! One block of the model
struct Block
{
int Size, Sized, nb_exo, nb_exo_det, nb_other_endo, Nb_Recursives;
BlockType Type;
BlockSimulationType Simulation_Type;
int Max_Lead, Max_Lag, Nb_Lead_Lag_Endo;
int Max_Lag_Endo, Max_Lead_Endo;
int Max_Lag_Other_Endo, Max_Lead_Other_Endo;
int Max_Lag_Exo, Max_Lead_Exo;
bool is_linear;
int *Equation, *Own_Derivative;
EquationType *Equation_Type;
NodeID *Equation_Normalized;
int *Variable, *Other_Endogenous, *Exogenous;
temporary_terms_type **Temporary_Terms_in_Equation;
//temporary_terms_type *Temporary_terms;
temporary_terms_inuse_type *Temporary_InUse;
IM_compact *IM_lead_lag;
int Code_Start, Code_Length;
};
//! The set of all blocks of the model
struct Model_Block
{
int Size, Periods;
Block* Block_List;
//int *in_Block_Equ, *in_Block_Var, *in_Equ_of_Block, *in_Var_of_Block;
};
//! Creates the incidence matrix, computes prologue & epilogue, normalizes the model and computes the block decomposition //! Creates the incidence matrix, computes prologue & epilogue, normalizes the model and computes the block decomposition
class BlockTriangular class BlockTriangular
{ {
......
...@@ -17,11 +17,11 @@ ...@@ -17,11 +17,11 @@
* along with Dynare. If not, see <http://www.gnu.org/licenses/>. * along with Dynare. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include <iostream>
#include <cmath> #include <cmath>
#include <cstdlib> #include <cstdlib>
#include <cassert> #include <cassert>
#include "DynamicModel.hh" #include "DynamicModel.hh"
// For mkdir() and chdir() // For mkdir() and chdir()
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
using namespace std; using namespace std;
#include <fstream>
#include "StaticModel.hh" #include "StaticModel.hh"
#include "BlockTriangular.hh" #include "BlockTriangular.hh"
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include "ExprNode.hh" #include "ExprNode.hh"
#include "DataTree.hh" #include "DataTree.hh"
#include "BlockTriangular.hh"
ExprNode::ExprNode(DataTree &datatree_arg) : datatree(datatree_arg) ExprNode::ExprNode(DataTree &datatree_arg) : datatree(datatree_arg)
{ {
...@@ -94,13 +95,6 @@ ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count, ...@@ -94,13 +95,6 @@ ExprNode::computeTemporaryTerms(map<NodeID, int> &reference_count,
// Nothing to do for a terminal node // Nothing to do for a terminal node
} }
void
ExprNode::writeOutput(ostream &output, ExprNodeOutputType output_type,
const temporary_terms_type &temporary_terms) const
{
//writeOutput(output, oMatlabOutsideModel, temporary_terms_type());
}
void void
ExprNode::writeOutput(ostream &output) ExprNode::writeOutput(ostream &output)
...@@ -108,11 +102,6 @@ ExprNode::writeOutput(ostream &output) ...@@ -108,11 +102,6 @@ ExprNode::writeOutput(ostream &output)
writeOutput(output, oMatlabOutsideModel, temporary_terms_type()); writeOutput(output, oMatlabOutsideModel, temporary_terms_type());
} }
pair<bool, NodeID>
ExprNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) const
{
return(make_pair(true, (NodeID)NULL));
}
NumConstNode::NumConstNode(DataTree &datatree_arg, int id_arg) : NumConstNode::NumConstNode(DataTree &datatree_arg, int id_arg) :
ExprNode(datatree_arg), ExprNode(datatree_arg),
...@@ -160,7 +149,7 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep ...@@ -160,7 +149,7 @@ NumConstNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
} }
void void
NumConstNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const NumConstNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
{ {
CompileCode.write(&FLDC, sizeof(FLDC)); CompileCode.write(&FLDC, sizeof(FLDC));
double vard = datatree.num_constants.getDouble(id); double vard = datatree.num_constants.getDouble(id);
...@@ -448,7 +437,7 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep ...@@ -448,7 +437,7 @@ VariableNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
} }
void void
VariableNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const VariableNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
{ {
int i, lagl; int i, lagl;
#ifdef DEBUGC #ifdef DEBUGC
...@@ -543,7 +532,7 @@ VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con ...@@ -543,7 +532,7 @@ VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con
{ {
if (type ==eEndogenous) if (type ==eEndogenous)
{ {
if (datatree.symbol_table.getTypeSpecificID(symb_id)==var_endo and lag==0) if (datatree.symbol_table.getTypeSpecificID(symb_id)==var_endo && lag==0)
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
else else
return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag))); return(make_pair(false, datatree.AddVariableInternal(datatree.symbol_table.getName(symb_id), lag)));
...@@ -557,19 +546,6 @@ VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con ...@@ -557,19 +546,6 @@ VariableNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con
} }
} }
template<class InputIterator, class T>
pair<InputIterator, int> find_r ( InputIterator first, InputIterator last, const T& value )
{
int i=0;
for (; first!=last; first++)
{
if ( *first==value ) break;
i++;
}
return make_pair(first, i);
}
NodeID NodeID
VariableNode::getChainRuleDerivative(int deriv_id_arg, const map<int, NodeID> &recursive_variables) VariableNode::getChainRuleDerivative(int deriv_id_arg, const map<int, NodeID> &recursive_variables)
{ {
...@@ -1003,7 +979,7 @@ UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcept ...@@ -1003,7 +979,7 @@ UnaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcept
} }
void void
UnaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const UnaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
{ {
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this)); temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<UnaryOpNode *>(this));
if (it != temporary_terms.end()) if (it != temporary_terms.end())
...@@ -1037,7 +1013,7 @@ UnaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) cons ...@@ -1037,7 +1013,7 @@ UnaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) cons
pair<bool, NodeID> res = arg->normalizeLinearInEndoEquation(var_endo, Derivative); pair<bool, NodeID> res = arg->normalizeLinearInEndoEquation(var_endo, Derivative);
bool is_endogenous_present = res.first; bool is_endogenous_present = res.first;
NodeID New_NodeID = res.second; NodeID New_NodeID = res.second;
if (not is_endogenous_present) if (!is_endogenous_present)
{ {
switch (op_code) switch (op_code)
{ {
...@@ -1447,7 +1423,7 @@ BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcep ...@@ -1447,7 +1423,7 @@ BinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExcep
} }
void void
BinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const BinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
{ {
// If current node is a temporary term // If current node is a temporary term
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this)); temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<BinaryOpNode *>(this));
...@@ -1667,63 +1643,63 @@ BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con ...@@ -1667,63 +1643,63 @@ BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con
switch (op_code) switch (op_code)
{ {
case oPlus: case oPlus:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddPlus(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddPlus(NodeID_1, NodeID_2)));
else if (is_endogenous_present_1 and is_endogenous_present_2) else if (is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
else if (not is_endogenous_present_1 and is_endogenous_present_2) else if (!is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(false, NodeID_1)); return(make_pair(false, NodeID_1));
else if (is_endogenous_present_1 and not is_endogenous_present_2) else if (is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, NodeID_2)); return(make_pair(false, NodeID_2));
break; break;
case oMinus: case oMinus:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddMinus(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddMinus(NodeID_1, NodeID_2)));
else if (is_endogenous_present_1 and is_endogenous_present_2) else if (is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
else if (not is_endogenous_present_1 and is_endogenous_present_2) else if (!is_endogenous_present_1 && is_endogenous_present_2)
return(make_pair(false, NodeID_1)); return(make_pair(false, NodeID_1));
else if (is_endogenous_present_1 and not is_endogenous_present_2) else if (is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddUMinus(NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddUMinus(NodeID_2)));
break; break;
case oTimes: case oTimes:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddTimes(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddTimes(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oDivide: case oDivide:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddDivide(NodeID_1, NodeID_2))); return(make_pair(false, datatree.AddDivide(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oPower: case oPower:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddPower(NodeID_1, NodeID_2))); return(make_pair(false, datatree.AddPower(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oEqual: case oEqual:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
{ {
if (Derivative!=datatree.One) if (Derivative!=datatree.One)
return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddMinus(NodeID_2, NodeID_1), Derivative))) ); return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddMinus(NodeID_2, NodeID_1), Derivative))) );
else else
return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddMinus(NodeID_2, NodeID_1))) ); return( make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddMinus(NodeID_2, NodeID_1))) );
} }
else if (is_endogenous_present_1 and is_endogenous_present_2) else if (is_endogenous_present_1 && is_endogenous_present_2)
{ {
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.Zero))); return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.Zero)));
} }
else if (not is_endogenous_present_1 and is_endogenous_present_2) else if (!is_endogenous_present_1 && is_endogenous_present_2)
{ {
if (Derivative!=datatree.One) if (Derivative!=datatree.One)
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddUMinus(NodeID_1), Derivative)))); return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(datatree.AddUMinus(NodeID_1), Derivative))));
else else
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddUMinus(NodeID_1)))); return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddUMinus(NodeID_1))));
} }
else if (is_endogenous_present_1 and not is_endogenous_present_2) else if (is_endogenous_present_1 && !is_endogenous_present_2)
{ {
if (Derivative!=datatree.One) if (Derivative!=datatree.One)
return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(NodeID_2, Derivative)))); return(make_pair(false, datatree.AddEqual(datatree.AddVariable(datatree.symbol_table.getName(datatree.symbol_table.getID(eEndogenous, var_endo)), 0), datatree.AddDivide(NodeID_2, Derivative))));
...@@ -1732,49 +1708,49 @@ BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con ...@@ -1732,49 +1708,49 @@ BinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) con
} }
break; break;
case oMax: case oMax:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddMax(NodeID_1, NodeID_2))); return(make_pair(false, datatree.AddMax(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oMin: case oMin:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, datatree.AddMin(NodeID_1, NodeID_2))); return(make_pair(false, datatree.AddMin(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oLess: case oLess:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddLess(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddLess(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oGreater: case oGreater:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddGreater(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddGreater(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oLessEqual: case oLessEqual:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddLessEqual(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddLessEqual(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oGreaterEqual: case oGreaterEqual:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddGreaterEqual(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddGreaterEqual(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oEqualEqual: case oEqualEqual:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddEqualEqual(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddEqualEqual(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
break; break;
case oDifferent: case oDifferent:
if (not is_endogenous_present_1 and not is_endogenous_present_2) if (!is_endogenous_present_1 && !is_endogenous_present_2)
return(make_pair(false, /*tmp_*/datatree.AddDifferent(NodeID_1, NodeID_2))); return(make_pair(false, /*tmp_*/datatree.AddDifferent(NodeID_1, NodeID_2)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
...@@ -2042,7 +2018,7 @@ TrinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExce ...@@ -2042,7 +2018,7 @@ TrinaryOpNode::eval(const eval_context_type &eval_context) const throw (EvalExce
} }
void void
TrinaryOpNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const TrinaryOpNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
{ {
// If current node is a temporary term // If current node is a temporary term
temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this)); temporary_terms_type::const_iterator it = temporary_terms.find(const_cast<TrinaryOpNode *>(this));
...@@ -2133,7 +2109,7 @@ TrinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) co ...@@ -2133,7 +2109,7 @@ TrinaryOpNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivative) co
res = arg3->normalizeLinearInEndoEquation(var_endo, Derivative); res = arg3->normalizeLinearInEndoEquation(var_endo, Derivative);
bool is_endogenous_present_3 = res.first; bool is_endogenous_present_3 = res.first;
NodeID NodeID_3 = res.second; NodeID NodeID_3 = res.second;
if (not is_endogenous_present_1 and not is_endogenous_present_2 and not is_endogenous_present_3) if (!is_endogenous_present_1 && !is_endogenous_present_2 && !is_endogenous_present_3)
return(make_pair(false, /*tmp_*/datatree.AddNormcdf(NodeID_1, NodeID_2, NodeID_3))); return(make_pair(false, /*tmp_*/datatree.AddNormcdf(NodeID_1, NodeID_2, NodeID_3)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
...@@ -2261,7 +2237,7 @@ UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (Ev ...@@ -2261,7 +2237,7 @@ UnknownFunctionNode::eval(const eval_context_type &eval_context) const throw (Ev
} }
void void
UnknownFunctionNode::compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const UnknownFunctionNode::compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const
{ {
cerr << "UnknownFunctionNode::compile: operation impossible!" << endl; cerr << "UnknownFunctionNode::compile: operation impossible!" << endl;
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -2277,10 +2253,10 @@ UnknownFunctionNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivati ...@@ -2277,10 +2253,10 @@ UnknownFunctionNode::normalizeLinearInEndoEquation(int var_endo, NodeID Derivati
it != arguments.end(); it++) it != arguments.end(); it++)
{ {
V_arguments.push_back((*it)->normalizeLinearInEndoEquation(var_endo, Derivative)); V_arguments.push_back((*it)->normalizeLinearInEndoEquation(var_endo, Derivative));
present = present or V_arguments[V_arguments.size()-1].first; present = present || V_arguments[V_arguments.size()-1].first;
V_NodeID.push_back(V_arguments[V_arguments.size()-1].second); V_NodeID.push_back(V_arguments[V_arguments.size()-1].second);
} }
if (not present) if (!present)
return(make_pair(false, datatree.AddUnknownFunction(datatree.symbol_table.getName(symb_id), V_NodeID))); return(make_pair(false, datatree.AddUnknownFunction(datatree.symbol_table.getName(symb_id), V_NodeID)));
else else
return(make_pair(true, (NodeID)NULL)); return(make_pair(true, (NodeID)NULL));
......
...@@ -25,8 +25,7 @@ using namespace std; ...@@ -25,8 +25,7 @@ using namespace std;
#include <set> #include <set>
#include <map> #include <map>
#include <vector> #include <vector>
#include <iostream> #include <ostream>
#include <fstream>
#include "SymbolTable.hh" #include "SymbolTable.hh"
#include "CodeInterpreter.hh" #include "CodeInterpreter.hh"
...@@ -44,7 +43,6 @@ struct ExprNodeLess; ...@@ -44,7 +43,6 @@ struct ExprNodeLess;
typedef set<NodeID, ExprNodeLess> temporary_terms_type; typedef set<NodeID, ExprNodeLess> temporary_terms_type;
typedef map<int,int> map_idx_type; typedef map<int,int> map_idx_type;
typedef set<int> temporary_terms_inuse_type;
//! Type for evaluation contexts //! Type for evaluation contexts
/*! The key is a symbol id. Lags are assumed to be null */ /*! The key is a symbol id. Lags are assumed to be null */
...@@ -152,7 +150,7 @@ public: ...@@ -152,7 +150,7 @@ public:
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const; virtual void computeTemporaryTerms(map<NodeID, int> &reference_count, temporary_terms_type &temporary_terms, bool is_matlab) const;
//! Writes output of node, using a Txxx notation for nodes in temporary_terms //! Writes output of node, using a Txxx notation for nodes in temporary_terms
virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const /*= 0*/; virtual void writeOutput(ostream &output, ExprNodeOutputType output_type, const temporary_terms_type &temporary_terms) const = 0;
//! Writes output of node (with no temporary terms and with "outside model" output type) //! Writes output of node (with no temporary terms and with "outside model" output type)
void writeOutput(ostream &output); void writeOutput(ostream &output);
...@@ -186,7 +184,7 @@ public: ...@@ -186,7 +184,7 @@ public:
}; };
virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0; virtual double eval(const eval_context_type &eval_context) const throw (EvalException) = 0;
virtual void compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const = 0; virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const = 0;
//! Creates a static version of this node //! Creates a static version of this node
/*! /*!
This method duplicates the current node by creating a similar node from which all leads/lags have been stripped, This method duplicates the current node by creating a similar node from which all leads/lags have been stripped,
...@@ -194,7 +192,7 @@ public: ...@@ -194,7 +192,7 @@ public:
*/ */
virtual NodeID toStatic(DataTree &static_datatree) const = 0; virtual NodeID toStatic(DataTree &static_datatree) const = 0;
//! Try to normalize an equation linear in its endogenous variable //! Try to normalize an equation linear in its endogenous variable
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const; virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const = 0;
}; };
//! Object used to compare two nodes (using their indexes) //! Object used to compare two nodes (using their indexes)
...@@ -221,7 +219,7 @@ public: ...@@ -221,7 +219,7 @@ public:
virtual void collectExogenous(set<pair<int, int> > &result) const; virtual void collectExogenous(set<pair<int, int> > &result) const;
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const; virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const;
virtual double eval(const eval_context_type &eval_context) const throw (EvalException); virtual double eval(const eval_context_type &eval_context) const throw (EvalException);
virtual void compile(ofstream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const; virtual void compile(ostream &CompileCode, bool lhs_rhs, const temporary_terms_type &temporary_terms, map_idx_type &map_idx) const;
virtual NodeID toStatic(DataTree &static_datatree) const; virtual NodeID toStatic(DataTree &static_datatree) const;
virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const; virtual pair<bool, NodeID> normalizeLinearInEndoEquation(int symb_id_endo, NodeID Derivative) const;
virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables); virtual NodeID getChainRuleDerivative(int deriv_id, const map<int, NodeID> &recursive_variables);
...@@ -240,7 +238,7 @@ private: ...@@ -240,7 +238,7 @@ private:
virtual NodeID computeDerivative(int deriv_id_arg); virtual NodeID computeDerivative(int deriv_id_arg);