Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
BiconnectedTest.h
1 /*
2  *
3  * This file is part of Tulip (www.tulip-software.org)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
7  *
8  * Tulip is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License
10  * as published by the Free Software Foundation, either version 3
11  * of the License, or (at your option) any later version.
12  *
13  * Tulip is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU General Public License for more details.
17  *
18  */
19 
20 #ifndef TULIP_BICONNEX_H
21 #define TULIP_BICONNEX_H
22 
23 #include <tulip/MutableContainer.h>
24 #include <tulip/Observable.h>
25 
26 namespace tlp {
27 class Graph;
28 
29 /**
30  * @ingroup Checks
31  * @brief Performs a test of biconnexity on the graph, and provides a function to make a graph biconnected.
32  * From Wikipedia: "A biconnected graph is connected and nonseparable, meaning that if any vertex were to be removed, the graph will remain connected."
33  **/
34 class TLP_SCOPE BiconnectedTest : private Observable {
35 
36 public:
37  /**
38  * @brief Checks whether the graph is biconnected (i.e. removing one edge does not disconnect the graph, at least two must be removed).
39  *
40  * @param graph The graph to check for biconnectivity.
41  * @return bool True if the graph is biconnected, false otherwise.
42  **/
43  static bool isBiconnected(const Graph *graph);
44 
45  /**
46  * If the graph is not biconnected, adds edges in order to make the graph
47  * biconnected. The new edges are added in addedEdges.
48  */
49  /**
50  * @brief Adds edges to make the graph biconnected.
51  *
52  * @param graph The graph to make biconnected.
53  * @param addedEdges The edges that were added in the process.
54  * @return void
55  **/
56  static void makeBiconnected(Graph *graph, std::vector<edge>& addedEdges);
57 
58 private:
60 
61  /**
62  * @brief Makes the graph biconnected.
63  * Starts by making the graph connected (using ConnectgedTest::makeConnected()),
64  * then calls another function that will visit the graph using a recursive dfs algorithm and make it biconnected.
65  *
66  * @param graph The graph to make biconnected.
67  * @param addedEdges The edges that were added to make it biconnected.
68  * @return void
69  **/
70  void connect(Graph * graph, std::vector<edge>& addedEdges);
71 
72  /**
73  * @brief check if the graph is biconnected.
74  *
75  * @param graph the graph to check.
76  * @return bool true if the graph is biconnected, false otherwise.
77  **/
78  bool compute(const Graph * graph);
79 
80  //override of Observable::treatEvent to remove the cached result for a graph if it is modified.
81  virtual void treatEvent(const Event&);
82 
83  /**
84  * @brief Singleton instance of this class.
85  **/
86  static BiconnectedTest * instance;
87  /**
88  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
89  **/
90  TLP_HASH_MAP<unsigned long,bool> resultsBuffer;
91 };
92 }
93 
94 #endif