Tulip  5.2.1
Large graphs analysis and drawing
TreeTest.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_TREETEST_H
21 #define TULIP_TREETEST_H
22 
23 #include <tulip/tuliphash.h>
24 #include <tulip/Observable.h>
25 #include <tulip/Graph.h>
26 
27 namespace tlp {
28 
29 class PluginProgress;
30 /**
31  * @ingroup Checks
32  * @brief Performs test to check whether a graph is a simple or rooted tree.
33  * From wikipedia: "A tree is an undirected graph in which any two vertices are connected by exactly
34  *one simple path."
35  * Free trees have no designated root, while rooted trees do.
36  **/
37 class TLP_SCOPE TreeTest : private Observable {
38 public:
39  /**
40  * @brief Checks if the graph is a rooted tree (i.e. one node is designated as the root).
41  *
42  * @param graph The graph to check is a tree.
43  * @return bool True if the graph is a tree, false otherwise.
44  **/
45  static bool isTree(const Graph *graph);
46 
47  /**
48  * Returns true if the graph is a topological tree
49  * (i.e. if the graph was undirected, there would be no cycle),
50  * false otherwise.
51  */
52  /**
53  * @brief Checks if the graph is a topological tree (i.e. if the graph was undirected, there would
54  *be no cycle).
55  *
56  * @param graph The graph to check is a free tree.
57  * @return bool True if the graph is a free tree, false otherwise.
58  **/
59  static bool isFreeTree(const Graph *graph);
60 
61  /**
62  * Turns a free tree into a rooted tree.
63  */
64  /**
65  * @brief Makes a free tree into a rooted tree.
66  *
67  * @param freeTree The free tree to make a rooted tree.
68  * @param root The root of the tree.
69  * @return void
70  **/
71  static void makeRootedTree(Graph *freeTree, node root);
72 
73  /**
74  * @brief Computes a rooted tree from the graph.
75  * If the graph is a rooted tree, the input graph is returned as is.
76  * If the graphs is a free tree, a rooted clone subgraph is returned.
77  * If the graph is connected, a rooted spanning tree of a clone subgraph is returned
78  * If the graph is not connected, computes a tree for each of the connected components of a clone
79  *subgraph, adds a simple source and returns the clone.
80  *
81  * @param graph The graph to compute a tree on.
82  * @param pluginProgress reports progress on the computation. Defaults to 0.
83  * @return :Graph* If the input graph is a rooted tree, returns it as is, otherwise a clone
84  *subgraph transformed into a rooted tree.
85  **/
86  static Graph *computeTree(Graph *graph, PluginProgress *pluginProgress = nullptr);
87 
88  /**
89  * @brief Removes subgraphs created during tree computation.
90  * If graph and tree are the same graph, does nothing.
91  *
92  * @param graph The graph to clean from tree subgraphs.
93  * @param tree The tree subgraph to remove.
94  * @return void
95  * @note this deletes the root of the graph from graph's root (i.e. calls
96  *graph->getRoot()->delNode()).
97  **/
98  static void cleanComputedTree(Graph *graph, Graph *tree);
99 
100 private:
101  TreeTest();
102 
103  bool compute(const Graph *graph);
104 
105  bool isFreeTree(const Graph *graph, node curRoot);
106 
107  // override Observable::treatEvent
108  void treatEvent(const Event &) override;
109 
110  /**
111  * @brief Singleton instance of this class.
112  **/
113  static TreeTest *instance;
114  /**
115  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the
116  *hashmap.
117  **/
118  TLP_HASH_MAP<const Graph *, bool> resultsBuffer;
119 };
120 } // namespace tlp
121 #endif
The node struct represents a node in a Graph object.
Definition: Node.h:40
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:51
PluginProcess subclasses are meant to notify about the progress state of some process (typically a pl...
Performs test to check whether a graph is a simple or rooted tree. From wikipedia: "A tree is an undi...
Definition: TreeTest.h:37
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:141