Tulip  5.4.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 
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 private:
83  /**
84  * @brief Makes the graph connected.
85  *
86  * @param graph The graph to make connected.
87  * @param toLink The nodes that need to be linked so the graph is connected.
88  * @return void
89  **/
90  static void connect(const Graph *const, std::vector<node> &toLink);
91 };
92 } // namespace tlp
93 
94 #endif
Performs a test of connexity on the graph, and provides a function to make a graph connected...
Definition: ConnectedTest.h:41