UnCoVer (Using Coverability for Verification)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
AnonHypergraph.h
1 /***************************************************************************
2  * Copyright (C) 2005 by SZS *
3  * Copyright (C) 2014 by Jan Stückrath <jan.stueckrath@uni-due.de> *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the GNU General Public License as published by *
7  * the Free Software Foundation; either version 2 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the GNU General Public License *
16  * along with this program; if not, write to the *
17  * Free Software Foundation, Inc., *
18  * 51 Franklin St, Fifth Floor, Boston, MA 02110, USA *
19  ***************************************************************************/
20 
21 #ifndef ANONHYPERGRAPH_H_
22 #define ANONHYPERGRAPH_H_
23 
24 #include "../basic_types/globals.h"
25 #include "Vertex.h"
26 #include "Edge.h"
27 #include "../basic_types/InitialisationException.h"
28 #include "../basic_types/InvalidInputException.h"
29 #include "../basic_types/Streamable.h"
30 
31 namespace uncover {
32  namespace graphs {
33 
44 
45  public:
46 
50  // Tests have shown better performance when using map instead of unordered_map.
51  typedef map<IDType, Vertex> VMap;
52 
56  // Tests have shown better performance when using map instead of unordered_map.
57  typedef map<IDType, Edge> EMap;
58 
63  typedef unordered_multiset<IDType> ESet;
64 
69  AnonHypergraph(std::string name = "");
70 
76  AnonHypergraph(const AnonHypergraph& graph);
77 
81  virtual ~AnonHypergraph();
82 
87  string getName() const;
88 
93  void setName(string s);
94 
99  virtual void streamTo(std::ostream& ost) const override;
100 
102  // Vertex manipulation
104 
109  IDType addVertex();
110 
116  bool hasVertex(IDType id) const;
117 
127  bool deleteVertex(IDType id, unordered_set<IDType>* delEdges = nullptr);
128 
138  bool deleteVertices(vector<IDType> const& ids, unordered_set<IDType>* delEdges = nullptr);
139 
144  size_t getVertexCount() const;
145 
150  AnonHypergraph::VMap::iterator beginVertices() noexcept;
151 
156  AnonHypergraph::VMap::const_iterator beginVertices() const noexcept;
157 
162  AnonHypergraph::VMap::const_iterator cbeginVertices() const noexcept;
163 
169  AnonHypergraph::VMap::iterator endVertices() noexcept;
170 
176  AnonHypergraph::VMap::const_iterator endVertices() const noexcept;
177 
183  AnonHypergraph::VMap::const_iterator cendVertices() const noexcept;
184 
193 
201  AnonHypergraph::ESet const* getConnectedEdges(IDType vid) const;
202 
209  int getConnEdgesCount(IDType vid) const;
210 
220  IDType mergeVertices(IDType id1, IDType id2);
221 
228  void mergeVertexIntoFirst(IDType id1, IDType id2);
229 
237  IDType mergeVertices(unordered_set<IDType> const& ids);
238 
240  // Edge manipulation
242 
248  bool hasEdge(IDType id) const;
249 
259  IDType addEdge(string label, vector<IDType> const& attVertices = vector<IDType>());
260 
266  bool deleteEdge(IDType id);
267 
274  vector<IDType>* getVerticesOfEdge(IDType edgeID);
275 
282  vector<IDType> const* getVerticesOfEdge(IDType edgeID) const;
283 
289  Edge* getEdge(IDType id);
290 
296  Edge const* getEdge(IDType id) const;
297 
305  int getEdgeArity(IDType id) const;
306 
311  size_t getEdgeCount() const;
312 
317  AnonHypergraph::EMap::iterator beginEdges() noexcept;
318 
323  AnonHypergraph::EMap::const_iterator beginEdges() const noexcept;
324 
329  AnonHypergraph::EMap::const_iterator cbeginEdges() const noexcept;
330 
336  AnonHypergraph::EMap::iterator endEdges() noexcept;
337 
343  AnonHypergraph::EMap::const_iterator endEdges() const noexcept;
344 
350  AnonHypergraph::EMap::const_iterator cendEdges() const noexcept;
351 
361  IDType mergeEdges(IDType id1, IDType id2);
362 
370  IDType mergeEdges(unordered_set<IDType> const& ids);
371 
380  bool areParallelEdges(IDType id1, IDType id2) const;
381 
382  protected:
383 
387  IDType lastUsedID;
388 
392  string name;
393 
398 
403 
408  unordered_map<IDType, AnonHypergraph::ESet> connectedEdges;
409 
410  };
411 
415  typedef shared_ptr<AnonHypergraph> AnonHypergraph_sp;
416 
420  typedef shared_ptr<const AnonHypergraph> AnonHypergraph_csp;
421 
422  } /* namespace graphs */
423 } /* namespace uncover */
424 
425 #endif /* ANONHYPERGRAPH_H_ */
IDType addEdge(string label, vector< IDType > const &attVertices=vector< IDType >())
Adds an edge with the given label and incident vertices to this graph.
Definition: AnonHypergraph.cpp:296
shared_ptr< AnonHypergraph > AnonHypergraph_sp
Alias of a shared pointer to an AnonHypergraph.
Definition: AnonHypergraph.h:415
IDType lastUsedID
Stores the last ID assigned to a vertex or edge.
Definition: AnonHypergraph.h:387
AnonHypergraph::VMap::const_iterator cbeginVertices() const noexcept
Returns a const_iterator to the first entry in the vertex map.
Definition: AnonHypergraph.cpp:244
bool deleteVertices(vector< IDType > const &ids, unordered_set< IDType > *delEdges=nullptr)
All vertices with IDs in the given vector will be deleted, also deleting all edges incident to them...
Definition: AnonHypergraph.cpp:464
Streamable provides a streaming function which must be implemented by any deriving class...
Definition: Streamable.h:31
unordered_map< IDType, AnonHypergraph::ESet > connectedEdges
Maps every vertex ID to a set containing all IDs of edges incident to them.
Definition: AnonHypergraph.h:408
shared_ptr< const AnonHypergraph > AnonHypergraph_csp
Alias of a shared pointer to a constant AnonHypergraph.
Definition: AnonHypergraph.h:420
unordered_multiset< IDType > ESet
Alias for a set of edge IDs connected to a vertex.
Definition: AnonHypergraph.h:63
Edge * getEdge(IDType id)
Returns the edge with the given ID if it exists.
Definition: AnonHypergraph.cpp:353
IDType addVertex()
Adds a new vertex to this graph and returns the ID of the added vertex.
Definition: AnonHypergraph.cpp:322
string getName() const
Returns the name of this graph.
Definition: AnonHypergraph.cpp:226
AnonHypergraph::EMap edges
Stores a map of all edges of this graph, where the key is their ID.
Definition: AnonHypergraph.h:402
IDType mergeVertices(IDType id1, IDType id2)
Merges the vertices with the given IDs, such that all edges incident to one of the vertices will be i...
Definition: AnonHypergraph.cpp:55
AnonHypergraph::EMap::const_iterator cbeginEdges() const noexcept
Returns a const_iterator to the first entry in the edge map.
Definition: AnonHypergraph.cpp:268
void setName(string s)
Sets the name of this graph to the given string.
Definition: AnonHypergraph.cpp:231
int getEdgeArity(IDType id) const
Returns the arity of the edge with the given ID, i.e.
Definition: AnonHypergraph.cpp:365
map< IDType, Vertex > VMap
Alias for a vertex map returned by this class.
Definition: AnonHypergraph.h:51
size_t getEdgeCount() const
Returns the number of edges of this graph.
Definition: AnonHypergraph.cpp:373
string name
Stores the name of this graph.
Definition: AnonHypergraph.h:392
AnonHypergraph::EMap::const_iterator cendEdges() const noexcept
Returns a const_iterator pointing beyond the last entry in the edge map.
Definition: AnonHypergraph.cpp:280
virtual ~AnonHypergraph()
Deletes this graph, freeing all its memory.
Definition: AnonHypergraph.cpp:49
size_t getVertexCount() const
Returns the number of vertices of this graph.
Definition: AnonHypergraph.cpp:377
AnonHypergraph::VMap::const_iterator cendVertices() const noexcept
Returns a const_iterator pointing beyond the last entry in the vertex map.
Definition: AnonHypergraph.cpp:256
bool hasEdge(IDType id) const
Returns true, iff this graph has an edge with the given ID.
Definition: AnonHypergraph.cpp:329
AnonHypergraph::VMap::iterator endVertices() noexcept
Returns an iterator pointing beyond the last entry in the vertex map.
Definition: AnonHypergraph.cpp:248
bool deleteEdge(IDType id)
Deleted the edge with the given ID, if it exists (ignored if it does not exist).
Definition: AnonHypergraph.cpp:397
AnonHypergraph::VMap vertices
Stores a map of all vertices of this graph, where the key is their ID.
Definition: AnonHypergraph.h:397
virtual void streamTo(std::ostream &ost) const override
Prints a string representation of this graph to the given stream.
Definition: AnonHypergraph.cpp:414
AnonHypergraph::EMap::iterator endEdges() noexcept
Returns an iterator pointing beyond the last entry in the edge map.
Definition: AnonHypergraph.cpp:272
int getConnEdgesCount(IDType vid) const
Returns the number of edges connected to the vertex with the given ID.
Definition: AnonHypergraph.cpp:284
An AnonHypergraph is a data structure storing a hypergraph.
Definition: AnonHypergraph.h:43
AnonHypergraph::EMap::iterator beginEdges() noexcept
Returns an iterator to the first entry in the edge map.
Definition: AnonHypergraph.cpp:260
map< IDType, Edge > EMap
Alias for an edge map returned by this class.
Definition: AnonHypergraph.h:57
vector< IDType > * getVerticesOfEdge(IDType edgeID)
Returns the sequence of vertices incident to the edge with the given ID.
Definition: AnonHypergraph.cpp:339
void mergeVertexIntoFirst(IDType id1, IDType id2)
Same as mergeVertices(IDType,IDType), but it is guaranteed that the ID of the merged vertex will be t...
Definition: AnonHypergraph.cpp:51
AnonHypergraph(std::string name="")
Generates a new graph with the given name and an empty collection of vertices and edges...
AnonHypergraph::VMap::iterator beginVertices() noexcept
Returns an iterator to the first entry in the vertex map.
Definition: AnonHypergraph.cpp:236
bool areParallelEdges(IDType id1, IDType id2) const
Returns true if the given IDs are parallel edges, i.e.
Definition: AnonHypergraph.cpp:472
bool deleteVertex(IDType id, unordered_set< IDType > *delEdges=nullptr)
Deletes the vertex with the given ID if it exists in this graph.
Definition: AnonHypergraph.cpp:441
bool hasVertex(IDType id) const
Returns true if and only if this graph has a vertex with the given ID.
Definition: AnonHypergraph.cpp:334
AnonHypergraph::ESet * getConnectedEdges(IDType vid)
Returns the set of IDs of edges incident to the vertex with the given ID.
Definition: AnonHypergraph.cpp:381
IDType mergeEdges(IDType id1, IDType id2)
Merges the edges with the given IDs.
Definition: AnonHypergraph.cpp:134
unsigned int IDType
IDType is an (unsigned) integer specifically used as an Identifier of graphs, elements of graphs or a...
Definition: globals.h:53
This class represents an edge in a Hypergraph.
Definition: Edge.h:34