Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces 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 #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, chenge this function once c++11 compilers are used.
72  **/
73  static void computeConnectedComponents(const Graph *graph, std::vector< std::set<node> >& components);
74 
75 private:
76  ConnectedTest();
77 
78 
79  /**
80  * @brief Makes the graph connected.
81  *
82  * @param graph The graph to make connected.
83  * @param toLink The nodes that need to be linked so the graph is connected.
84  * @return void
85  **/
86  void connect(const Graph * const, std::vector<node>& toLink);
87 
88  /**
89  * @brief check if the graph is biconnected.
90  *
91  * @param graph the graph to check.
92  * @return bool true if the graph is connected, false otherwise.
93  **/
94  bool compute(const Graph * const);
95 
96  //override of Observable::treatEvent to remove the cached result for a graph if it is modified.
97  virtual void treatEvent(const Event&);
98 
99  /**
100  * @brief Singleton instance of this class.
101  **/
102  static ConnectedTest * instance;
103  /**
104  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
105  **/
106  TLP_HASH_MAP<const Graph*,bool> resultsBuffer;
107 };
108 
109 }
110 
111 #endif