Tulip  5.1.0
Large graphs analysis and drawing
ConnectedTest.h
1 /*
2  *
3  * This file is part of Tulip (http://tulip.labri.fr)
4  *
5  * Authors: David Auber and the Tulip development Team
6  * from LaBRI, University of Bordeaux
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 #include <tulip/Graph.h>
29 
30 namespace tlp {
31 
32 /**
33  * @ingroup Checks
34  * @brief @brief Performs a test of connexity on the graph, and provides a function to make a graph connected.
35  * 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).
36  **/
37 class TLP_SCOPE ConnectedTest : public Observable {
38 public:
39 
40  /**
41  * @brief Checks if a graph is connected (i.e. there is a path between every pair of vertices).
42  *
43  * @param graph The graph to check.
44  * @return bool True if the graph is connected, false otherwise.
45  **/
46  static bool isConnected(const Graph* const graph);
47 
48  /**
49  * @brief If the graph is not connected, adds edges to make it connected.
50  *
51  * @param graph The graph to make connected.
52  * @param addedEdges The edges that were added to make it connected.
53  * @return void
54  **/
55  static void makeConnected(Graph *graph, std::vector<edge>& addedEdges);
56 
57  /**
58  * @brief Gets the number of connected components in the graph.
59  *
60  * @param graph The graph in which to count the number of connected components.
61  * @return unsigned int The number of connected componments.
62  **/
63  static unsigned int numberOfConnectedComponents(const Graph* const graph);
64 
65  /**
66  * @brief Computes the sets of connected components and stores the result in the components vector.
67  *
68  * @param graph The graph on which to compute connected components.
69  * @param components The components that were found. It is passed as a reference to avoid copying the data when returning.
70  * @return void
71  * @note The components parameter can be returned with c++11 thanks to move constructors without performance loss, change this function once c++11 compilers are used.
72  **/
73  static void computeConnectedComponents(const Graph *graph, std::vector< std::vector<node> >& components);
74 
75  /**
76  * @brief This function is defined for compatibility purpose only.
77  * @warning This function is deprecated, use the one above.
78  **/
79  static _DEPRECATED void computeConnectedComponents(const Graph *graph, std::vector< std::set<node> >& components);
80 
81 private:
82  ConnectedTest();
83 
84 
85  /**
86  * @brief Makes the graph connected.
87  *
88  * @param graph The graph to make connected.
89  * @param toLink The nodes that need to be linked so the graph is connected.
90  * @return void
91  **/
92  void connect(const Graph * const, std::vector<node>& toLink);
93 
94  /**
95  * @brief check if the graph is biconnected.
96  *
97  * @param graph the graph to check.
98  * @return bool true if the graph is connected, false otherwise.
99  **/
100  bool compute(const Graph * const);
101 
102  //override of Observable::treatEvent to remove the cached result for a graph if it is modified.
103  virtual void treatEvent(const Event&);
104 
105  /**
106  * @brief Singleton instance of this class.
107  **/
108  static ConnectedTest * instance;
109  /**
110  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
111  **/
112  TLP_HASH_MAP<const Graph*,bool> resultsBuffer;
113 };
114 
115 }
116 
117 #endif
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47
Performs a test of connexity on the graph, and provides a function to make a graph connected...
Definition: ConnectedTest.h:37
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:123