Tulip  5.3.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 
26 #include <tulip/tulipconf.h>
27 
28 namespace tlp {
29 
30 class Graph;
31 struct node;
32 struct edge;
33 
34 /**
35  * @ingroup Checks
36  * @brief @brief Performs a test of connexity on the graph, and provides a function to make a graph
37  *connected.
38  * From Wikipedia: "A graph is said to be connected if every pair of vertices in the graph are
39  *connected." (i.e. there is a path between every pair of vertices).
40  **/
41 class TLP_SCOPE ConnectedTest {
42 public:
43  /**
44  * @brief Checks if a graph is connected (i.e. there is a path between every pair of vertices).
45  *
46  * @param graph The graph to check.
47  * @return bool True if the graph is connected, false otherwise.
48  **/
49  static bool isConnected(const Graph *const graph);
50 
51  /**
52  * @brief If the graph is not connected, adds edges to make it connected.
53  *
54  * @param graph The graph to make connected.
55  * @param addedEdges The edges that were added to make it connected.
56  * @return void
57  **/
58  static void makeConnected(Graph *graph, std::vector<edge> &addedEdges);
59 
60  /**
61  * @brief Gets the number of connected components in the graph.
62  *
63  * @param graph The graph in which to count the number of connected components.
64  * @return unsigned int The number of connected componments.
65  **/
66  static unsigned int numberOfConnectedComponents(const Graph *const graph);
67 
68  /**
69  * @brief Computes the sets of connected components and stores the result in the components
70  *vector.
71  *
72  * @param graph The graph on which to compute connected components.
73  * @param components The components that were found. It is passed as a reference to avoid copying
74  *the data when returning.
75  * @return void
76  * @note The components parameter can be returned with c++11 thanks to move constructors without
77  *performance loss, change this function once c++11 compilers are used.
78  **/
79  static void computeConnectedComponents(const Graph *graph,
80  std::vector<std::vector<node>> &components);
81 
82  /**
83  * @brief This function is defined for compatibility purpose only.
84  * @warning This function is deprecated, use the one above.
85  **/
86  static _DEPRECATED void computeConnectedComponents(const Graph *graph,
87  std::vector<std::set<node>> &components);
88 
89 private:
90  /**
91  * @brief Makes the graph connected.
92  *
93  * @param graph The graph to make connected.
94  * @param toLink The nodes that need to be linked so the graph is connected.
95  * @return void
96  **/
97  static void connect(const Graph *const, std::vector<node> &toLink);
98 };
99 } // namespace tlp
100 
101 #endif
Performs a test of connexity on the graph, and provides a function to make a graph connected...
Definition: ConnectedTest.h:41