preprocessor: pac: change functionality of diff operator
parent
42d9ad2a41
commit
77bf21a333
|
@ -4750,10 +4750,37 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::substituteAdlAndDiff()
|
DynamicModel::substituteAdl()
|
||||||
{
|
{
|
||||||
for (int i = 0; i < (int) equations.size(); i++)
|
for (int i = 0; i < (int) equations.size(); i++)
|
||||||
equations[i] = dynamic_cast<BinaryOpNode *>(equations[i]->substituteAdlAndDiff());
|
equations[i] = dynamic_cast<BinaryOpNode *>(equations[i]->substituteAdl());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
DynamicModel::substituteDiff()
|
||||||
|
{
|
||||||
|
ExprNode::subst_table_t subst_table;
|
||||||
|
vector<BinaryOpNode *> neweqs;
|
||||||
|
|
||||||
|
// Substitute in model local variables
|
||||||
|
for (map<int, expr_t>::iterator it = local_variables_table.begin();
|
||||||
|
it != local_variables_table.end(); it++)
|
||||||
|
it->second = it->second->substituteDiff(subst_table, neweqs);
|
||||||
|
|
||||||
|
// Substitute in equations
|
||||||
|
for (int i = 0; i < (int) equations.size(); i++)
|
||||||
|
{
|
||||||
|
BinaryOpNode *substeq = dynamic_cast<BinaryOpNode *>(equations[i]->substituteDiff(subst_table, neweqs));
|
||||||
|
assert(substeq != NULL);
|
||||||
|
equations[i] = substeq;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new equations
|
||||||
|
for (int i = 0; i < (int) neweqs.size(); i++)
|
||||||
|
addEquation(neweqs[i], -1);
|
||||||
|
|
||||||
|
if (subst_table.size() > 0)
|
||||||
|
cout << "Substitution of Diff operator: added " << neweqs.size() << " auxiliary variables and equations." << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
|
@ -366,8 +366,11 @@ public:
|
||||||
//! Transforms the model by removing trends specified by the user
|
//! Transforms the model by removing trends specified by the user
|
||||||
void detrendEquations();
|
void detrendEquations();
|
||||||
|
|
||||||
//! Substitutes adl and diff operators
|
//! Substitutes adl operator
|
||||||
void substituteAdlAndDiff();
|
void substituteAdl();
|
||||||
|
|
||||||
|
//! Substitutes diff operator
|
||||||
|
void substituteDiff();
|
||||||
|
|
||||||
//! Fill var_expectation_functions_to_write
|
//! Fill var_expectation_functions_to_write
|
||||||
void fillVarExpectationFunctionsToWrite();
|
void fillVarExpectationFunctionsToWrite();
|
||||||
|
|
113
ExprNode.cc
113
ExprNode.cc
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2007-2017 Dynare Team
|
* Copyright (C) 2007-2018 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -482,7 +482,13 @@ NumConstNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpN
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
NumConstNode::substituteAdlAndDiff() const
|
NumConstNode::substituteAdl() const
|
||||||
|
{
|
||||||
|
return const_cast<NumConstNode *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
NumConstNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
{
|
{
|
||||||
return const_cast<NumConstNode *>(this);
|
return const_cast<NumConstNode *>(this);
|
||||||
}
|
}
|
||||||
|
@ -1244,7 +1250,13 @@ VariableNode::maxLead() const
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
VariableNode::substituteAdlAndDiff() const
|
VariableNode::substituteAdl() const
|
||||||
|
{
|
||||||
|
return const_cast<VariableNode *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
VariableNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
{
|
{
|
||||||
return const_cast<VariableNode *>(this);
|
return const_cast<VariableNode *>(this);
|
||||||
}
|
}
|
||||||
|
@ -2709,22 +2721,15 @@ UnaryOpNode::maxLead() const
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
UnaryOpNode::substituteAdlAndDiff() const
|
UnaryOpNode::substituteAdl() const
|
||||||
{
|
{
|
||||||
if (op_code != oDiff && op_code != oAdl)
|
if (op_code != oAdl)
|
||||||
{
|
{
|
||||||
expr_t argsubst = arg->substituteAdlAndDiff();
|
expr_t argsubst = arg->substituteAdl();
|
||||||
return buildSimilarUnaryOpNode(argsubst, datatree);
|
return buildSimilarUnaryOpNode(argsubst, datatree);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (op_code == oDiff)
|
expr_t arg1subst = arg->substituteAdl();
|
||||||
{
|
|
||||||
expr_t argsubst = arg->substituteAdlAndDiff();
|
|
||||||
return datatree.AddMinus(argsubst,
|
|
||||||
argsubst->decreaseLeadsLags(1));
|
|
||||||
}
|
|
||||||
|
|
||||||
expr_t arg1subst = arg->substituteAdlAndDiff();
|
|
||||||
expr_t retval;
|
expr_t retval;
|
||||||
ostringstream inttostr;
|
ostringstream inttostr;
|
||||||
if (adl_param_lag >= 0)
|
if (adl_param_lag >= 0)
|
||||||
|
@ -2765,6 +2770,34 @@ UnaryOpNode::substituteAdlAndDiff() const
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
UnaryOpNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
|
{
|
||||||
|
if (op_code != oDiff)
|
||||||
|
{
|
||||||
|
expr_t argsubst = arg->substituteDiff(subst_table, neweqs);
|
||||||
|
return buildSimilarUnaryOpNode(argsubst, datatree);
|
||||||
|
}
|
||||||
|
|
||||||
|
subst_table_t::iterator it = subst_table.find(const_cast<UnaryOpNode *>(this));
|
||||||
|
if (it != subst_table.end())
|
||||||
|
return const_cast<VariableNode *>(it->second);
|
||||||
|
|
||||||
|
expr_t argsubst = arg->substituteDiff(subst_table, neweqs);
|
||||||
|
assert(argsubst != NULL);
|
||||||
|
|
||||||
|
int symb_id = datatree.symbol_table.addDiffAuxiliaryVar(argsubst->idx, argsubst);
|
||||||
|
expr_t newAuxVar = datatree.AddVariable(symb_id, 0);
|
||||||
|
|
||||||
|
//AUX_DIFF_IDX = argsubst - argsubst(-1)
|
||||||
|
neweqs.push_back(dynamic_cast<BinaryOpNode *>(datatree.AddEqual(newAuxVar,
|
||||||
|
datatree.AddMinus(argsubst, argsubst->decreaseLeadsLags(1)))));
|
||||||
|
|
||||||
|
assert(dynamic_cast<VariableNode *>(newAuxVar) != NULL);
|
||||||
|
subst_table[this] = dynamic_cast<VariableNode *>(newAuxVar);
|
||||||
|
return newAuxVar;
|
||||||
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
UnaryOpNode::decreaseLeadsLags(int n) const
|
UnaryOpNode::decreaseLeadsLags(int n) const
|
||||||
{
|
{
|
||||||
|
@ -4361,10 +4394,18 @@ BinaryOpNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOpN
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
BinaryOpNode::substituteAdlAndDiff() const
|
BinaryOpNode::substituteAdl() const
|
||||||
{
|
{
|
||||||
expr_t arg1subst = arg1->substituteAdlAndDiff();
|
expr_t arg1subst = arg1->substituteAdl();
|
||||||
expr_t arg2subst = arg2->substituteAdlAndDiff();
|
expr_t arg2subst = arg2->substituteAdl();
|
||||||
|
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
BinaryOpNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
|
{
|
||||||
|
expr_t arg1subst = arg1->substituteDiff(subst_table, neweqs);
|
||||||
|
expr_t arg2subst = arg2->substituteDiff(subst_table, neweqs);
|
||||||
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
|
return buildSimilarBinaryOpNode(arg1subst, arg2subst, datatree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5108,11 +5149,20 @@ TrinaryOpNode::substituteExpectation(subst_table_t &subst_table, vector<BinaryOp
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
TrinaryOpNode::substituteAdlAndDiff() const
|
TrinaryOpNode::substituteAdl() const
|
||||||
{
|
{
|
||||||
expr_t arg1subst = arg1->substituteAdlAndDiff();
|
expr_t arg1subst = arg1->substituteAdl();
|
||||||
expr_t arg2subst = arg2->substituteAdlAndDiff();
|
expr_t arg2subst = arg2->substituteAdl();
|
||||||
expr_t arg3subst = arg3->substituteAdlAndDiff();
|
expr_t arg3subst = arg3->substituteAdl();
|
||||||
|
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
TrinaryOpNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
|
{
|
||||||
|
expr_t arg1subst = arg1->substituteDiff(subst_table, neweqs);
|
||||||
|
expr_t arg2subst = arg2->substituteDiff(subst_table, neweqs);
|
||||||
|
expr_t arg3subst = arg3->substituteDiff(subst_table, neweqs);
|
||||||
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
|
return buildSimilarTrinaryOpNode(arg1subst, arg2subst, arg3subst, datatree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -5420,11 +5470,20 @@ AbstractExternalFunctionNode::substituteExpectation(subst_table_t &subst_table,
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
AbstractExternalFunctionNode::substituteAdlAndDiff() 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 (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
|
||||||
arguments_subst.push_back((*it)->substituteAdlAndDiff());
|
arguments_subst.push_back((*it)->substituteAdl());
|
||||||
|
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
AbstractExternalFunctionNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
|
{
|
||||||
|
vector<expr_t> arguments_subst;
|
||||||
|
for (vector<expr_t>::const_iterator it = arguments.begin(); it != arguments.end(); it++)
|
||||||
|
arguments_subst.push_back((*it)->substituteDiff(subst_table, neweqs));
|
||||||
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
|
return buildSimilarExternalFunctionNode(arguments_subst, datatree);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6892,7 +6951,13 @@ VarExpectationNode::substituteExpectation(subst_table_t &subst_table, vector<Bin
|
||||||
}
|
}
|
||||||
|
|
||||||
expr_t
|
expr_t
|
||||||
VarExpectationNode::substituteAdlAndDiff() const
|
VarExpectationNode::substituteAdl() const
|
||||||
|
{
|
||||||
|
return const_cast<VarExpectationNode *>(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
expr_t
|
||||||
|
VarExpectationNode::substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const
|
||||||
{
|
{
|
||||||
return const_cast<VarExpectationNode *>(this);
|
return const_cast<VarExpectationNode *>(this);
|
||||||
}
|
}
|
||||||
|
|
30
ExprNode.hh
30
ExprNode.hh
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2007-2017 Dynare Team
|
* Copyright (C) 2007-2018 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -457,8 +457,11 @@ enum ExprNodeOutputType
|
||||||
*/
|
*/
|
||||||
virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const = 0;
|
virtual expr_t detrend(int symb_id, bool log_trend, expr_t trend) const = 0;
|
||||||
|
|
||||||
//! Substitute adl and diff operators
|
//! Substitute adl operator
|
||||||
virtual expr_t substituteAdlAndDiff() const = 0;
|
virtual expr_t substituteAdl() const = 0;
|
||||||
|
|
||||||
|
//! Substitute diff operator
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const = 0;
|
||||||
|
|
||||||
//! Add ExprNodes to the provided datatree
|
//! Add ExprNodes to the provided datatree
|
||||||
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0;
|
virtual expr_t cloneDynamic(DataTree &dynamic_datatree) const = 0;
|
||||||
|
@ -530,7 +533,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
||||||
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual bool isNumConstNodeEqualTo(double value) const;
|
virtual bool isNumConstNodeEqualTo(double value) const;
|
||||||
|
@ -605,7 +609,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
||||||
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual bool isNumConstNodeEqualTo(double value) const;
|
virtual bool isNumConstNodeEqualTo(double value) const;
|
||||||
|
@ -703,7 +708,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
||||||
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual bool isNumConstNodeEqualTo(double value) const;
|
virtual bool isNumConstNodeEqualTo(double value) const;
|
||||||
|
@ -813,7 +819,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
||||||
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual bool isNumConstNodeEqualTo(double value) const;
|
virtual bool isNumConstNodeEqualTo(double value) const;
|
||||||
|
@ -903,7 +910,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
||||||
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual bool isNumConstNodeEqualTo(double value) const;
|
virtual bool isNumConstNodeEqualTo(double value) const;
|
||||||
|
@ -993,7 +1001,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const = 0;
|
virtual expr_t buildSimilarExternalFunctionNode(vector<expr_t> &alt_args, DataTree &alt_datatree) const = 0;
|
||||||
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
virtual expr_t decreaseLeadsLagsPredeterminedVariables() const;
|
||||||
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t differentiateForwardVars(const vector<string> &subset, subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
|
@ -1174,7 +1183,8 @@ public:
|
||||||
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
virtual expr_t substituteExoLead(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool deterministic_model) const;
|
||||||
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
virtual expr_t substituteExoLag(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
virtual expr_t substituteExpectation(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs, bool partial_information_model) const;
|
||||||
virtual expr_t substituteAdlAndDiff() const;
|
virtual expr_t substituteAdl() const;
|
||||||
|
virtual expr_t substituteDiff(subst_table_t &subst_table, vector<BinaryOpNode *> &neweqs) const;
|
||||||
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const;
|
virtual pair<int, expr_t> normalizeEquation(int symb_id_endo, vector<pair<int, pair<expr_t, expr_t> > > &List_of_Op_RHS) const;
|
||||||
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
virtual void compile(ostream &CompileCode, unsigned int &instruction_number,
|
||||||
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
bool lhs_rhs, const temporary_terms_t &temporary_terms,
|
||||||
|
|
|
@ -346,7 +346,7 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
|
||||||
{
|
{
|
||||||
// Save the original model (must be done before any model transformations by preprocessor)
|
// Save the original model (must be done before any model transformations by preprocessor)
|
||||||
// - except adl and diff which we always want expanded
|
// - except adl and diff which we always want expanded
|
||||||
dynamic_model.substituteAdlAndDiff();
|
dynamic_model.substituteAdl();
|
||||||
dynamic_model.setLeadsLagsOrig();
|
dynamic_model.setLeadsLagsOrig();
|
||||||
dynamic_model.cloneDynamic(original_model);
|
dynamic_model.cloneDynamic(original_model);
|
||||||
|
|
||||||
|
@ -381,6 +381,9 @@ ModFile::transformPass(bool nostrict, bool stochastic, bool compute_xrefs, const
|
||||||
if (symbol_table.predeterminedNbr() > 0)
|
if (symbol_table.predeterminedNbr() > 0)
|
||||||
dynamic_model.transformPredeterminedVariables();
|
dynamic_model.transformPredeterminedVariables();
|
||||||
|
|
||||||
|
// Create auxiliary variable and equations for Diff operator
|
||||||
|
dynamic_model.substituteDiff();
|
||||||
|
|
||||||
// Create auxiliary vars for Expectation operator
|
// Create auxiliary vars for Expectation operator
|
||||||
dynamic_model.substituteExpectation(mod_file_struct.partial_information);
|
dynamic_model.substituteExpectation(mod_file_struct.partial_information);
|
||||||
|
|
||||||
|
|
|
@ -354,6 +354,7 @@ SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
{
|
{
|
||||||
case avEndoLead:
|
case avEndoLead:
|
||||||
case avExoLead:
|
case avExoLead:
|
||||||
|
case avDiff:
|
||||||
break;
|
break;
|
||||||
case avEndoLag:
|
case avEndoLag:
|
||||||
case avExoLag:
|
case avExoLag:
|
||||||
|
@ -475,6 +476,7 @@ SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
case avExpectation:
|
case avExpectation:
|
||||||
case avMultiplier:
|
case avMultiplier:
|
||||||
case avDiffForward:
|
case avDiffForward:
|
||||||
|
case avDiff:
|
||||||
break;
|
break;
|
||||||
case avEndoLag:
|
case avEndoLag:
|
||||||
case avExoLag:
|
case avExoLag:
|
||||||
|
@ -568,6 +570,7 @@ SymbolTable::writeCCOutput(ostream &output) const throw (NotYetFrozenException)
|
||||||
case avExpectation:
|
case avExpectation:
|
||||||
case avMultiplier:
|
case avMultiplier:
|
||||||
case avDiffForward:
|
case avDiffForward:
|
||||||
|
case avDiff:
|
||||||
break;
|
break;
|
||||||
case avEndoLag:
|
case avEndoLag:
|
||||||
case avExoLag:
|
case avExoLag:
|
||||||
|
@ -691,6 +694,29 @@ SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, expr_t e
|
||||||
return symb_id;
|
return symb_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
SymbolTable::addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException)
|
||||||
|
{
|
||||||
|
ostringstream varname;
|
||||||
|
int symb_id;
|
||||||
|
|
||||||
|
varname << "AUX_DIFF_" << index;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
symb_id = addSymbol(varname.str(), eEndogenous);
|
||||||
|
}
|
||||||
|
catch (AlreadyDeclaredException &e)
|
||||||
|
{
|
||||||
|
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
|
aux_vars.push_back(AuxVarInfo(symb_id, avDiff, 0, 0, 0, 0, expr_arg));
|
||||||
|
|
||||||
|
return symb_id;
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
SymbolTable::addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException)
|
SymbolTable::addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException)
|
||||||
{
|
{
|
||||||
|
@ -1001,6 +1027,7 @@ SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenExceptio
|
||||||
{
|
{
|
||||||
case avEndoLead:
|
case avEndoLead:
|
||||||
case avExoLead:
|
case avExoLead:
|
||||||
|
case avDiff:
|
||||||
break;
|
break;
|
||||||
case avEndoLag:
|
case avEndoLag:
|
||||||
case avExoLag:
|
case avExoLag:
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2017 Dynare Team
|
* Copyright (C) 2003-2018 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -43,7 +43,8 @@ enum aux_var_t
|
||||||
avExpectation = 4, //!< Substitute for Expectation Operator
|
avExpectation = 4, //!< Substitute for Expectation Operator
|
||||||
avDiffForward = 5, //!< Substitute for the differentiate of a forward variable
|
avDiffForward = 5, //!< Substitute for the differentiate of a forward variable
|
||||||
avMultiplier = 6, //!< Multipliers for FOC of Ramsey Problem
|
avMultiplier = 6, //!< Multipliers for FOC of Ramsey Problem
|
||||||
avVarModel = 7 //!< Variable for var_model with order > abs(min_lag()) present in model
|
avVarModel = 7, //!< Variable for var_model with order > abs(min_lag()) present in model
|
||||||
|
avDiff = 8 //!< Variable for Diff operator
|
||||||
};
|
};
|
||||||
|
|
||||||
//! Information on some auxiliary variables
|
//! Information on some auxiliary variables
|
||||||
|
@ -283,6 +284,8 @@ public:
|
||||||
//! Adds an auxiliary variable when var_model is used with an order that is greater in absolute value
|
//! Adds an auxiliary variable when var_model is used with an order that is greater in absolute value
|
||||||
//! than the largest lag present in the model.
|
//! than the largest lag present in the model.
|
||||||
int addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException);
|
int addVarModelEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (AlreadyDeclaredException, FrozenException);
|
||||||
|
//! Adds an auxiliary variable when the diff operator is encountered
|
||||||
|
int addDiffAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException);
|
||||||
//! Returns the number of auxiliary variables
|
//! Returns the number of auxiliary variables
|
||||||
int
|
int
|
||||||
AuxVarsSize() const
|
AuxVarsSize() const
|
||||||
|
|
Loading…
Reference in New Issue