From 8af9e0dd9587b29fea6b84938fc8c93307c6fe4f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien.villemot@ens.fr> Date: Mon, 13 Dec 2010 14:23:04 +0100 Subject: [PATCH] Preprocessor: no longer use boost::graph::GraphvizDigraph class, removed in Boost 1.44 (closes #155) --- MinimumFeedbackSet.cc | 57 +++++++++---------------------------------- MinimumFeedbackSet.hh | 19 +++++++++------ ModelTree.cc | 29 +++++++++++++--------- 3 files changed, 42 insertions(+), 63 deletions(-) diff --git a/MinimumFeedbackSet.cc b/MinimumFeedbackSet.cc index 8456823c..19b1537b 100644 --- a/MinimumFeedbackSet.cc +++ b/MinimumFeedbackSet.cc @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Dynare Team + * Copyright (C) 2009-2010 Dynare Team * * This file is part of Dynare. * @@ -135,65 +135,32 @@ namespace MFS return G; } - void - Print(GraphvizDigraph &G) - { - GraphvizDigraph::vertex_iterator it, it_end; - property_map<GraphvizDigraph, vertex_index_t>::type v_index = get(vertex_index, G); - cout << "Graph\n"; - cout << "-----\n"; - for (tie(it, it_end) = vertices(G); it != it_end; ++it) - { - cout << "vertex[" << v_index[*it] + 1 << "] ->"; - GraphvizDigraph::out_edge_iterator it_out, out_end; - for (tie(it_out, out_end) = out_edges(*it, G); it_out != out_end; ++it_out) - cout << v_index[target(*it_out, G)] + 1 << " "; - cout << "\n"; - } - } - - GraphvizDigraph - AM_2_GraphvizDigraph(bool *AM, unsigned int n) - { - GraphvizDigraph G(n); - property_map<GraphvizDigraph, vertex_index_t>::type v_index = get(vertex_index, G); - /*for (unsigned int i = 0;i < n;i++) - cout << "v_index[" << i << "] = " << v_index[i] << "\n";*/ - //put(v_index, vertex(i, G), i); - //v_index[/*vertex(i,G)*/i]["v_index"]=i; - for (unsigned int i = 0; i < n; i++) - for (unsigned int j = 0; j < n; j++) - if (AM[i*n+j]) - add_edge(vertex(j, G), vertex(i, G), G); - return G; - } - AdjacencyList_t - GraphvizDigraph_2_AdjacencyList(GraphvizDigraph &G1, set<int> select_index) + extract_subgraph(AdjacencyList_t &G1, set<int> select_index) { unsigned int n = select_index.size(); AdjacencyList_t G(n); property_map<AdjacencyList_t, vertex_index_t>::type v_index = get(vertex_index, G); property_map<AdjacencyList_t, vertex_index1_t>::type v_index1 = get(vertex_index1, G); - property_map<GraphvizDigraph, vertex_index_t>::type v1_index = get(vertex_index, G1); - set<int>::iterator it = select_index.begin(); + property_map<AdjacencyList_t, vertex_index_t>::type v1_index = get(vertex_index, G1); map<int, int> reverse_index; - for (unsigned int i = 0; i < n; i++, ++it) + set<int>::iterator it; + unsigned int i; + for (it = select_index.begin(), i = 0; i < n; i++, ++it) { - reverse_index[v1_index[*it]] = i; - put(v_index, vertex(i, G), v1_index[*it]); + reverse_index[get(v1_index, vertex(*it, G1))] = i; + put(v_index, vertex(i, G), get(v1_index, vertex(*it, G1))); put(v_index1, vertex(i, G), i); } - unsigned int i; for (it = select_index.begin(), i = 0; i < n; i++, ++it) { - GraphvizDigraph::out_edge_iterator it_out, out_end; - GraphvizDigraph::vertex_descriptor vi = vertex(*it, G1); + AdjacencyList_t::out_edge_iterator it_out, out_end; + AdjacencyList_t::vertex_descriptor vi = vertex(*it, G1); for (tie(it_out, out_end) = out_edges(vi, G1); it_out != out_end; ++it_out) { - int ii = target(*it_out, G1); + int ii = v1_index[target(*it_out, G1)]; if (select_index.find(ii) != select_index.end()) - add_edge(vertex(reverse_index[source(*it_out, G1)], G), vertex(reverse_index[target(*it_out, G1)], G), G); + add_edge(vertex(reverse_index[get(v1_index, source(*it_out, G1))], G), vertex(reverse_index[get(v1_index, target(*it_out, G1))], G), G); } } return G; diff --git a/MinimumFeedbackSet.hh b/MinimumFeedbackSet.hh index 3d956cf9..066df3a7 100644 --- a/MinimumFeedbackSet.hh +++ b/MinimumFeedbackSet.hh @@ -1,5 +1,5 @@ /* - * Copyright (C) 2009 Dynare Team + * Copyright (C) 2009-2010 Dynare Team * * This file is part of Dynare. * @@ -22,7 +22,6 @@ #include <map> #include <vector> -#include <boost/graph/graphviz.hpp> #include <boost/graph/adjacency_list.hpp> using namespace std; @@ -55,14 +54,20 @@ namespace MFS /*! We have to suppress this vertex and store it into the feedback set.*/ bool Suppression_of_Vertex_X_if_it_loops_store_in_set_of_feedback_vertex_Step(set<int> &feed_back_vertices, AdjacencyList_t &G1); //! Print the Graph - void Print(GraphvizDigraph &G); void Print(AdjacencyList_t &G); - //! Create a GraphvizDigraph from a Adjacency Matrix (an incidence Matrix without the diagonal terms) - GraphvizDigraph AM_2_GraphvizDigraph(bool *AM, unsigned int n); //! Create an adjacency graph from a Adjacency Matrix (an incidence Matrix without the diagonal terms) AdjacencyList_t AM_2_AdjacencyList(bool *AMp, unsigned int n); - //! Create an adjacency graph from a GraphvizDigraph - AdjacencyList_t GraphvizDigraph_2_AdjacencyList(GraphvizDigraph &G1, set<int> select_index); + //! Extracts a subgraph + /*! + \param[in] G1 The original graph + \param[in] select_index The vertex indices to select + \return The subgraph + + The property vertex_index of the subgraph contains indices of the original + graph, the property vertex_index1 contains new contiguous indices specific + to the subgraph. + */ + AdjacencyList_t extract_subgraph(AdjacencyList_t &G1, set<int> select_index); //! Check if the graph contains any cycle (true if the model contains at least one cycle, false otherwise) bool has_cycle(vector<int> &circuit_stack, AdjacencyList_t &g); bool has_cycle_dfs(AdjacencyList_t &g, AdjacencyList_t::vertex_descriptor u, color_t &color, vector<int> &circuit_stack); diff --git a/ModelTree.cc b/ModelTree.cc index 289619ea..772bab24 100644 --- a/ModelTree.cc +++ b/ModelTree.cc @@ -512,9 +512,13 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob { int nb_var = variable_reordered.size(); int n = nb_var - prologue - epilogue; - typedef adjacency_list<vecS, vecS, directedS> DirectedGraph; - GraphvizDigraph G2(n); + AdjacencyList_t G2(n); + + // It is necessary to manually initialize vertex_index property since this graph uses listS and not vecS as underlying vertex container + property_map<AdjacencyList_t, vertex_index_t>::type v_index = get(vertex_index, G2); + for (int i = 0; i < n; i++) + put(v_index, vertex(i, G2), i); vector<int> reverse_equation_reordered(nb_var), reverse_variable_reordered(nb_var); @@ -528,12 +532,15 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob if (reverse_equation_reordered[it->first.first] >= prologue && reverse_equation_reordered[it->first.first] < nb_var - epilogue && reverse_variable_reordered[it->first.second] >= prologue && reverse_variable_reordered[it->first.second] < nb_var - epilogue && it->first.first != endo2eq[it->first.second]) - add_edge(reverse_equation_reordered[endo2eq[it->first.second]]-prologue, reverse_equation_reordered[it->first.first]-prologue, G2); + add_edge(vertex(reverse_equation_reordered[endo2eq[it->first.second]]-prologue, G2), + vertex(reverse_equation_reordered[it->first.first]-prologue, G2), + G2); vector<int> endo2block(num_vertices(G2)), discover_time(num_vertices(G2)); + iterator_property_map<int*, property_map<AdjacencyList_t, vertex_index_t>::type, int, int&> endo2block_map(&endo2block[0], get(vertex_index, G2)); // Compute strongly connected components - int num = strong_components(G2, &endo2block[0]); + int num = strong_components(G2, endo2block_map); blocks = vector<pair<int, int> >(num, make_pair(0, 0)); @@ -543,12 +550,12 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob for (unsigned int i = 0; i < num_vertices(G2); i++) { - GraphvizDigraph::out_edge_iterator it_out, out_end; - GraphvizDigraph::vertex_descriptor vi = vertex(i, G2); + AdjacencyList_t::out_edge_iterator it_out, out_end; + AdjacencyList_t::vertex_descriptor vi = vertex(i, G2); for (tie(it_out, out_end) = out_edges(vi, G2); it_out != out_end; ++it_out) { - int t_b = endo2block[target(*it_out, G2)]; - int s_b = endo2block[source(*it_out, G2)]; + int t_b = endo2block_map[target(*it_out, G2)]; + int s_b = endo2block_map[source(*it_out, G2)]; if (s_b != t_b) add_edge(s_b, t_b, dag); } @@ -589,13 +596,13 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob || equation_lag_lead[equation_reordered[i+prologue]].second > 0 || equation_lag_lead[equation_reordered[i+prologue]].first > 0 || mfs == 0) - add_edge(i, i, G2); + add_edge(vertex(i, G2), vertex(i, G2), G2); } else { for (int i = 0; i < n; i++) if (Equation_Type[equation_reordered[i+prologue]].first == E_SOLVE || mfs == 0) - add_edge(i, i, G2); + add_edge(vertex(i, G2), vertex(i, G2), G2); } //Determines the dynamic structure of each equation n_static = vector<unsigned int>(prologue+num+epilogue, 0); @@ -620,7 +627,7 @@ ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock(const jacob for (int i = 0; i < num; i++) { - AdjacencyList_t G = GraphvizDigraph_2_AdjacencyList(G2, components_set[i].first); + AdjacencyList_t G = extract_subgraph(G2, components_set[i].first); set<int> feed_back_vertices; //Print(G); AdjacencyList_t G1 = Minimal_set_of_feedback_vertex(feed_back_vertices, G); -- GitLab