Tulip  5.2.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 #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 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
70  *the data when returning.
71  * @return void
72  * @note The components parameter can be returned with c++11 thanks to move constructors without
73  *performance loss, change this function once c++11 compilers are used.
74  **/
75  static void computeConnectedComponents(const Graph *graph,
76  std::vector<std::vector<node>> &components);
77 
78  /**
79  * @brief This function is defined for compatibility purpose only.
80  * @warning This function is deprecated, use the one above.
81  **/
82  static _DEPRECATED void computeConnectedComponents(const Graph *graph,
83  std::vector<std::set<node>> &components);
84 
85 private:
86  ConnectedTest();
87 
88  /**
89  * @brief Makes the graph connected.
90  *
91  * @param graph The graph to make connected.
92  * @param toLink The nodes that need to be linked so the graph is connected.
93  * @return void
94  **/
95  void connect(const Graph *const, std::vector<node> &toLink);
96 
97  /**
98  * @brief check if the graph is biconnected.
99  *
100  * @param graph the graph to check.
101  * @return bool true if the graph is connected, false otherwise.
102  **/
103  bool compute(const Graph *const);
104 
105  // override of Observable::treatEvent to remove the cached result for a graph if it is modified.
106  void treatEvent(const Event &) override;
107 
108  /**
109  * @brief Singleton instance of this class.
110  **/
111  static ConnectedTest *instance;
112  /**
113  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the
114  *hashmap.
115  **/
116  TLP_HASH_MAP<const Graph *, bool> resultsBuffer;
117 };
118 }
119 
120 #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