diff --git a/ExprNode.hh b/ExprNode.hh index 1a427400..0383272a 100644 --- a/ExprNode.hh +++ b/ExprNode.hh @@ -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 > &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 > &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 &reference_count, temporary_terms_type &temporary_terms, diff --git a/StaticModel.cc b/StaticModel.cc index 838d7a0a..f125d56d 100644 --- a/StaticModel.cc +++ b/StaticModel.cc @@ -18,9 +18,15 @@ */ #include +#include + +#include +#include #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 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 > endo; + for(int i = 0; i < n; i++) + { + endo.clear(); + equations[i]->collectEndogenous(endo); + for(set >::const_iterator it = endo.begin(); + it != endo.end(); it++) + add_edge(i + n, symbol_table.getTypeSpecificID(it->first), g); + } + + // Compute maximum cardinality matching + vector::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; +} diff --git a/StaticModel.hh b/StaticModel.hh index 8c6dd119..5c7beb5b 100644 --- a/StaticModel.hh +++ b/StaticModel.hh @@ -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)