2008-02-03 11:28:36 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2003-2008 Dynare Team
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-08-24 12:54:20 +02:00
|
|
|
#include <cstdlib>
|
|
|
|
|
2008-02-03 11:28:36 +01:00
|
|
|
#include "VariableTable.hh"
|
|
|
|
|
|
|
|
VariableTable::VariableTable(const SymbolTable &symbol_table_arg) :
|
|
|
|
symbol_table(symbol_table_arg),
|
|
|
|
var_endo_nbr(0), var_exo_nbr(0), var_exo_det_nbr(0),
|
|
|
|
max_lag(0), max_lead(0),
|
|
|
|
max_endo_lag(0), max_endo_lead(0),
|
|
|
|
max_exo_lag(0), max_exo_lead(0),
|
|
|
|
max_exo_det_lag(0), max_exo_det_lead(0),
|
|
|
|
max_recur_lag(0), max_recur_lead(0)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2008-08-24 12:54:20 +02:00
|
|
|
VariableTable::addVariable(Type type, int symb_id, int lag) throw (DynJacobianColsAlreadyComputedException)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2008-08-24 12:54:20 +02:00
|
|
|
if (dyn_jacobian_cols_table.size() != 0)
|
|
|
|
throw DynJacobianColsAlreadyComputedException();
|
2008-02-03 11:28:36 +01:00
|
|
|
|
|
|
|
var_key_type key = make_pair(make_pair(type, lag), symb_id);
|
|
|
|
|
|
|
|
// Testing if variable already exists
|
|
|
|
variable_table_type::const_iterator it = variable_table.find(key);
|
|
|
|
if (it != variable_table.end())
|
|
|
|
return it->second;
|
|
|
|
|
|
|
|
int var_id = size();
|
|
|
|
|
|
|
|
variable_table[key] = var_id;
|
|
|
|
inv_variable_table[var_id] = key;
|
|
|
|
|
|
|
|
// Setting maximum and minimum lags
|
|
|
|
if (max_lead < lag)
|
|
|
|
max_lead = lag;
|
|
|
|
else if (-max_lag > lag)
|
|
|
|
max_lag = -lag;
|
|
|
|
|
|
|
|
switch(type)
|
|
|
|
{
|
|
|
|
case eEndogenous:
|
2008-08-24 12:54:20 +02:00
|
|
|
var_endo_nbr++;
|
2008-02-03 11:28:36 +01:00
|
|
|
if (max_endo_lead < lag)
|
|
|
|
max_endo_lead = lag;
|
|
|
|
else if (-max_endo_lag > lag)
|
|
|
|
max_endo_lag = -lag;
|
|
|
|
break;
|
|
|
|
case eExogenous:
|
2008-08-24 12:54:20 +02:00
|
|
|
var_exo_nbr++;
|
2008-02-03 11:28:36 +01:00
|
|
|
if (max_exo_lead < lag)
|
|
|
|
max_exo_lead = lag;
|
|
|
|
else if (-max_exo_lag > lag)
|
|
|
|
max_exo_lag = -lag;
|
|
|
|
break;
|
|
|
|
case eExogenousDet:
|
2008-08-24 12:54:20 +02:00
|
|
|
var_exo_det_nbr++;
|
2008-02-03 11:28:36 +01:00
|
|
|
if (max_exo_det_lead < lag)
|
|
|
|
max_exo_det_lead = lag;
|
|
|
|
else if (-max_exo_det_lag > lag)
|
|
|
|
max_exo_det_lag = -lag;
|
|
|
|
break;
|
|
|
|
case eRecursiveVariable:
|
|
|
|
if (max_recur_lead < lag)
|
|
|
|
max_recur_lead = lag;
|
|
|
|
else if (-max_recur_lag > lag)
|
|
|
|
max_recur_lag = -lag;
|
|
|
|
break;
|
|
|
|
default:
|
2008-08-24 12:54:20 +02:00
|
|
|
cerr << "VariableTable::addVariable(): forbidden variable type" << endl;
|
|
|
|
exit(-1);
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|
|
|
|
return var_id;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2008-08-24 12:54:20 +02:00
|
|
|
VariableTable::computeDynJacobianCols() throw (DynJacobianColsAlreadyComputedException)
|
2008-02-03 11:28:36 +01:00
|
|
|
{
|
2008-08-24 12:54:20 +02:00
|
|
|
if (dyn_jacobian_cols_table.size() != 0)
|
|
|
|
throw DynJacobianColsAlreadyComputedException();
|
|
|
|
|
|
|
|
dyn_jacobian_cols_table.resize(size());
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2008-08-24 12:54:20 +02:00
|
|
|
variable_table_type::const_iterator it = variable_table.begin();
|
|
|
|
|
|
|
|
// Assign the first columns to endogenous, using the lexicographic order over (lag, symbol_id) implemented in variable_table map
|
2008-02-03 11:28:36 +01:00
|
|
|
int sorted_id = 0;
|
2008-08-25 21:57:21 +02:00
|
|
|
while(it->first.first.first == eEndogenous && it != variable_table.end())
|
2008-08-24 12:54:20 +02:00
|
|
|
{
|
|
|
|
dyn_jacobian_cols_table[it->second] = sorted_id++;
|
|
|
|
it++;
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
|
2008-08-24 12:54:20 +02:00
|
|
|
// Assign subsequent columns to exogenous and then exogenous deterministic, using an offset + symbol_id
|
2008-08-25 21:57:21 +02:00
|
|
|
while(it->first.first.first == eExogenous && it != variable_table.end())
|
2008-08-24 12:54:20 +02:00
|
|
|
{
|
|
|
|
dyn_jacobian_cols_table[it->second] = var_endo_nbr + it->first.second;
|
|
|
|
it++;
|
|
|
|
}
|
2008-08-25 21:57:21 +02:00
|
|
|
while(it->first.first.first == eExogenousDet && it != variable_table.end())
|
2008-08-24 12:54:20 +02:00
|
|
|
{
|
|
|
|
dyn_jacobian_cols_table[it->second] = var_endo_nbr + symbol_table.exo_nbr + it->first.second;
|
|
|
|
it++;
|
|
|
|
}
|
2008-02-03 11:28:36 +01:00
|
|
|
}
|