Tulip  4.4.0
Better Visualization Through Research
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Properties Groups Pages
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 1 and Inria Bordeaux - Sud Ouest
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 ///@cond DOXYGEN_HIDDEN
20 
21 
22 #ifndef TULIP_SIMPLETEST_H
23 #define TULIP_SIMPLETEST_H
24 
25 #include <tulip/tuliphash.h>
26 #include <tulip/Observable.h>
27 #include <tulip/Graph.h>
28 
29 namespace tlp {
30 
31 /**
32  * @ingroup Checks
33  * @brief Performs test to check if a graph is Simple.
34  * From Wikipedia: "A simple graph is an undirected graph that has no loops and no more than one edge between any two different vertices."
35  **/
36 class TLP_SCOPE SimpleTest : private Observable {
37 public:
38 
39  /**
40  * @brief Checks if the graph is simple (i.e. it contains no self loops or parallel edges).
41  *
42  * @param graph The graph to check.
43  * @return bool True if the graph is simple, false otherwise.
44  **/
45  static bool isSimple(const Graph *graph);
46 
47  /**
48  * Makes the graph simple by removing self loops and parallel edges if any.
49  * The removed edges are stored in the removed vector.
50  */
51  /**
52  * @brief Makes the graph simple, by removing self loops and parallel edges if any.
53  *
54  * @param graph The graph to make simple.
55  * @param removed The edges that were removed to make the graph simple.
56  * @return void
57  **/
58  static void makeSimple(Graph* graph, std::vector<edge> &removed);
59 
60  /**
61  * Performs simple test and stores found parallel edges in the multipleEdges vector
62  * and found self loops in the loops vector.
63  * Returns true if the graph is simple, false otherwise.
64  */
65  /**
66  * @brief Checks if the graph is simple, and stores parallel edges and self loops in different vectors.
67  *
68  * @param graph The graph to check for simplicity.
69  * @param multipleEdges The parallel edges that need to be removed to make the graph simple. 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=NULL, std::vector<edge> *loops=NULL);
74 
75 private:
76  SimpleTest();
77  // override Observable::treatEvent
78  void treatEvent(const Event&);
79  void deleteResult(Graph *graph);
80 
81  /**
82  * @brief Singleton instance of this class.
83  **/
84  static SimpleTest *instance;
85  /**
86  * @brief Stored results for graphs. When a graph is updated, its entry is removed from the hashmap.
87  **/
88  TLP_HASH_MAP<const Graph*, bool> resultsBuffer;
89 };
90 
91 
92 }
93 #endif
94 ///@endcond