parent
4d2f91813b
commit
47a8fd0147
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2013 Dynare Team
|
* Copyright (C) 2003-2014 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -3427,9 +3427,8 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
|
||||||
dynamic_model.AddLocalVariable(it->first, it->second->cloneDynamic(dynamic_model));
|
dynamic_model.AddLocalVariable(it->first, it->second->cloneDynamic(dynamic_model));
|
||||||
|
|
||||||
// Convert equations
|
// Convert equations
|
||||||
for (vector<BinaryOpNode *>::const_iterator it = equations.begin();
|
for (size_t i = 0; i < equations.size(); i++)
|
||||||
it != equations.end(); it++)
|
dynamic_model.addEquation(equations[i]->cloneDynamic(dynamic_model), equations_lineno[i]);
|
||||||
dynamic_model.addEquation((*it)->cloneDynamic(dynamic_model));
|
|
||||||
|
|
||||||
// Convert auxiliary equations
|
// Convert auxiliary equations
|
||||||
for (deque<BinaryOpNode *>::const_iterator it = aux_equations.begin();
|
for (deque<BinaryOpNode *>::const_iterator it = aux_equations.begin();
|
||||||
|
@ -3437,18 +3436,18 @@ DynamicModel::cloneDynamic(DynamicModel &dynamic_model) const
|
||||||
dynamic_model.addAuxEquation((*it)->cloneDynamic(dynamic_model));
|
dynamic_model.addAuxEquation((*it)->cloneDynamic(dynamic_model));
|
||||||
|
|
||||||
// Convert static_only equations
|
// Convert static_only equations
|
||||||
for (vector<BinaryOpNode *>::const_iterator it = static_only_equations.begin();
|
for (size_t i = 0; i < static_only_equations.size(); i++)
|
||||||
it != static_only_equations.end(); it++)
|
dynamic_model.addStaticOnlyEquation(static_only_equations[i]->cloneDynamic(dynamic_model),
|
||||||
dynamic_model.addStaticOnlyEquation((*it)->cloneDynamic(dynamic_model));
|
static_only_equations_lineno[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::replaceMyEquations(DynamicModel &dynamic_model) const
|
DynamicModel::replaceMyEquations(DynamicModel &dynamic_model) const
|
||||||
{
|
{
|
||||||
dynamic_model.equations.clear();
|
dynamic_model.equations.clear();
|
||||||
for (vector<BinaryOpNode *>::const_iterator it = equations.begin();
|
for (size_t i = 0; i < equations.size(); i++)
|
||||||
it != equations.end(); it++)
|
dynamic_model.addEquation(equations[i]->cloneDynamic(dynamic_model),
|
||||||
dynamic_model.addEquation((*it)->cloneDynamic(dynamic_model));
|
equations_lineno[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -3468,7 +3467,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model)
|
||||||
|
|
||||||
// Add Planner Objective to equations to include in computeDerivIDs
|
// Add Planner Objective to equations to include in computeDerivIDs
|
||||||
assert(static_model.equations.size() == 1);
|
assert(static_model.equations.size() == 1);
|
||||||
addEquation(static_model.equations[0]->cloneDynamic(*this));
|
addEquation(static_model.equations[0]->cloneDynamic(*this), static_model.equations_lineno[0]);
|
||||||
|
|
||||||
// Get max endo lead and max endo lag
|
// Get max endo lead and max endo lag
|
||||||
set<pair<int, int> > dynvars;
|
set<pair<int, int> > dynvars;
|
||||||
|
@ -3513,7 +3512,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model)
|
||||||
}
|
}
|
||||||
|
|
||||||
equations.clear();
|
equations.clear();
|
||||||
addEquation(AddEqual(lagrangian, Zero));
|
addEquation(AddEqual(lagrangian, Zero), -1);
|
||||||
computeDerivIDs();
|
computeDerivIDs();
|
||||||
|
|
||||||
//Compute derivatives and overwrite equations
|
//Compute derivatives and overwrite equations
|
||||||
|
@ -3527,7 +3526,7 @@ DynamicModel::computeRamseyPolicyFOCs(const StaticModel &static_model)
|
||||||
// Add new equations
|
// Add new equations
|
||||||
equations.clear();
|
equations.clear();
|
||||||
for (int i = 0; i < (int) neweqs.size(); i++)
|
for (int i = 0; i < (int) neweqs.size(); i++)
|
||||||
addEquation(neweqs[i]);
|
addEquation(neweqs[i], -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -3559,11 +3558,11 @@ DynamicModel::toStatic(StaticModel &static_model) const
|
||||||
// If yes, replace it by an equation marked [static]
|
// If yes, replace it by an equation marked [static]
|
||||||
if (is_dynamic_only)
|
if (is_dynamic_only)
|
||||||
{
|
{
|
||||||
static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model));
|
static_model.addEquation(static_only_equations[static_only_index]->toStatic(static_model), static_only_equations_lineno[static_only_index]);
|
||||||
static_only_index++;
|
static_only_index++;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
static_model.addEquation(equations[i]->toStatic(static_model));
|
static_model.addEquation(equations[i]->toStatic(static_model), equations_lineno[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert auxiliary equations
|
// Convert auxiliary equations
|
||||||
|
@ -3795,7 +3794,8 @@ DynamicModel::testTrendDerivativesEqualToZero(const eval_context_t &eval_context
|
||||||
double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog
|
double nearZero = testeq->getDerivative(endogit->second)->eval(eval_context); // eval d F / d Trend d Endog
|
||||||
if (fabs(nearZero) > ZERO_BAND)
|
if (fabs(nearZero) > ZERO_BAND)
|
||||||
{
|
{
|
||||||
cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " w.r.t. trend variable "
|
cerr << "ERROR: trends not compatible with balanced growth path; the second-order cross partial of equation " << eq + 1 << " (line "
|
||||||
|
<< equations_lineno[eq] << ") w.r.t. trend variable "
|
||||||
<< symbol_table.getName(it->first.first) << " and endogenous variable "
|
<< symbol_table.getName(it->first.first) << " and endogenous variable "
|
||||||
<< symbol_table.getName(endogit->first.first) << " is not null. " << endl;
|
<< symbol_table.getName(endogit->first.first) << " is not null. " << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -4075,7 +4075,7 @@ DynamicModel::substituteLeadLagInternal(aux_var_t type, bool deterministic_model
|
||||||
|
|
||||||
// Add new equations
|
// Add new equations
|
||||||
for (int i = 0; i < (int) neweqs.size(); i++)
|
for (int i = 0; i < (int) neweqs.size(); i++)
|
||||||
addEquation(neweqs[i]);
|
addEquation(neweqs[i], -1);
|
||||||
|
|
||||||
// Order of auxiliary variable definition equations:
|
// Order of auxiliary variable definition equations:
|
||||||
// - expectation (entered before this function is called)
|
// - expectation (entered before this function is called)
|
||||||
|
@ -4135,7 +4135,7 @@ DynamicModel::substituteExpectation(bool partial_information_model)
|
||||||
|
|
||||||
// Add new equations
|
// Add new equations
|
||||||
for (int i = 0; i < (int) neweqs.size(); i++)
|
for (int i = 0; i < (int) neweqs.size(); i++)
|
||||||
addEquation(neweqs[i]);
|
addEquation(neweqs[i], -1);
|
||||||
|
|
||||||
// Add the new set of equations at the *beginning* of aux_equations
|
// Add the new set of equations at the *beginning* of aux_equations
|
||||||
copy(neweqs.rbegin(), neweqs.rend(), front_inserter(aux_equations));
|
copy(neweqs.rbegin(), neweqs.rend(), front_inserter(aux_equations));
|
||||||
|
@ -4256,12 +4256,13 @@ DynamicModel::isModelLocalVariableUsed() const
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
DynamicModel::addStaticOnlyEquation(expr_t eq)
|
DynamicModel::addStaticOnlyEquation(expr_t eq, int lineno)
|
||||||
{
|
{
|
||||||
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
|
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
|
||||||
assert(beq != NULL && beq->get_op_code() == oEqual);
|
assert(beq != NULL && beq->get_op_code() == oEqual);
|
||||||
|
|
||||||
static_only_equations.push_back(beq);
|
static_only_equations.push_back(beq);
|
||||||
|
static_only_equations_lineno.push_back(lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t
|
size_t
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2013 Dynare Team
|
* Copyright (C) 2003-2014 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -35,6 +35,9 @@ private:
|
||||||
/*! They will be used in toStatic() to replace equations marked as [dynamic] */
|
/*! They will be used in toStatic() to replace equations marked as [dynamic] */
|
||||||
vector<BinaryOpNode *> static_only_equations;
|
vector<BinaryOpNode *> static_only_equations;
|
||||||
|
|
||||||
|
//! Stores line numbers of equations declared as [static]
|
||||||
|
vector<int> static_only_equations_lineno;
|
||||||
|
|
||||||
typedef map<pair<int, int>, int> deriv_id_table_t;
|
typedef map<pair<int, int>, int> deriv_id_table_t;
|
||||||
//! Maps a pair (symbol_id, lag) to a deriv ID
|
//! Maps a pair (symbol_id, lag) to a deriv ID
|
||||||
deriv_id_table_t deriv_id_table;
|
deriv_id_table_t deriv_id_table;
|
||||||
|
@ -237,7 +240,7 @@ public:
|
||||||
void replaceMyEquations(DynamicModel &dynamic_model) const;
|
void replaceMyEquations(DynamicModel &dynamic_model) const;
|
||||||
|
|
||||||
//! Adds an equation marked as [static]
|
//! Adds an equation marked as [static]
|
||||||
void addStaticOnlyEquation(expr_t eq);
|
void addStaticOnlyEquation(expr_t eq, int lineno);
|
||||||
|
|
||||||
//! Returns number of static only equations
|
//! Returns number of static only equations
|
||||||
size_t staticOnlyEquationsNbr() const;
|
size_t staticOnlyEquationsNbr() const;
|
||||||
|
|
11
ModelTree.cc
11
ModelTree.cc
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2013 Dynare Team
|
* Copyright (C) 2003-2014 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -270,7 +270,7 @@ ModelTree::evaluateAndReduceJacobian(const eval_context_t &eval_context, jacob_m
|
||||||
}
|
}
|
||||||
catch (ExprNode::EvalException &e)
|
catch (ExprNode::EvalException &e)
|
||||||
{
|
{
|
||||||
cerr << "ERROR: evaluation of Jacobian failed for equation " << eq+1 << " and variable " << symbol_table.getName(symb) << "(" << lag << ") [" << symb << "] !" << endl;
|
cerr << "ERROR: evaluation of Jacobian failed for equation " << eq+1 << " (line " << equations_lineno[eq] << ") and variable " << symbol_table.getName(symb) << "(" << lag << ") [" << symb << "] !" << endl;
|
||||||
Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms);
|
Id->writeOutput(cerr, oMatlabDynamicModelSparse, temporary_terms);
|
||||||
cerr << endl;
|
cerr << endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
@ -1376,21 +1376,22 @@ ModelTree::writeLatexModelFile(const string &filename, ExprNodeOutputType output
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::addEquation(expr_t eq)
|
ModelTree::addEquation(expr_t eq, int lineno)
|
||||||
{
|
{
|
||||||
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
|
BinaryOpNode *beq = dynamic_cast<BinaryOpNode *>(eq);
|
||||||
assert(beq != NULL && beq->get_op_code() == oEqual);
|
assert(beq != NULL && beq->get_op_code() == oEqual);
|
||||||
|
|
||||||
equations.push_back(beq);
|
equations.push_back(beq);
|
||||||
|
equations_lineno.push_back(lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
ModelTree::addEquation(expr_t eq, vector<pair<string, string> > &eq_tags)
|
ModelTree::addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags)
|
||||||
{
|
{
|
||||||
int n = equation_number();
|
int n = equation_number();
|
||||||
for (size_t i = 0; i < eq_tags.size(); i++)
|
for (size_t i = 0; i < eq_tags.size(); i++)
|
||||||
equation_tags.push_back(make_pair(n, eq_tags[i]));
|
equation_tags.push_back(make_pair(n, eq_tags[i]));
|
||||||
addEquation(eq);
|
addEquation(eq, lineno);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
11
ModelTree.hh
11
ModelTree.hh
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2013 Dynare Team
|
* Copyright (C) 2003-2014 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -54,6 +54,9 @@ protected:
|
||||||
//! Stores declared and generated auxiliary equations
|
//! Stores declared and generated auxiliary equations
|
||||||
vector<BinaryOpNode *> equations;
|
vector<BinaryOpNode *> equations;
|
||||||
|
|
||||||
|
//! Stores line numbers of declared equations; -1 means undefined
|
||||||
|
vector<int> equations_lineno;
|
||||||
|
|
||||||
//! Only stores generated auxiliary equations, in an order meaningful for evaluation
|
//! Only stores generated auxiliary equations, in an order meaningful for evaluation
|
||||||
deque<BinaryOpNode *> aux_equations;
|
deque<BinaryOpNode *> aux_equations;
|
||||||
|
|
||||||
|
@ -295,10 +298,10 @@ public:
|
||||||
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
|
3 : the variables belonging to a non normalizable non linear equation are considered as feedback variables
|
||||||
default value = 0 */
|
default value = 0 */
|
||||||
int mfs;
|
int mfs;
|
||||||
//! Declare a node as an equation of the model
|
//! Declare a node as an equation of the model; also give its line number
|
||||||
void addEquation(expr_t eq);
|
void addEquation(expr_t eq, int lineno);
|
||||||
//! Declare a node as an equation of the model, also giving its tags
|
//! Declare a node as an equation of the model, also giving its tags
|
||||||
void addEquation(expr_t eq, vector<pair<string, string> > &eq_tags);
|
void addEquation(expr_t eq, int lineno, vector<pair<string, string> > &eq_tags);
|
||||||
//! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations
|
//! Declare a node as an auxiliary equation of the model, adding it at the end of the list of auxiliary equations
|
||||||
void addAuxEquation(expr_t eq);
|
void addAuxEquation(expr_t eq);
|
||||||
//! Returns the number of equations in the model
|
//! Returns the number of equations in the model
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2003-2013 Dynare Team
|
* Copyright (C) 2003-2014 Dynare Team
|
||||||
*
|
*
|
||||||
* This file is part of Dynare.
|
* This file is part of Dynare.
|
||||||
*
|
*
|
||||||
|
@ -1741,7 +1741,7 @@ ParsingDriver::end_planner_objective(expr_t expr)
|
||||||
{
|
{
|
||||||
// Add equation corresponding to expression
|
// Add equation corresponding to expression
|
||||||
expr_t eq = model_tree->AddEqual(expr, model_tree->Zero);
|
expr_t eq = model_tree->AddEqual(expr, model_tree->Zero);
|
||||||
model_tree->addEquation(eq);
|
model_tree->addEquation(eq, location.begin.line);
|
||||||
|
|
||||||
mod_file->addStatement(new PlannerObjectiveStatement(dynamic_cast<StaticModel *>(model_tree)));
|
mod_file->addStatement(new PlannerObjectiveStatement(dynamic_cast<StaticModel *>(model_tree)));
|
||||||
|
|
||||||
|
@ -1988,10 +1988,10 @@ ParsingDriver::add_model_equal(expr_t arg1, expr_t arg2)
|
||||||
if (!id->isInStaticForm())
|
if (!id->isInStaticForm())
|
||||||
error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators");
|
error("An equation tagged [static] cannot contain leads, lags, expectations or STEADY_STATE operators");
|
||||||
|
|
||||||
dynamic_model->addStaticOnlyEquation(id);
|
dynamic_model->addStaticOnlyEquation(id, location.begin.line);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
model_tree->addEquation(id, eq_tags);
|
model_tree->addEquation(id, location.begin.line, eq_tags);
|
||||||
|
|
||||||
eq_tags.clear();
|
eq_tags.clear();
|
||||||
return id;
|
return id;
|
||||||
|
|
Loading…
Reference in New Issue