Tulip  4.1.0
Better Visualization Through Research
 All Classes Files Functions Variables Enumerations Enumerator Properties Groups Pages
ConnectedTest.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 
21 #ifndef TULIP_CONNECTEDTEST_H
22 #define TULIP_CONNECTEDTEST_H
23 
24 #include <set>
25 #include <vector>
26 #include <tulip/tuliphash.h>
27 #include <tulip/Observable.h>
28 
29 namespace tlp {
30 
31 class Graph;
32 
33 /**
34  * @ingroup Checks
35  * @brief @brief Performs a test of connexity on the graph, and provides a function to make a graph connected.
36  * From Wikipedia: "A graph is said to be connected if every pair of vertices in the graph are connected." (i.e. there is a path between every pair of vertices).
37  **/
38 class TLP_SCOPE ConnectedTest : public Observable {
39 public:
40 
41  /**
42  * @brief Checks if a graph is connected (i.e. there is a path between every pair of vertices).
43  *
44  * @param graph The graph to check.
45  * @return bool True if the graph is connected, false otherwise.
46  **/
47  static bool isConnected(const Graph* const graph);
48 
49  /**
50  * @brief If the graph is not connected, adds edges to make it connected.
51  *
52  * @param graph The graph to make connected.
53  * @param addedEdges The edges that were added to make it connected.
54  * @return void
55  **/
56  static void makeConnected(Graph *graph, std::vector<edge>& addedEdges);
57 
58  /**
59  * @brief Gets the number of connected components in the graph.
60  *
61  * @param graph The graph in which to count the number of connected components.
62  * @return unsigned int The number of connected componments.
63  **/
64  static unsigned int numberOfConnectedComponents(const Graph* const graph);
65 
66  /**
67  * @brief Computes the sets of connected components and stores the result in the components vector.
68  *
69  * @param graph The graph on which to compute connected components.
70  * @param components The components that were found. It is passed as a reference to avoid copying the data when returning.
71  * @return void
72  * @note The components parameter can be returned with c++11 thanks to move constructors without performance loss, chenge this function once c++11 compilers are used.
73  **/
74  static void computeConnectedComponents(const Graph *graph, std::vector< std::set<node> >& components);
75 
76 private:
77  ConnectedTest();
78 
79 
80  /**
81  * @brief Makes the graph connected.
82  *
83  * @param graph The graph to make connected.
84  * @param toLink The nodes that need to be linked so the graph is connected.
85  * @return void
86  **/
87  void connect(const Graph * const, std::vector<node>& toLink);
88 
89  /**
90  * @brief check if the graph is biconnected.
91  *
92  * @param graph the graph to check.
93  * @return bool true if the graph is connected, false otherwise.
94  **/
95  bool compute(const Graph * const);
96 
97  //override of Observable::treatEvent to remove the cached result for a graph if it is modified.
98  virtual void treatEvent(const Event&);
99 
100  /**
101  * @brief Singleton instance of this class.
102  **/
103  static ConnectedTest * instance;
104  /**
105  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
106  **/
107  TLP_HASH_MAP<unsigned long,bool> resultsBuffer;
108 };
109 
110 }
111 
112 #endif