trunk StaticModel.cc: added model normalization (still need to force normalization of equations of the form a = f(b,c))

git-svn-id: https://www.dynare.org/svn/dynare/trunk@2638 ac1d8469-bf42-47a9-8791-bf33cf982152
issue#70
sebastien 2009-04-27 17:15:14 +00:00
parent 02d388d6b9
commit 261f08dce3
3 changed files with 58 additions and 2 deletions

View File

@ -140,10 +140,19 @@ public:
void writeOutput(ostream &output);
//! Computes the set of endogenous variables in the expression
/*! Endogenous are stored as integer pairs of the form (symb_id, lag)
They are added to the set given in argument */
/*!
Endogenous are stored as integer pairs of the form (symb_id, lag).
They are added to the set given in argument.
*/
virtual void collectEndogenous(set<pair<int, int> > &result) const = 0;
//! Computes the set of exogenous variables in the expression
/*!
Exogenous are stored as integer pairs of the form (symb_id, lag).
They are added to the set given in argument.
*/
virtual void collectExogenous(set<pair<int, int> > &result) const = 0;
virtual void collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const = 0;
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
temporary_terms_type &temporary_terms,

View File

@ -18,9 +18,15 @@
*/
#include <cstdlib>
#include <cassert>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/max_cardinality_matching.hpp>
#include "StaticModel.hh"
using namespace boost;
StaticModel::StaticModel(SymbolTable &symbol_table_arg,
NumericalConstants &num_constants_arg) :
ModelTree(symbol_table_arg, num_constants_arg)
@ -305,3 +311,41 @@ StaticModel::getDerivID(int symb_id, int lag) const throw (UnknownDerivIDExcepti
else
throw UnknownDerivIDException();
}
void
StaticModel::computeNormalization()
{
int n = equation_number();
assert(n == symbol_table.endo_nbr());
typedef adjacency_list<vecS, vecS, undirectedS> BipartiteGraph;
/*
Vertices 0 to n-1 are for endogenous (using type specific ID)
Vertices n to 2*n-1 are for equations (using equation no.)
*/
BipartiteGraph g(2 * n);
// Fill in the graph
set<pair<int, int> > endo;
for(int i = 0; i < n; i++)
{
endo.clear();
equations[i]->collectEndogenous(endo);
for(set<pair<int, int> >::const_iterator it = endo.begin();
it != endo.end(); it++)
add_edge(i + n, symbol_table.getTypeSpecificID(it->first), g);
}
// Compute maximum cardinality matching
vector<graph_traits<BipartiteGraph>::vertex_descriptor> mate_map(2*n);
bool check = checked_edmonds_maximum_cardinality_matching(g, &mate_map[0]);
assert(check);
for(int i = 0; i < n; i++)
cout << "Endogenous " << symbol_table.getName(symbol_table.getID(eEndogenous, i)) << " matched with equation "
<< (mate_map[i]-n+1) << endl;
}

View File

@ -39,6 +39,9 @@ private:
virtual int computeDerivID(int symb_id, int lag);
//! Computes normalization of the static model
void computeNormalization();
public:
StaticModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
//! Execute computations (derivation)