2008-01-11 14:42:14 +01:00
|
|
|
/*
|
2016-02-26 16:23:39 +01:00
|
|
|
* Copyright (C) 2003-2016 Dynare Team
|
2008-01-11 14:42:14 +01:00
|
|
|
*
|
|
|
|
* This file is part of Dynare.
|
|
|
|
*
|
|
|
|
* Dynare is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Dynare is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with Dynare. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#include <algorithm>
|
2006-11-28 12:56:02 +01:00
|
|
|
#include <sstream>
|
2009-09-30 17:10:31 +02:00
|
|
|
#include <iostream>
|
2009-11-09 12:03:18 +01:00
|
|
|
#include <cassert>
|
2006-11-28 12:56:02 +01:00
|
|
|
|
2006-11-05 00:31:17 +01:00
|
|
|
#include "SymbolTable.hh"
|
2006-11-28 12:56:02 +01:00
|
|
|
|
2011-03-21 18:40:57 +01:00
|
|
|
AuxVarInfo::AuxVarInfo(int symb_id_arg, aux_var_t type_arg, int orig_symb_id_arg, int orig_lead_lag_arg,
|
2015-05-26 15:47:56 +02:00
|
|
|
int equation_number_for_multiplier_arg, int information_set_arg,
|
2016-03-18 14:55:14 +01:00
|
|
|
expr_t expr_node_arg) :
|
2010-01-18 23:08:44 +01:00
|
|
|
symb_id(symb_id_arg),
|
|
|
|
type(type_arg),
|
|
|
|
orig_symb_id(orig_symb_id_arg),
|
|
|
|
orig_lead_lag(orig_lead_lag_arg),
|
2015-05-26 15:47:56 +02:00
|
|
|
equation_number_for_multiplier(equation_number_for_multiplier_arg),
|
|
|
|
information_set(information_set_arg),
|
2016-03-18 14:55:14 +01:00
|
|
|
expr_node(expr_node_arg)
|
2010-01-18 23:08:44 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
SymbolTable::SymbolTable() : frozen(false), size(0)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
int
|
2016-06-24 17:38:54 +02:00
|
|
|
SymbolTable::addSymbol(const string &name, SymbolType type, const string &tex_name, const vector<pair<string * , string *> *> *partition_value) throw (AlreadyDeclaredException, FrozenException)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
if (frozen)
|
|
|
|
throw FrozenException();
|
|
|
|
|
2007-12-19 16:16:43 +01:00
|
|
|
if (exists(name))
|
2008-06-28 13:20:45 +02:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
if (type_table[getID(name)] == type)
|
2008-06-28 13:20:45 +02:00
|
|
|
throw AlreadyDeclaredException(name, true);
|
|
|
|
else
|
|
|
|
throw AlreadyDeclaredException(name, false);
|
|
|
|
}
|
2007-12-19 16:16:43 +01:00
|
|
|
|
2013-12-10 11:39:41 +01:00
|
|
|
string final_tex_name = tex_name;
|
|
|
|
if (final_tex_name.empty())
|
|
|
|
{
|
|
|
|
final_tex_name = name;
|
|
|
|
size_t pos = 0;
|
|
|
|
while ((pos = final_tex_name.find('_', pos)) != string::npos)
|
|
|
|
{
|
|
|
|
final_tex_name.insert(pos, "\\");
|
|
|
|
pos += 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 17:38:54 +02:00
|
|
|
string final_long_name = name;
|
|
|
|
bool non_long_name_partition_exists = false;
|
|
|
|
if (partition_value)
|
|
|
|
for (vector<pair<string *, string *> *>::const_iterator it = partition_value->begin();
|
|
|
|
it != partition_value->end(); it++)
|
|
|
|
if (*((*it)->first) == "long_name")
|
|
|
|
final_long_name = *((*it)->second);
|
|
|
|
else
|
|
|
|
non_long_name_partition_exists = true;
|
2013-12-10 11:39:41 +01:00
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
int id = size++;
|
|
|
|
|
|
|
|
symbol_table[name] = id;
|
|
|
|
type_table.push_back(type);
|
|
|
|
name_table.push_back(name);
|
2013-12-10 11:39:41 +01:00
|
|
|
tex_name_table.push_back(final_tex_name);
|
|
|
|
long_name_table.push_back(final_long_name);
|
2016-06-24 17:38:54 +02:00
|
|
|
if (non_long_name_partition_exists)
|
|
|
|
{
|
|
|
|
map<string, string> pmv;
|
|
|
|
for (vector<pair<string *, string *> *>::const_iterator it = partition_value->begin();
|
|
|
|
it != partition_value->end(); it++)
|
|
|
|
pmv[*((*it)->first)] = *((*it)->second);
|
|
|
|
partition_value_map[id] = pmv;
|
|
|
|
}
|
2009-09-30 17:10:31 +02:00
|
|
|
return id;
|
2009-02-27 13:19:25 +01:00
|
|
|
}
|
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
int
|
2009-04-30 15:14:33 +02:00
|
|
|
SymbolTable::addSymbol(const string &name, SymbolType type) throw (AlreadyDeclaredException, FrozenException)
|
|
|
|
{
|
2016-02-26 16:23:39 +01:00
|
|
|
return addSymbol(name, type, "", NULL);
|
2009-04-30 15:14:33 +02:00
|
|
|
}
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
void
|
|
|
|
SymbolTable::freeze() throw (FrozenException)
|
|
|
|
{
|
|
|
|
if (frozen)
|
|
|
|
throw FrozenException();
|
2006-11-05 00:31:17 +01:00
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
frozen = true;
|
|
|
|
|
2009-12-16 18:13:23 +01:00
|
|
|
for (int i = 0; i < size; i++)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
int tsi;
|
2009-12-16 18:13:23 +01:00
|
|
|
switch (getType(i))
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
case eEndogenous:
|
|
|
|
tsi = endo_ids.size();
|
|
|
|
endo_ids.push_back(i);
|
|
|
|
break;
|
|
|
|
case eExogenous:
|
|
|
|
tsi = exo_ids.size();
|
|
|
|
exo_ids.push_back(i);
|
|
|
|
break;
|
|
|
|
case eExogenousDet:
|
|
|
|
tsi = exo_det_ids.size();
|
|
|
|
exo_det_ids.push_back(i);
|
|
|
|
break;
|
|
|
|
case eParameter:
|
|
|
|
tsi = param_ids.size();
|
|
|
|
param_ids.push_back(i);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
tsi = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
type_specific_ids.push_back(tsi);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SymbolTable::changeType(int id, SymbolType newtype) throw (UnknownSymbolIDException, FrozenException)
|
|
|
|
{
|
|
|
|
if (frozen)
|
|
|
|
throw FrozenException();
|
|
|
|
|
|
|
|
if (id < 0 || id >= size)
|
|
|
|
throw UnknownSymbolIDException(id);
|
|
|
|
|
|
|
|
type_table[id] = newtype;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SymbolTable::getID(SymbolType type, int tsid) const throw (UnknownTypeSpecificIDException, NotYetFrozenException)
|
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
2009-12-16 18:13:23 +01:00
|
|
|
switch (type)
|
2009-02-27 13:19:25 +01:00
|
|
|
{
|
|
|
|
case eEndogenous:
|
|
|
|
if (tsid < 0 || tsid >= (int) endo_ids.size())
|
|
|
|
throw UnknownTypeSpecificIDException(tsid, type);
|
|
|
|
else
|
|
|
|
return endo_ids[tsid];
|
2006-11-05 00:31:17 +01:00
|
|
|
case eExogenous:
|
2009-02-27 13:19:25 +01:00
|
|
|
if (tsid < 0 || tsid >= (int) exo_ids.size())
|
|
|
|
throw UnknownTypeSpecificIDException(tsid, type);
|
|
|
|
else
|
|
|
|
return exo_ids[tsid];
|
2006-11-05 00:31:17 +01:00
|
|
|
case eExogenousDet:
|
2009-02-27 13:19:25 +01:00
|
|
|
if (tsid < 0 || tsid >= (int) exo_det_ids.size())
|
|
|
|
throw UnknownTypeSpecificIDException(tsid, type);
|
|
|
|
else
|
|
|
|
return exo_det_ids[tsid];
|
2006-11-05 00:31:17 +01:00
|
|
|
case eParameter:
|
2009-02-27 13:19:25 +01:00
|
|
|
if (tsid < 0 || tsid >= (int) param_ids.size())
|
|
|
|
throw UnknownTypeSpecificIDException(tsid, type);
|
|
|
|
else
|
|
|
|
return param_ids[tsid];
|
|
|
|
default:
|
|
|
|
throw UnknownTypeSpecificIDException(tsid, type);
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 17:38:54 +02:00
|
|
|
map<string, map<int, string> >
|
|
|
|
SymbolTable::getPartitionsForType(enum SymbolType st) const throw (UnknownSymbolIDException)
|
2016-02-26 16:23:39 +01:00
|
|
|
{
|
2016-06-24 17:38:54 +02:00
|
|
|
map<string, map<int, string> > partitions;
|
|
|
|
for (map<int, map<string, string> >::const_iterator it = partition_value_map.begin();
|
2016-02-26 16:23:39 +01:00
|
|
|
it != partition_value_map.end(); it++)
|
2016-06-24 17:38:54 +02:00
|
|
|
if (getType(it->first) == st)
|
|
|
|
for (map<string, string>::const_iterator it1 = it->second.begin();
|
|
|
|
it1 != it->second.end(); it1++)
|
|
|
|
{
|
|
|
|
if (partitions.find(it1->first) == partitions.end())
|
|
|
|
partitions[it1->first] = map<int, string> ();
|
|
|
|
partitions[it1->first][it->first] = it1->second;
|
|
|
|
}
|
|
|
|
return partitions;
|
2016-02-26 16:23:39 +01:00
|
|
|
}
|
|
|
|
|
2006-12-12 12:54:30 +01:00
|
|
|
void
|
2009-02-27 13:19:25 +01:00
|
|
|
SymbolTable::writeOutput(ostream &output) const throw (NotYetFrozenException)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
if (exo_nbr() > 0)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
output << "M_.exo_names = '" << getName(exo_ids[0]) << "';" << endl;
|
|
|
|
output << "M_.exo_names_tex = '" << getTeXName(exo_ids[0]) << "';" << endl;
|
2013-11-15 10:39:00 +01:00
|
|
|
output << "M_.exo_names_long = '" << getLongName(exo_ids[0]) << "';" << endl;
|
2009-02-27 13:19:25 +01:00
|
|
|
for (int id = 1; id < exo_nbr(); id++)
|
2016-06-24 17:38:54 +02:00
|
|
|
output << "M_.exo_names = char(M_.exo_names, '" << getName(exo_ids[id]) << "');" << endl
|
|
|
|
<< "M_.exo_names_tex = char(M_.exo_names_tex, '" << getTeXName(exo_ids[id]) << "');" << endl
|
|
|
|
<< "M_.exo_names_long = char(M_.exo_names_long, '" << getLongName(exo_ids[id]) << "');" << endl;
|
|
|
|
|
|
|
|
|
|
|
|
map<string, map<int, string> > partitions = getPartitionsForType(eExogenous);
|
|
|
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
|
|
|
it != partitions.end(); it++)
|
|
|
|
if (it->first != "long_name")
|
|
|
|
{
|
|
|
|
map<int, string>::const_iterator it1;
|
|
|
|
output << "M_.exo_partitions." << it->first << " = { ";
|
|
|
|
for (int id = 0; id < exo_nbr(); id++)
|
|
|
|
{
|
|
|
|
output << "'";
|
|
|
|
it1 = it->second.find(exo_ids[id]);
|
|
|
|
if (it1 != it->second.end())
|
|
|
|
output << it1->second;
|
|
|
|
output << "' ";
|
|
|
|
}
|
|
|
|
output << "};" << endl;
|
|
|
|
}
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
2016-02-26 16:23:39 +01:00
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
if (exo_det_nbr() > 0)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
output << "M_.exo_det_names = '" << getName(exo_det_ids[0]) << "';" << endl;
|
|
|
|
output << "M_.exo_det_names_tex = '" << getTeXName(exo_det_ids[0]) << "';" << endl;
|
2013-11-15 10:39:00 +01:00
|
|
|
output << "M_.exo_det_names_long = '" << getLongName(exo_det_ids[0]) << "';" << endl;
|
2009-02-27 13:19:25 +01:00
|
|
|
for (int id = 1; id < exo_det_nbr(); id++)
|
2016-06-24 17:38:54 +02:00
|
|
|
output << "M_.exo_det_names = char(M_.exo_det_names, '" << getName(exo_det_ids[id]) << "');" << endl
|
|
|
|
<< "M_.exo_det_names_tex = char(M_.exo_det_names_tex, '" << getTeXName(exo_det_ids[id]) << "');" << endl
|
|
|
|
<< "M_.exo_det_names_long = char(M_.exo_det_names_long, '" << getLongName(exo_det_ids[id]) << "');" << endl;
|
|
|
|
|
|
|
|
output << "M_.exo_det_partitions = struct();" << endl;
|
|
|
|
map<string, map<int, string> > partitions = getPartitionsForType(eExogenousDet);
|
|
|
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
|
|
|
it != partitions.end(); it++)
|
|
|
|
if (it->first != "long_name")
|
|
|
|
{
|
|
|
|
map<int, string>::const_iterator it1;
|
|
|
|
output << "M_.exo_det_partitions." << it->first << " = { ";
|
|
|
|
for (int id = 0; id < exo_det_nbr(); id++)
|
|
|
|
{
|
|
|
|
output << "'";
|
|
|
|
it1 = it->second.find(exo_det_ids[id]);
|
|
|
|
if (it1 != it->second.end())
|
|
|
|
output << it1->second;
|
|
|
|
output << "' ";
|
|
|
|
}
|
|
|
|
output << "};" << endl;
|
|
|
|
}
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
2016-02-26 16:23:39 +01:00
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
if (endo_nbr() > 0)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
output << "M_.endo_names = '" << getName(endo_ids[0]) << "';" << endl;
|
|
|
|
output << "M_.endo_names_tex = '" << getTeXName(endo_ids[0]) << "';" << endl;
|
2013-11-15 09:46:18 +01:00
|
|
|
output << "M_.endo_names_long = '" << getLongName(endo_ids[0]) << "';" << endl;
|
2009-02-27 13:19:25 +01:00
|
|
|
for (int id = 1; id < endo_nbr(); id++)
|
2016-06-24 17:38:54 +02:00
|
|
|
output << "M_.endo_names = char(M_.endo_names, '" << getName(endo_ids[id]) << "');" << endl
|
|
|
|
<< "M_.endo_names_tex = char(M_.endo_names_tex, '" << getTeXName(endo_ids[id]) << "');" << endl
|
|
|
|
<< "M_.endo_names_long = char(M_.endo_names_long, '" << getLongName(endo_ids[id]) << "');" << endl;
|
|
|
|
|
|
|
|
output << "M_.endo_partitions = struct();" << endl;
|
|
|
|
map<string, map<int, string> > partitions = getPartitionsForType(eEndogenous);
|
|
|
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
|
|
|
it != partitions.end(); it++)
|
|
|
|
if (it->first != "long_name")
|
|
|
|
{
|
|
|
|
map<int, string>::const_iterator it1;
|
|
|
|
output << "M_.endo_partitions." << it->first << " = { ";
|
|
|
|
for (int id = 0; id < endo_nbr(); id++)
|
|
|
|
{
|
|
|
|
output << "'";
|
|
|
|
it1 = it->second.find(endo_ids[id]);
|
|
|
|
if (it1 != it->second.end())
|
|
|
|
output << it1->second;
|
|
|
|
output << "' ";
|
|
|
|
}
|
|
|
|
output << "};" << endl;
|
|
|
|
}
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
2016-02-26 16:23:39 +01:00
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
if (param_nbr() > 0)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2009-02-27 13:19:25 +01:00
|
|
|
output << "M_.param_names = '" << getName(param_ids[0]) << "';" << endl;
|
|
|
|
output << "M_.param_names_tex = '" << getTeXName(param_ids[0]) << "';" << endl;
|
2013-11-15 10:56:48 +01:00
|
|
|
output << "M_.param_names_long = '" << getLongName(param_ids[0]) << "';" << endl;
|
2009-02-27 13:19:25 +01:00
|
|
|
for (int id = 1; id < param_nbr(); id++)
|
2006-11-05 00:31:17 +01:00
|
|
|
{
|
2010-09-26 13:42:41 +02:00
|
|
|
output << "M_.param_names = char(M_.param_names, '" << getName(param_ids[id]) << "');" << endl
|
2013-11-15 10:56:48 +01:00
|
|
|
<< "M_.param_names_tex = char(M_.param_names_tex, '" << getTeXName(param_ids[id]) << "');" << endl
|
|
|
|
<< "M_.param_names_long = char(M_.param_names_long, '" << getLongName(param_ids[id]) << "');" << endl;
|
2010-06-21 18:40:36 +02:00
|
|
|
|
|
|
|
if (getName(param_ids[id]) == "dsge_prior_weight")
|
|
|
|
output << "options_.dsge_var = 1;" << endl;
|
2016-06-23 15:59:35 +02:00
|
|
|
}
|
2016-06-24 17:38:54 +02:00
|
|
|
|
|
|
|
output << "M_.param_partitions = struct();" << endl;
|
|
|
|
map<string, map<int, string> > partitions = getPartitionsForType(eParameter);
|
|
|
|
for (map<string, map<int, string> >::const_iterator it = partitions.begin();
|
|
|
|
it != partitions.end(); it++)
|
|
|
|
if (it->first != "long_name")
|
|
|
|
{
|
|
|
|
map<int, string>::const_iterator it1;
|
|
|
|
output << "M_.param_partitions." << it->first << " = { ";
|
|
|
|
for (int id = 0; id < param_nbr(); id++)
|
|
|
|
{
|
|
|
|
output << "'";
|
|
|
|
it1 = it->second.find(param_ids[id]);
|
|
|
|
if (it1 != it->second.end())
|
|
|
|
output << it1->second;
|
|
|
|
output << "' ";
|
|
|
|
}
|
|
|
|
output << "};" << endl;
|
|
|
|
}
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
|
|
|
|
2009-02-27 13:19:25 +01:00
|
|
|
output << "M_.exo_det_nbr = " << exo_det_nbr() << ";" << endl
|
|
|
|
<< "M_.exo_nbr = " << exo_nbr() << ";" << endl
|
|
|
|
<< "M_.endo_nbr = " << endo_nbr() << ";" << endl
|
|
|
|
<< "M_.param_nbr = " << param_nbr() << ";" << endl;
|
2007-12-19 16:16:43 +01:00
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
// Write the auxiliary variable table
|
2010-04-23 18:36:51 +02:00
|
|
|
output << "M_.orig_endo_nbr = " << orig_endo_nbr() << ";" << endl;
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
if (aux_vars.size() == 0)
|
|
|
|
output << "M_.aux_vars = [];" << endl;
|
|
|
|
else
|
2009-12-16 18:13:23 +01:00
|
|
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
{
|
2010-01-18 23:08:44 +01:00
|
|
|
output << "M_.aux_vars(" << i+1 << ").endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id())+1 << ";" << endl
|
|
|
|
<< "M_.aux_vars(" << i+1 << ").type = " << aux_vars[i].get_type() << ";" << endl;
|
|
|
|
switch (aux_vars[i].get_type())
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
{
|
|
|
|
case avEndoLead:
|
|
|
|
case avExoLead:
|
|
|
|
break;
|
|
|
|
case avEndoLag:
|
|
|
|
case avExoLag:
|
2010-01-18 23:08:44 +01:00
|
|
|
output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl
|
|
|
|
<< "M_.aux_vars(" << i+1 << ").orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
break;
|
2011-03-21 18:40:57 +01:00
|
|
|
case avMultiplier:
|
2015-08-17 10:51:14 +02:00
|
|
|
output << "M_.aux_vars(" << i+1 << ").eq_nbr = " << aux_vars[i].get_equation_number_for_multiplier() + 1 << ";" << endl;
|
2011-03-21 18:40:57 +01:00
|
|
|
break;
|
2013-04-25 18:09:31 +02:00
|
|
|
case avDiffForward:
|
|
|
|
output << "M_.aux_vars(" << i+1 << ").orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ";" << endl;
|
|
|
|
break;
|
2015-05-26 15:47:56 +02:00
|
|
|
case avExpectation:
|
|
|
|
output << "M_.aux_vars(" << i+1 << ").orig_expr = '\\mathbb{E}_{t"
|
|
|
|
<< (aux_vars[i].get_information_set() < 0 ? "" : "+")
|
|
|
|
<< aux_vars[i].get_information_set() << "}(";
|
2016-03-18 14:55:14 +01:00
|
|
|
aux_vars[i].get_expr_node()->writeOutput(output, oLatexDynamicModel);
|
2015-05-26 15:47:56 +02:00
|
|
|
output << ")';" << endl;
|
|
|
|
break;
|
Fixes for ticket #57
preprocessor:
* add a field "M_.orig_endo_nbr" containing the nbr of endogenous before adding aux vars
* always provide "M_.aux_vars" (define it to "[]" when there is no aux var)
* rename "M_.aux_vars().orig_endo_index" to "M_.aux_vars().orig_index"
M-files:
* for commands which accept a list of variables (stoch_simul, osr, estimation, dynasave, dynatype, datatomfile), when no variable is given, use only the set of original endogenous (without aux vars) as the default
* when displaying the decision rule, when there is aux vars in the state variables, replace them by their original name (with the right lag)
* in "steady", don't display aux vars
* special exception for ramsey policy: all vars (including aux vars) are displayed, because the system of aux vars from ramsey policy is not compatible with the aux vars from the preprocessor
git-svn-id: https://www.dynare.org/svn/dynare/trunk@3166 ac1d8469-bf42-47a9-8791-bf33cf982152
2009-11-25 11:22:39 +01:00
|
|
|
}
|
|
|
|
}
|
2009-11-09 12:03:18 +01:00
|
|
|
|
|
|
|
if (predeterminedNbr() > 0)
|
|
|
|
{
|
|
|
|
output << "M_.predetermined_variables = [ ";
|
2009-12-16 18:13:23 +01:00
|
|
|
for (set<int>::const_iterator it = predetermined_variables.begin();
|
|
|
|
it != predetermined_variables.end(); it++)
|
2009-11-09 12:07:31 +01:00
|
|
|
output << getTypeSpecificID(*it)+1 << " ";
|
2009-11-09 12:03:18 +01:00
|
|
|
output << "];" << endl;
|
|
|
|
}
|
2010-04-14 15:03:41 +02:00
|
|
|
|
|
|
|
if (observedVariablesNbr() > 0)
|
|
|
|
{
|
2013-05-14 14:41:34 +02:00
|
|
|
int ic = 1;
|
|
|
|
output << "options_.varobs = cell(1);" << endl;
|
2010-04-14 15:03:41 +02:00
|
|
|
for (vector<int>::const_iterator it = varobs.begin();
|
2015-07-23 18:10:44 +02:00
|
|
|
it != varobs.end(); it++, ic++)
|
|
|
|
output << "options_.varobs(" << ic << ") = {'" << getName(*it) << "'};" << endl;
|
|
|
|
|
2010-06-11 19:18:16 +02:00
|
|
|
output << "options_.varobs_id = [ ";
|
|
|
|
for (vector<int>::const_iterator it = varobs.begin();
|
|
|
|
it != varobs.end(); it++)
|
|
|
|
output << getTypeSpecificID(*it)+1 << " ";
|
|
|
|
output << " ];" << endl;
|
2010-04-14 15:03:41 +02:00
|
|
|
}
|
2009-09-30 17:10:31 +02:00
|
|
|
}
|
|
|
|
|
2013-08-06 21:20:36 +02:00
|
|
|
void
|
|
|
|
SymbolTable::writeCOutput(ostream &output) const throw (NotYetFrozenException)
|
2014-03-15 21:07:09 +01:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
output << endl
|
|
|
|
<< "int exo_nbr = " << exo_nbr() << ";" << endl;
|
|
|
|
if (exo_nbr() > 0)
|
|
|
|
{
|
|
|
|
output << "char *exo_names[" << exo_nbr() << "];" << endl;
|
|
|
|
for (int id = 0; id < exo_nbr(); id++)
|
|
|
|
output << "exo_names[" << id << "] = \"" << getName(exo_ids[id]) << "\";" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
output << endl
|
|
|
|
<< "int exo_det_nbr = " << exo_det_nbr() << ";" << endl;
|
|
|
|
if (exo_det_nbr() > 0)
|
|
|
|
{
|
|
|
|
output << "char *exo_det_names[" << exo_det_nbr() << "];" << endl;
|
|
|
|
for (int id = 0; id < exo_det_nbr(); id++)
|
|
|
|
output << "exo_det_names[" << id << "] = \"" << getName(exo_det_ids[id]) << "\";" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
output << endl
|
|
|
|
<< "int endo_nbr = " << endo_nbr() << ";" << endl;
|
|
|
|
if (endo_nbr() > 0)
|
|
|
|
{
|
|
|
|
output << "char *endo_names[" << endo_nbr() << "];" << endl;
|
|
|
|
for (int id = 0; id < endo_nbr(); id++)
|
|
|
|
output << "endo_names[" << id << "] = \"" << getName(endo_ids[id]) << "\";" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
output << endl
|
|
|
|
<< "int param_nbr = " << param_nbr() << ";" << endl;
|
|
|
|
if (param_nbr() > 0)
|
|
|
|
{
|
|
|
|
output << "char *param_names[" << param_nbr() << "];" << endl;
|
|
|
|
for (int id = 0; id < param_nbr(); id++)
|
|
|
|
output << "param_names[" << id << "] = \"" << getName(param_ids[id]) << "\";" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Write the auxiliary variable table
|
|
|
|
output << "int aux_var_nbr = " << aux_vars.size() << ";" << endl;
|
|
|
|
if (aux_vars.size() > 0)
|
|
|
|
{
|
|
|
|
output << "struct aux_vars_t *av[" << aux_vars.size() << "];" << endl;
|
|
|
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
|
|
|
{
|
|
|
|
output << "av[" << i << "].endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl
|
|
|
|
<< "av[" << i << "].type = " << aux_vars[i].get_type() << ";" << endl;
|
|
|
|
switch (aux_vars[i].get_type())
|
|
|
|
{
|
|
|
|
case avEndoLead:
|
|
|
|
case avExoLead:
|
|
|
|
case avExpectation:
|
|
|
|
case avMultiplier:
|
|
|
|
case avDiffForward:
|
|
|
|
break;
|
|
|
|
case avEndoLag:
|
|
|
|
case avExoLag:
|
|
|
|
output << "av[" << i << "].orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
|
|
|
|
<< "av[" << i << "].orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
output << "int predeterminedNbr = " << predeterminedNbr() << ";" << endl;
|
|
|
|
if (predeterminedNbr() > 0)
|
|
|
|
{
|
|
|
|
output << "int predetermined_variables[" << predeterminedNbr() << "] = {";
|
|
|
|
for (set<int>::const_iterator it = predetermined_variables.begin();
|
|
|
|
it != predetermined_variables.end(); it++)
|
|
|
|
{
|
|
|
|
if ( it != predetermined_variables.begin() )
|
|
|
|
output << ",";
|
|
|
|
output << getTypeSpecificID(*it);
|
|
|
|
}
|
|
|
|
output << "};" << endl;
|
|
|
|
}
|
|
|
|
|
|
|
|
output << "int observedVariablesNbr = " << observedVariablesNbr() << ";" << endl;
|
|
|
|
if (observedVariablesNbr() > 0)
|
|
|
|
{
|
|
|
|
output << "int varobs[" << observedVariablesNbr() << "] = {";
|
|
|
|
for (vector<int>::const_iterator it = varobs.begin();
|
|
|
|
it != varobs.end(); it++)
|
|
|
|
{
|
|
|
|
if ( it != varobs.begin() )
|
|
|
|
output << ",";
|
|
|
|
output << getTypeSpecificID(*it);
|
|
|
|
}
|
|
|
|
output << "};" << endl;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
SymbolTable::writeCCOutput(ostream &output) const throw (NotYetFrozenException)
|
2013-08-06 21:20:36 +02:00
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
|
|
|
output << endl
|
2013-11-03 18:05:38 +01:00
|
|
|
<< "exo_nbr = " << exo_nbr() << ";" << endl;
|
2015-08-11 12:10:44 +02:00
|
|
|
for (int id = 0; id < exo_nbr(); id++)
|
|
|
|
output << "exo_names[\"" << getName(exo_ids[id]) << "\"] = " << id << ";" << endl;
|
2013-08-06 21:20:36 +02:00
|
|
|
|
|
|
|
output << endl
|
2013-11-03 18:05:38 +01:00
|
|
|
<< "exo_det_nbr = " << exo_det_nbr() << ";" << endl;
|
2015-08-11 12:10:44 +02:00
|
|
|
for (int id = 0; id < exo_det_nbr(); id++)
|
|
|
|
output << "exo_det_names[\"" << getName(exo_det_ids[id]) << "\"] = " << id << " ;" << endl;
|
2013-08-06 21:20:36 +02:00
|
|
|
|
|
|
|
output << endl
|
2013-11-03 18:05:38 +01:00
|
|
|
<< "endo_nbr = " << endo_nbr() << ";" << endl;
|
2015-08-11 12:10:44 +02:00
|
|
|
for (int id = 0; id < endo_nbr(); id++)
|
|
|
|
output << "endo_names[\"" << getName(endo_ids[id]) << "\"] = " << id << ";" << endl;
|
2013-08-06 21:20:36 +02:00
|
|
|
|
|
|
|
output << endl
|
2016-06-18 11:18:55 +02:00
|
|
|
<< "param_nbr = " << param_nbr() << ";" << endl;
|
2015-08-11 12:10:44 +02:00
|
|
|
for (int id = 0; id < param_nbr(); id++)
|
|
|
|
output << "param_names[\"" << getName(param_ids[id]) << "\"] = " << id << ";" << endl;
|
2013-08-06 21:20:36 +02:00
|
|
|
|
|
|
|
// Write the auxiliary variable table
|
2015-08-11 12:10:44 +02:00
|
|
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
|
|
|
{
|
|
|
|
output << "aux_vars_t av" << i << ";" << endl;
|
|
|
|
output << "av" << i << ".endo_index = " << getTypeSpecificID(aux_vars[i].get_symb_id()) << ";" << endl
|
|
|
|
<< "av" << i << ".type = " << aux_vars[i].get_type() << ";" << endl;
|
|
|
|
switch (aux_vars[i].get_type())
|
|
|
|
{
|
|
|
|
case avEndoLead:
|
|
|
|
case avExoLead:
|
|
|
|
case avExpectation:
|
|
|
|
case avMultiplier:
|
|
|
|
case avDiffForward:
|
|
|
|
break;
|
|
|
|
case avEndoLag:
|
|
|
|
case avExoLag:
|
|
|
|
output << "av" << i << ".orig_index = " << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) << ";" << endl
|
|
|
|
<< "av" << i << ".orig_lead_lag = " << aux_vars[i].get_orig_lead_lag() << ";" << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
output << "aux_vars.push_back(" << "av" << i << ");" << endl;
|
|
|
|
}
|
2013-08-06 21:20:36 +02:00
|
|
|
|
2015-08-11 12:10:44 +02:00
|
|
|
for (set<int>::const_iterator it = predetermined_variables.begin();
|
|
|
|
it != predetermined_variables.end(); it++)
|
|
|
|
output << "predetermined_variables.push_back(" << getTypeSpecificID(*it) << ");" << endl;
|
2013-08-06 21:20:36 +02:00
|
|
|
|
2015-08-11 12:10:44 +02:00
|
|
|
for (vector<int>::const_iterator it = varobs.begin();
|
|
|
|
it != varobs.end(); it++)
|
|
|
|
output << "varobs.push_back(" << getTypeSpecificID(*it) << ");" << endl;
|
2013-08-06 21:20:36 +02:00
|
|
|
}
|
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addLeadAuxiliaryVarInternal(bool endo, int index, expr_t expr_arg) throw (FrozenException)
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
|
|
|
ostringstream varname;
|
2009-10-07 18:34:42 +02:00
|
|
|
if (endo)
|
|
|
|
varname << "AUX_ENDO_LEAD_";
|
|
|
|
else
|
|
|
|
varname << "AUX_EXO_LEAD_";
|
|
|
|
varname << index;
|
2009-09-30 17:10:31 +02:00
|
|
|
int symb_id;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
symb_id = addSymbol(varname.str(), eEndogenous);
|
|
|
|
}
|
2009-12-16 18:13:23 +01:00
|
|
|
catch (AlreadyDeclaredException &e)
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
|
|
|
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:55:14 +01:00
|
|
|
aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLead : avExoLead), 0, 0, 0, 0, expr_arg));
|
2009-09-30 17:10:31 +02:00
|
|
|
|
|
|
|
return symb_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addLagAuxiliaryVarInternal(bool endo, int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (FrozenException)
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
|
|
|
ostringstream varname;
|
2009-10-07 18:34:42 +02:00
|
|
|
if (endo)
|
|
|
|
varname << "AUX_ENDO_LAG_";
|
|
|
|
else
|
|
|
|
varname << "AUX_EXO_LAG_";
|
2010-09-07 17:12:06 +02:00
|
|
|
varname << orig_symb_id << "_" << -orig_lead_lag;
|
2009-10-07 16:07:13 +02:00
|
|
|
|
2009-09-30 17:10:31 +02:00
|
|
|
int symb_id;
|
|
|
|
try
|
|
|
|
{
|
|
|
|
symb_id = addSymbol(varname.str(), eEndogenous);
|
|
|
|
}
|
2009-12-16 18:13:23 +01:00
|
|
|
catch (AlreadyDeclaredException &e)
|
2009-09-30 17:10:31 +02:00
|
|
|
{
|
|
|
|
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:55:14 +01:00
|
|
|
aux_vars.push_back(AuxVarInfo(symb_id, (endo ? avEndoLag : avExoLag), orig_symb_id, orig_lead_lag, 0, 0, expr_arg));
|
2009-09-30 17:10:31 +02:00
|
|
|
|
|
|
|
return symb_id;
|
2006-11-05 00:31:17 +01:00
|
|
|
}
|
2009-10-07 16:07:13 +02:00
|
|
|
|
2009-10-07 18:34:42 +02:00
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addEndoLeadAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException)
|
2009-10-07 18:34:42 +02:00
|
|
|
{
|
2016-03-18 14:55:14 +01:00
|
|
|
return addLeadAuxiliaryVarInternal(true, index, expr_arg);
|
2009-10-07 18:34:42 +02:00
|
|
|
}
|
|
|
|
|
2009-10-07 16:07:13 +02:00
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addEndoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (FrozenException)
|
2009-10-07 16:07:13 +02:00
|
|
|
{
|
2016-03-18 14:55:14 +01:00
|
|
|
return addLagAuxiliaryVarInternal(true, orig_symb_id, orig_lead_lag, expr_arg);
|
2009-10-07 16:07:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addExoLeadAuxiliaryVar(int index, expr_t expr_arg) throw (FrozenException)
|
2009-10-07 16:07:13 +02:00
|
|
|
{
|
2016-03-18 14:55:14 +01:00
|
|
|
return addLeadAuxiliaryVarInternal(false, index, expr_arg);
|
2009-10-07 16:07:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addExoLagAuxiliaryVar(int orig_symb_id, int orig_lead_lag, expr_t expr_arg) throw (FrozenException)
|
2009-10-07 16:07:13 +02:00
|
|
|
{
|
2016-03-18 14:55:14 +01:00
|
|
|
return addLagAuxiliaryVarInternal(false, orig_symb_id, orig_lead_lag, expr_arg);
|
2009-10-07 16:07:13 +02:00
|
|
|
}
|
2009-10-29 18:16:10 +01:00
|
|
|
|
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addExpectationAuxiliaryVar(int information_set, int index, expr_t expr_arg) throw (FrozenException)
|
2009-10-29 18:16:10 +01:00
|
|
|
{
|
|
|
|
ostringstream varname;
|
|
|
|
int symb_id;
|
2010-01-18 23:08:44 +01:00
|
|
|
|
2011-10-25 16:46:12 +02:00
|
|
|
varname << "AUX_EXPECT_" << (information_set < 0 ? "LAG" : "LEAD") << "_"
|
|
|
|
<< abs(information_set) << "_" << index;
|
2010-01-18 23:08:44 +01:00
|
|
|
|
2009-10-29 18:16:10 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
symb_id = addSymbol(varname.str(), eEndogenous);
|
|
|
|
}
|
2009-12-16 18:13:23 +01:00
|
|
|
catch (AlreadyDeclaredException &e)
|
2009-10-29 18:16:10 +01:00
|
|
|
{
|
|
|
|
cerr << "ERROR: you should rename your variable called " << varname.str() << ", this name is internally used by Dynare" << endl;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:55:14 +01:00
|
|
|
aux_vars.push_back(AuxVarInfo(symb_id, avExpectation, 0, 0, 0, information_set, expr_arg));
|
2011-03-21 18:40:57 +01:00
|
|
|
|
|
|
|
return symb_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SymbolTable::addMultiplierAuxiliaryVar(int index) throw (FrozenException)
|
|
|
|
{
|
|
|
|
ostringstream varname;
|
|
|
|
int symb_id;
|
2011-05-24 15:51:38 +02:00
|
|
|
varname << "MULT_" << index+1;
|
2011-03-21 18:40:57 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2009-10-29 18:16:10 +01:00
|
|
|
|
2015-05-26 15:47:56 +02:00
|
|
|
aux_vars.push_back(AuxVarInfo(symb_id, avMultiplier, 0, 0, index, 0, NULL));
|
2009-10-29 18:16:10 +01:00
|
|
|
return symb_id;
|
|
|
|
}
|
2009-11-09 12:03:18 +01:00
|
|
|
|
2013-04-25 18:09:31 +02:00
|
|
|
int
|
2016-03-18 14:55:14 +01:00
|
|
|
SymbolTable::addDiffForwardAuxiliaryVar(int orig_symb_id, expr_t expr_arg) throw (FrozenException)
|
2013-04-25 18:09:31 +02:00
|
|
|
{
|
|
|
|
ostringstream varname;
|
|
|
|
int symb_id;
|
|
|
|
varname << "AUX_DIFF_FWRD_" << orig_symb_id+1;
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2016-03-18 14:55:14 +01:00
|
|
|
aux_vars.push_back(AuxVarInfo(symb_id, avDiffForward, orig_symb_id, 0, 0, 0, expr_arg));
|
2013-04-25 18:09:31 +02:00
|
|
|
return symb_id;
|
|
|
|
}
|
|
|
|
|
2011-02-04 16:25:38 +01:00
|
|
|
int
|
2010-10-20 14:47:03 +02:00
|
|
|
SymbolTable::searchAuxiliaryVars(int orig_symb_id, int orig_lead_lag) const throw (SearchFailedException)
|
2010-09-10 11:43:48 +02:00
|
|
|
{
|
2010-10-20 14:47:03 +02:00
|
|
|
for (size_t i = 0; i < aux_vars.size(); i++)
|
2010-10-20 11:39:09 +02:00
|
|
|
if ((aux_vars[i].get_type() == avEndoLag || aux_vars[i].get_type() == avExoLag)
|
|
|
|
&& aux_vars[i].get_orig_symb_id() == orig_symb_id && aux_vars[i].get_orig_lead_lag() == orig_lead_lag)
|
2010-09-10 11:43:48 +02:00
|
|
|
return aux_vars[i].get_symb_id();
|
2010-10-20 14:47:03 +02:00
|
|
|
throw SearchFailedException(orig_symb_id, orig_lead_lag);
|
2010-09-10 11:43:48 +02:00
|
|
|
}
|
|
|
|
|
2016-03-18 14:55:14 +01:00
|
|
|
expr_t
|
|
|
|
SymbolTable::getAuxiliaryVarsExprNode(int symb_id) const throw (SearchFailedException)
|
|
|
|
// throw exception if it is a Lagrange multiplier
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < aux_vars.size(); i++)
|
|
|
|
if (aux_vars[i].get_symb_id() == symb_id)
|
|
|
|
{
|
|
|
|
expr_t expr_node = aux_vars[i].get_expr_node();
|
|
|
|
if (expr_node != NULL)
|
|
|
|
return expr_node;
|
|
|
|
else
|
|
|
|
throw SearchFailedException(symb_id);
|
|
|
|
}
|
|
|
|
throw SearchFailedException(symb_id);
|
|
|
|
}
|
|
|
|
|
2009-11-09 12:03:18 +01:00
|
|
|
void
|
|
|
|
SymbolTable::markPredetermined(int symb_id) throw (UnknownSymbolIDException, FrozenException)
|
|
|
|
{
|
|
|
|
if (symb_id < 0 || symb_id >= size)
|
|
|
|
throw UnknownSymbolIDException(symb_id);
|
|
|
|
if (frozen)
|
|
|
|
throw FrozenException();
|
|
|
|
|
|
|
|
assert(getType(symb_id) == eEndogenous);
|
|
|
|
|
|
|
|
predetermined_variables.insert(symb_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SymbolTable::isPredetermined(int symb_id) const throw (UnknownSymbolIDException)
|
|
|
|
{
|
|
|
|
if (symb_id < 0 || symb_id >= size)
|
|
|
|
throw UnknownSymbolIDException(symb_id);
|
|
|
|
|
2009-12-16 18:13:23 +01:00
|
|
|
return (predetermined_variables.find(symb_id) != predetermined_variables.end());
|
2009-11-09 12:03:18 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SymbolTable::predeterminedNbr() const
|
|
|
|
{
|
2009-12-16 18:13:23 +01:00
|
|
|
return (predetermined_variables.size());
|
2009-11-09 12:03:18 +01:00
|
|
|
}
|
2010-04-14 15:03:41 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SymbolTable::addObservedVariable(int symb_id) throw (UnknownSymbolIDException)
|
|
|
|
{
|
|
|
|
if (symb_id < 0 || symb_id >= size)
|
|
|
|
throw UnknownSymbolIDException(symb_id);
|
|
|
|
|
|
|
|
assert(getType(symb_id) == eEndogenous);
|
|
|
|
varobs.push_back(symb_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SymbolTable::observedVariablesNbr() const
|
|
|
|
{
|
|
|
|
return (int) varobs.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool
|
|
|
|
SymbolTable::isObservedVariable(int symb_id) const
|
|
|
|
{
|
|
|
|
return (find(varobs.begin(), varobs.end(), symb_id) != varobs.end());
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
SymbolTable::getObservedVariableIndex(int symb_id) const
|
|
|
|
{
|
|
|
|
vector<int>::const_iterator it = find(varobs.begin(), varobs.end(), symb_id);
|
|
|
|
assert(it != varobs.end());
|
|
|
|
return (int) (it - varobs.begin());
|
|
|
|
}
|
2010-10-15 19:05:16 +02:00
|
|
|
|
|
|
|
vector <int>
|
|
|
|
SymbolTable::getTrendVarIds() const
|
|
|
|
{
|
|
|
|
vector <int> trendVars;
|
|
|
|
for (symbol_table_type::const_iterator it = symbol_table.begin();
|
|
|
|
it != symbol_table.end(); it++)
|
2013-03-26 16:46:18 +01:00
|
|
|
if (getType(it->second) == eTrend || getType(it->second) == eLogTrend)
|
2010-10-15 19:05:16 +02:00
|
|
|
trendVars.push_back(it->second);
|
|
|
|
return trendVars;
|
|
|
|
}
|
2012-10-31 15:23:02 +01:00
|
|
|
|
|
|
|
set<int>
|
|
|
|
SymbolTable::getExogenous() const
|
|
|
|
{
|
|
|
|
set <int> exogs;
|
|
|
|
for (symbol_table_type::const_iterator it = symbol_table.begin();
|
|
|
|
it != symbol_table.end(); it++)
|
|
|
|
if (getType(it->second) == eExogenous)
|
|
|
|
exogs.insert(it->second);
|
|
|
|
return exogs;
|
|
|
|
}
|
|
|
|
|
|
|
|
set<int>
|
|
|
|
SymbolTable::getEndogenous() const
|
|
|
|
{
|
|
|
|
set <int> endogs;
|
|
|
|
for (symbol_table_type::const_iterator it = symbol_table.begin();
|
|
|
|
it != symbol_table.end(); it++)
|
|
|
|
if (getType(it->second) == eEndogenous)
|
|
|
|
endogs.insert(it->second);
|
|
|
|
return endogs;
|
|
|
|
}
|
2014-02-24 17:27:19 +01:00
|
|
|
|
|
|
|
bool
|
|
|
|
SymbolTable::isAuxiliaryVariable(int symb_id) const
|
|
|
|
{
|
2014-03-15 21:07:09 +01:00
|
|
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
2014-02-24 17:27:19 +01:00
|
|
|
if (aux_vars[i].get_symb_id() == symb_id)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-21 11:51:48 +01:00
|
|
|
bool
|
|
|
|
SymbolTable::isAuxiliaryVariableButNotMultiplier(int symb_id) const
|
|
|
|
{
|
|
|
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
|
|
|
if (aux_vars[i].get_symb_id() == symb_id && aux_vars[i].get_type() != avMultiplier)
|
|
|
|
return true;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-02-24 17:27:19 +01:00
|
|
|
set<int>
|
|
|
|
SymbolTable::getOrigEndogenous() const
|
|
|
|
{
|
|
|
|
set <int> origendogs;
|
|
|
|
for (symbol_table_type::const_iterator it = symbol_table.begin();
|
|
|
|
it != symbol_table.end(); it++)
|
|
|
|
if (getType(it->second) == eEndogenous && !isAuxiliaryVariable(it->second))
|
|
|
|
origendogs.insert(it->second);
|
|
|
|
return origendogs;
|
|
|
|
}
|
2015-07-21 17:47:56 +02:00
|
|
|
|
|
|
|
void
|
|
|
|
SymbolTable::writeJuliaOutput(ostream &output) const throw (NotYetFrozenException)
|
|
|
|
{
|
|
|
|
if (!frozen)
|
|
|
|
throw NotYetFrozenException();
|
|
|
|
|
2015-07-28 17:43:57 +02:00
|
|
|
output << "# Endogenous Variables" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "model_.endo = [" << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
if (endo_nbr() > 0)
|
|
|
|
for (int id = 0; id < endo_nbr(); id++)
|
2015-08-21 16:28:43 +02:00
|
|
|
output << " DynareModel.Endo(\""
|
2015-07-23 17:32:09 +02:00
|
|
|
<< getName(endo_ids[id]) << "\", \""
|
|
|
|
<< getTeXName(endo_ids[id]) << "\", \""
|
2015-07-28 17:43:57 +02:00
|
|
|
<< getLongName(endo_ids[id]) << "\")" << endl;
|
2015-08-21 16:28:43 +02:00
|
|
|
output << " ]" << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
|
2015-07-28 17:43:57 +02:00
|
|
|
output << "# Exogenous Variables" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "model_.exo = [" << endl;
|
2015-07-21 17:47:56 +02:00
|
|
|
if (exo_nbr() > 0)
|
2015-07-23 17:32:09 +02:00
|
|
|
for (int id = 0; id < exo_nbr(); id++)
|
2015-08-21 16:28:43 +02:00
|
|
|
output << " DynareModel.Exo(\""
|
2015-07-23 17:32:09 +02:00
|
|
|
<< getName(exo_ids[id]) << "\", \""
|
|
|
|
<< getTeXName(exo_ids[id]) << "\", \""
|
2015-07-28 17:43:57 +02:00
|
|
|
<< getLongName(exo_ids[id]) << "\")" << endl;
|
2015-08-21 16:28:43 +02:00
|
|
|
output << " ]" << endl;
|
2015-07-21 17:47:56 +02:00
|
|
|
|
|
|
|
if (exo_det_nbr() > 0)
|
2015-07-28 17:43:57 +02:00
|
|
|
{
|
|
|
|
output << "# Exogenous Deterministic Variables" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "model_.exo_det = [" << endl;
|
2015-07-28 17:43:57 +02:00
|
|
|
if (exo_det_nbr() > 0)
|
|
|
|
for (int id = 0; id < exo_det_nbr(); id++)
|
2015-07-29 11:35:10 +02:00
|
|
|
output << " DynareModel.ExoDet(\""
|
2015-07-28 17:43:57 +02:00
|
|
|
<< getName(exo_det_ids[id]) << "\", \""
|
|
|
|
<< getTeXName(exo_det_ids[id]) << "\", \""
|
|
|
|
<< getLongName(exo_det_ids[id]) << "\")" << endl;
|
2015-07-29 11:35:10 +02:00
|
|
|
output << " ]" << endl;
|
2015-07-28 17:43:57 +02:00
|
|
|
}
|
2015-07-21 17:47:56 +02:00
|
|
|
|
2015-07-28 17:43:57 +02:00
|
|
|
output << "# Parameters" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "model_.param = [" << endl;
|
2015-07-21 17:47:56 +02:00
|
|
|
if (param_nbr() > 0)
|
2015-07-23 17:32:09 +02:00
|
|
|
for (int id = 0; id < param_nbr(); id++)
|
2015-08-21 16:28:43 +02:00
|
|
|
output << " DynareModel.Param(\""
|
2015-07-23 17:32:09 +02:00
|
|
|
<< getName(param_ids[id]) << "\", \""
|
|
|
|
<< getTeXName(param_ids[id]) << "\", \""
|
2015-07-28 17:43:57 +02:00
|
|
|
<< getLongName(param_ids[id]) << "\")" << endl;
|
2015-08-21 16:28:43 +02:00
|
|
|
output << " ]" << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
|
2016-05-19 18:32:48 +02:00
|
|
|
output << "model_.orig_endo_nbr = " << orig_endo_nbr() << endl;
|
2015-07-21 17:47:56 +02:00
|
|
|
|
2015-07-23 17:32:09 +02:00
|
|
|
if (aux_vars.size() > 0)
|
2015-07-29 11:51:27 +02:00
|
|
|
{
|
|
|
|
output << "# Auxiliary Variables" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "model_.aux_vars = [" << endl;
|
2015-07-29 11:51:27 +02:00
|
|
|
for (int i = 0; i < (int) aux_vars.size(); i++)
|
|
|
|
{
|
|
|
|
output << " DynareModel.AuxVars("
|
|
|
|
<< getTypeSpecificID(aux_vars[i].get_symb_id()) + 1 << ", "
|
|
|
|
<< aux_vars[i].get_type() << ", ";
|
|
|
|
switch (aux_vars[i].get_type())
|
|
|
|
{
|
|
|
|
case avEndoLead:
|
|
|
|
case avExoLead:
|
|
|
|
break;
|
|
|
|
case avEndoLag:
|
|
|
|
case avExoLag:
|
|
|
|
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id()) + 1 << ", "
|
|
|
|
<< aux_vars[i].get_orig_lead_lag() << ", NaN, NaN";
|
|
|
|
break;
|
|
|
|
case avMultiplier:
|
|
|
|
output << "NaN, NaN, " << aux_vars[i].get_equation_number_for_multiplier() + 1
|
|
|
|
<< ", NaN";
|
|
|
|
break;
|
|
|
|
case avDiffForward:
|
|
|
|
output << getTypeSpecificID(aux_vars[i].get_orig_symb_id())+1 << ", NaN, ";
|
|
|
|
break;
|
|
|
|
case avExpectation:
|
|
|
|
output << "NaN, NaN, NaN, \"\\mathbb{E}_{t"
|
|
|
|
<< (aux_vars[i].get_information_set() < 0 ? "" : "+")
|
|
|
|
<< aux_vars[i].get_information_set() << "}(";
|
2016-03-18 14:55:14 +01:00
|
|
|
aux_vars[i].get_expr_node()->writeOutput(output, oLatexDynamicModel);
|
2015-07-29 11:51:27 +02:00
|
|
|
output << ")\"";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
output << ")" << endl;
|
|
|
|
}
|
|
|
|
output << "]" << endl;
|
|
|
|
}
|
2015-07-23 17:32:09 +02:00
|
|
|
|
|
|
|
if (predeterminedNbr() > 0)
|
|
|
|
{
|
2015-07-29 11:51:27 +02:00
|
|
|
output << "# Predetermined Variables" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "model_.pred_vars = [ " << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
for (set<int>::const_iterator it = predetermined_variables.begin();
|
|
|
|
it != predetermined_variables.end(); it++)
|
2015-07-29 11:51:27 +02:00
|
|
|
output << " DynareModel.PredVars("
|
|
|
|
<< getTypeSpecificID(*it)+1 << ")" << endl;
|
|
|
|
output << " ]" << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (observedVariablesNbr() > 0)
|
|
|
|
{
|
2015-07-29 11:51:27 +02:00
|
|
|
output << "# Observed Variables" << endl
|
2016-05-19 18:32:48 +02:00
|
|
|
<< "options_.obs_vars = [" << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
for (vector<int>::const_iterator it = varobs.begin();
|
|
|
|
it != varobs.end(); it++)
|
2015-07-29 11:51:27 +02:00
|
|
|
output << " DynareModel.ObsVars("
|
|
|
|
<< getTypeSpecificID(*it)+1 << ")" << endl;
|
|
|
|
output << " ]" << endl;
|
2015-07-23 17:32:09 +02:00
|
|
|
}
|
2015-07-21 17:47:56 +02:00
|
|
|
}
|