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-bf33cf982152time-shift
parent
c637255023
commit
5cc4e16ebf
|
@ -140,10 +140,19 @@ public:
|
||||||
void writeOutput(ostream &output);
|
void writeOutput(ostream &output);
|
||||||
|
|
||||||
//! Computes the set of endogenous variables in the expression
|
//! 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;
|
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 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 collectTemporary_terms(const temporary_terms_type &temporary_terms, Model_Block *ModelBlock, int Curr_Block) const = 0;
|
||||||
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
virtual void computeTemporaryTerms(map<NodeID, int> &reference_count,
|
||||||
temporary_terms_type &temporary_terms,
|
temporary_terms_type &temporary_terms,
|
||||||
|
|
|
@ -18,9 +18,15 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include <boost/graph/adjacency_list.hpp>
|
||||||
|
#include <boost/graph/max_cardinality_matching.hpp>
|
||||||
|
|
||||||
#include "StaticModel.hh"
|
#include "StaticModel.hh"
|
||||||
|
|
||||||
|
using namespace boost;
|
||||||
|
|
||||||
StaticModel::StaticModel(SymbolTable &symbol_table_arg,
|
StaticModel::StaticModel(SymbolTable &symbol_table_arg,
|
||||||
NumericalConstants &num_constants_arg) :
|
NumericalConstants &num_constants_arg) :
|
||||||
ModelTree(symbol_table_arg, 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
|
else
|
||||||
throw UnknownDerivIDException();
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -39,6 +39,9 @@ private:
|
||||||
|
|
||||||
virtual int computeDerivID(int symb_id, int lag);
|
virtual int computeDerivID(int symb_id, int lag);
|
||||||
|
|
||||||
|
//! Computes normalization of the static model
|
||||||
|
void computeNormalization();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
StaticModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
|
StaticModel(SymbolTable &symbol_table_arg, NumericalConstants &num_constants);
|
||||||
//! Execute computations (derivation)
|
//! Execute computations (derivation)
|
||||||
|
|
Loading…
Reference in New Issue