Tulip  5.2.1
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 #ifndef TULIP_CONNECTEDTEST_H
21 #define TULIP_CONNECTEDTEST_H
22 
23 #include <set>
24 #include <vector>
25 #include <tulip/tuliphash.h>
26 #include <tulip/Observable.h>
27 #include <tulip/Graph.h>
28 
29 namespace tlp {
30 
31 /**
32  * @ingroup Checks
33  * @brief @brief Performs a test of connexity on the graph, and provides a function to make a graph
34  *connected.
35  * From Wikipedia: "A graph is said to be connected if every pair of vertices in the graph are
36  *connected." (i.e. there is a path between every pair of vertices).
37  **/
38 class TLP_SCOPE ConnectedTest : public Observable {
39 public:
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
67  *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
71  *the data when returning.
72  * @return void
73  * @note The components parameter can be returned with c++11 thanks to move constructors without
74  *performance loss, change this function once c++11 compilers are used.
75  **/
76  static void computeConnectedComponents(const Graph *graph,
77  std::vector<std::vector<node>> &components);
78 
79  /**
80  * @brief This function is defined for compatibility purpose only.
81  * @warning This function is deprecated, use the one above.
82  **/
83  static _DEPRECATED void computeConnectedComponents(const Graph *graph,
84  std::vector<std::set<node>> &components);
85 
86 private:
87  ConnectedTest();
88 
89  /**
90  * @brief Makes the graph connected.
91  *
92  * @param graph The graph to make connected.
93  * @param toLink The nodes that need to be linked so the graph is connected.
94  * @return void
95  **/
96  void connect(const Graph *const, std::vector<node> &toLink);
97 
98  /**
99  * @brief check if the graph is biconnected.
100  *
101  * @param graph the graph to check.
102  * @return bool true if the graph is connected, false otherwise.
103  **/
104  bool compute(const Graph *const);
105 
106  // override of Observable::treatEvent to remove the cached result for a graph if it is modified.
107  void treatEvent(const Event &) override;
108 
109  /**
110  * @brief Singleton instance of this class.
111  **/
112  static ConnectedTest *instance;
113  /**
114  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the
115  *hashmap.
116  **/
117  TLP_HASH_MAP<const Graph *, bool> resultsBuffer;
118 };
119 } // namespace tlp
120 
121 #endif
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:51
Performs a test of connexity on the graph, and provides a function to make a graph connected...
Definition: ConnectedTest.h:38
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:141