2009-05-19 10:57:07 +02:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2009 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/>.
|
|
|
|
*/
|
|
|
|
|
2009-06-30 16:43:59 +02:00
|
|
|
#ifndef _MINIMUMFEEDBACKSET_HH
|
|
|
|
#define _MINIMUMFEEDBACKSET_HH
|
2009-05-13 01:03:40 +02:00
|
|
|
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
#include <boost/graph/graphviz.hpp>
|
|
|
|
#include <boost/graph/adjacency_list.hpp>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace boost;
|
|
|
|
|
2009-06-30 16:43:59 +02:00
|
|
|
namespace MFS
|
|
|
|
{
|
2009-05-13 01:03:40 +02:00
|
|
|
typedef property<vertex_index_t, int,
|
2009-12-16 18:13:23 +01:00
|
|
|
property<vertex_index1_t, int,
|
|
|
|
property<vertex_degree_t, int,
|
|
|
|
property<vertex_in_degree_t, int,
|
|
|
|
property<vertex_out_degree_t, int > > > > > VertexProperty;
|
2009-05-13 01:03:40 +02:00
|
|
|
typedef adjacency_list<listS, listS, bidirectionalS, VertexProperty> AdjacencyList_type;
|
2009-12-16 18:13:23 +01:00
|
|
|
typedef map<graph_traits<AdjacencyList_type>::vertex_descriptor, default_color_type> color_type;
|
2009-05-13 01:03:40 +02:00
|
|
|
typedef vector<AdjacencyList_type::vertex_descriptor> vector_vertex_descriptor;
|
|
|
|
|
2009-06-30 16:43:59 +02:00
|
|
|
//! Eliminate a vertex i
|
2009-06-05 17:04:09 +02:00
|
|
|
/*! For a vertex i replace all edges e_k_i and e_i_j by a shorcut e_k_j and then Suppress the vertex i*/
|
2009-12-16 18:13:23 +01:00
|
|
|
void Eliminate(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type &G);
|
2009-06-30 16:43:59 +02:00
|
|
|
//! Collect all doublets (edges e_i_k such that there is an edge e_k_i with k!=i in the graph)
|
|
|
|
/*! Returns the vector of doublets */
|
2009-12-16 18:13:23 +01:00
|
|
|
vector_vertex_descriptor Collect_Doublet(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type &G);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Detect all the clique (all vertex in a clique are related to each other) in the graph
|
2009-12-16 18:13:23 +01:00
|
|
|
bool Vertex_Belong_to_a_Clique(AdjacencyList_type::vertex_descriptor vertex, AdjacencyList_type &G);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Graph reduction: eliminating purely intermediate variables or variables outside of any circuit
|
2009-12-16 18:13:23 +01:00
|
|
|
bool Elimination_of_Vertex_With_One_or_Less_Indegree_or_Outdegree_Step(AdjacencyList_type &G);
|
2009-06-30 16:43:59 +02:00
|
|
|
//! Graph reduction: elimination of a vertex inside a clique
|
2009-12-16 18:13:23 +01:00
|
|
|
bool Elimination_of_Vertex_belonging_to_a_clique_Step(AdjacencyList_type &G);
|
2009-06-30 16:43:59 +02:00
|
|
|
//! A vertex belong to the feedback vertex set if the vertex loops on itself.
|
2009-06-05 17:04:09 +02:00
|
|
|
/*! We have to suppress this vertex and store it into the feedback set.*/
|
2009-12-16 18:13:23 +01:00
|
|
|
bool Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(set<int> &feed_back_vertices, AdjacencyList_type &G1);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Print the Graph
|
2009-12-16 18:13:23 +01:00
|
|
|
void Print(GraphvizDigraph &G);
|
|
|
|
void Print(AdjacencyList_type &G);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Create a GraphvizDigraph from a Adjacency Matrix (an incidence Matrix without the diagonal terms)
|
2009-12-16 18:13:23 +01:00
|
|
|
GraphvizDigraph AM_2_GraphvizDigraph(bool *AM, unsigned int n);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Create an adjacency graph from a Adjacency Matrix (an incidence Matrix without the diagonal terms)
|
2009-12-16 18:13:23 +01:00
|
|
|
AdjacencyList_type AM_2_AdjacencyList(bool *AMp, unsigned int n);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Create an adjacency graph from a GraphvizDigraph
|
2009-12-16 18:13:23 +01:00
|
|
|
AdjacencyList_type GraphvizDigraph_2_AdjacencyList(GraphvizDigraph &G1, set<int> select_index);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Check if the graph contains any cycle (true if the model contains at least one cycle, false otherwise)
|
2009-12-16 18:13:23 +01:00
|
|
|
bool has_cycle(vector<int> &circuit_stack, AdjacencyList_type &g);
|
|
|
|
bool has_cycle_dfs(AdjacencyList_type &g, AdjacencyList_type::vertex_descriptor u, color_type &color, vector<int> &circuit_stack);
|
2009-06-05 16:45:23 +02:00
|
|
|
//! Return the feedback set
|
2009-12-16 18:13:23 +01:00
|
|
|
AdjacencyList_type Minimal_set_of_feedback_vertex(set<int> &feed_back_vertices, const AdjacencyList_type &G);
|
2009-06-30 16:43:59 +02:00
|
|
|
//! Clear all in and out edges of vertex_to_eliminate and remove vertex_to_eliminate from the graph
|
2009-12-16 18:13:23 +01:00
|
|
|
void Suppress(AdjacencyList_type::vertex_descriptor vertex_to_eliminate, AdjacencyList_type &G);
|
|
|
|
void Suppress(int vertex_num, AdjacencyList_type &G);
|
2009-06-30 16:43:59 +02:00
|
|
|
//! Reorder the recursive variables
|
|
|
|
/*! They appear first in a quasi triangular form and they are followed by the feedback variables */
|
2009-12-16 18:13:23 +01:00
|
|
|
void Reorder_the_recursive_variables(const AdjacencyList_type &G1, set<int> &feedback_vertices, vector< int> &Reordered_Vertices);
|
2009-05-13 01:03:40 +02:00
|
|
|
};
|
|
|
|
|
2009-06-30 16:43:59 +02:00
|
|
|
#endif // _MINIMUMFEEDBACKSET_HH
|