Tulip  5.0.0
Large graphs analysis and drawing
SimpleTest.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
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 edge between any two different vertices."
33  **/
34 class TLP_SCOPE SimpleTest : private Observable {
35 public:
36 
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 vectors.
65  *
66  * @param graph The graph to check for simplicity.
67  * @param multipleEdges The parallel edges that need to be removed to make the graph simple. Defaults to 0.
68  * @param loops The self loops that need to be removed to make the graph simple. Defaults to 0.
69  * @return bool True if the graph is simple, false otherwise.
70  **/
71  static bool simpleTest(const Graph *graph, std::vector<edge> *multipleEdges=NULL, std::vector<edge> *loops=NULL);
72 
73 private:
74  SimpleTest();
75  // override Observable::treatEvent
76  void treatEvent(const Event&);
77  void deleteResult(Graph *graph);
78 
79  /**
80  * @brief Singleton instance of this class.
81  **/
82  static SimpleTest *instance;
83  /**
84  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
85  **/
86  TLP_HASH_MAP<const Graph*, bool> resultsBuffer;
87 };
88 
89 
90 }
91 #endif
Performs test to check if a graph is Simple. From Wikipedia: "A simple graph is an undirected graph t...
Definition: SimpleTest.h:34
Event is the base class for all events used in the Observation mechanism.
Definition: Observable.h:47
The Observable class is the base of Tulip&#39;s observation system.
Definition: Observable.h:123