Tulip  4.3.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 
28 namespace tlp {
29 
30 class Graph;
31 
32 /**
33  * @ingroup Checks
34  * @brief Performs test to check if a graph is Simple.
35  * From Wikipedia: "A simple graph is an undirected graph that has no loops and no more than one edge between any two different vertices."
36  **/
37 class TLP_SCOPE SimpleTest : private Observable {
38 public:
39 
40  /**
41  * @brief Checks if the graph is simple (i.e. it contains no self loops or parallel edges).
42  *
43  * @param graph The graph to check.
44  * @return bool True if the graph is simple, false otherwise.
45  **/
46  static bool isSimple(const Graph *graph);
47 
48  /**
49  * Makes the graph simple by removing self loops and parallel edges if any.
50  * The removed edges are stored in the removed vector.
51  */
52  /**
53  * @brief Makes the graph simple, by removing self loops and parallel edges if any.
54  *
55  * @param graph The graph to make simple.
56  * @param removed The edges that were removed to make the graph simple.
57  * @return void
58  **/
59  static void makeSimple(Graph* graph, std::vector<edge> &removed);
60 
61  /**
62  * Performs simple test and stores found parallel edges in the multipleEdges vector
63  * and found self loops in the loops vector.
64  * Returns true if the graph is simple, false otherwise.
65  */
66  /**
67  * @brief Checks if the graph is simple, and stores parallel edges and self loops in different vectors.
68  *
69  * @param graph The graph to check for simplicity.
70  * @param multipleEdges The parallel edges that need to be removed to make the graph simple. Defaults to 0.
71  * @param loops The self loops that need to be removed to make the graph simple. Defaults to 0.
72  * @return bool True if the graph is simple, false otherwise.
73  **/
74  static bool simpleTest(const Graph *graph, std::vector<edge> *multipleEdges=NULL, std::vector<edge> *loops=NULL);
75 
76 private:
77  SimpleTest();
78  // override Observable::treatEvent
79  void treatEvent(const Event&);
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 hashmap.
88  **/
89  TLP_HASH_MAP<unsigned long, bool> resultsBuffer;
90 };
91 
92 
93 }
94 #endif
95 ///@endcond