Tulip  5.2.1
Large graphs analysis and drawing
SimpleTest.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_SIMPLETEST_H
21 #define TULIP_SIMPLETEST_H
22 
23 #include <tulip/tuliphash.h>
24 #include <tulip/Observable.h>
25 #include <tulip/Graph.h>
26 
27 namespace tlp {
28 
29 /**
30  * @ingroup Checks
31  * @brief Performs test to check if a graph is Simple.
32  * From Wikipedia: "A simple graph is an undirected graph that has no loops and no more than one
33  *edge between any two different vertices."
34  **/
35 class TLP_SCOPE SimpleTest : private Observable {
36 public:
37  /**
38  * @brief Checks if the graph is simple (i.e. it contains no self loops or parallel edges).
39  *
40  * @param graph The graph to check.
41  * @return bool True if the graph is simple, false otherwise.
42  **/
43  static bool isSimple(const Graph *graph);
44 
45  /**
46  * Makes the graph simple by removing self loops and parallel edges if any.
47  * The removed edges are stored in the removed vector.
48  */
49  /**
50  * @brief Makes the graph simple, by removing self loops and parallel edges if any.
51  *
52  * @param graph The graph to make simple.
53  * @param removed The edges that were removed to make the graph simple.
54  * @return void
55  **/
56  static void makeSimple(Graph *graph, std::vector<edge> &removed);
57 
58  /**
59  * Performs simple test and stores found parallel edges in the multipleEdges vector
60  * and found self loops in the loops vector.
61  * Returns true if the graph is simple, false otherwise.
62  */
63  /**
64  * @brief Checks if the graph is simple, and stores parallel edges and self loops in different
65  *vectors.
66  *
67  * @param graph The graph to check for simplicity.
68  * @param multipleEdges The parallel edges that need to be removed to make the graph simple.
69  *Defaults to 0.
70  * @param loops The self loops that need to be removed to make the graph simple. Defaults to 0.
71  * @return bool True if the graph is simple, false otherwise.
72  **/
73  static bool simpleTest(const Graph *graph, std::vector<edge> *multipleEdges = nullptr,
74  std::vector<edge> *loops = nullptr);
75 
76 private:
77  SimpleTest();
78  // override Observable::treatEvent
79  void treatEvent(const Event &) override;
80  void deleteResult(Graph *graph);
81 
82  /**
83  * @brief Singleton instance of this class.
84  **/
85  static SimpleTest *instance;
86  /**
87  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the
88  *hashmap.
89  **/
90  TLP_HASH_MAP<const Graph *, bool> resultsBuffer;
91 };
92 } // namespace tlp
93 #endif
Performs test to check if a graph is Simple. From Wikipedia: "A simple graph is an undirected graph t...
Definition: SimpleTest.h:35
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:51
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:141