UnCoVer (Using Coverability for Verification)
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | Protected Attributes | List of all members
AnonHypergraph Class Reference

An AnonHypergraph is a data structure storing a hypergraph. More...

#include <AnonHypergraph.h>

Inheritance diagram for AnonHypergraph:
Inheritance graph
[legend]
Collaboration diagram for AnonHypergraph:
Collaboration graph
[legend]

Public Types

typedef map< IDType, VertexVMap
 Alias for a vertex map returned by this class. More...
 
typedef map< IDType, EdgeEMap
 Alias for an edge map returned by this class. More...
 
typedef unordered_multiset
< IDType
ESet
 Alias for a set of edge IDs connected to a vertex. More...
 

Public Member Functions

 AnonHypergraph (std::string name="")
 Generates a new graph with the given name and an empty collection of vertices and edges. More...
 
 AnonHypergraph (const AnonHypergraph &graph)
 Generates a new graph with data copied from the given graph. More...
 
virtual ~AnonHypergraph ()
 Deletes this graph, freeing all its memory.
 
string getName () const
 Returns the name of this graph. More...
 
void setName (string s)
 Sets the name of this graph to the given string. More...
 
virtual void streamTo (std::ostream &ost) const override
 Prints a string representation of this graph to the given stream. More...
 
IDType addVertex ()
 Adds a new vertex to this graph and returns the ID of the added vertex. More...
 
bool hasVertex (IDType id) const
 Returns true if and only if this graph has a vertex with the given ID. More...
 
bool deleteVertex (IDType id, unordered_set< IDType > *delEdges=nullptr)
 Deletes the vertex with the given ID if it exists in this graph. More...
 
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. More...
 
size_t getVertexCount () const
 Returns the number of vertices of this graph. More...
 
AnonHypergraph::VMap::iterator beginVertices () noexcept
 Returns an iterator to the first entry in the vertex map. More...
 
AnonHypergraph::VMap::const_iterator beginVertices () const noexcept
 Returns a const_iterator to the first entry in the vertex map. More...
 
AnonHypergraph::VMap::const_iterator cbeginVertices () const noexcept
 Returns a const_iterator to the first entry in the vertex map. More...
 
AnonHypergraph::VMap::iterator endVertices () noexcept
 Returns an iterator pointing beyond the last entry in the vertex map. More...
 
AnonHypergraph::VMap::const_iterator endVertices () const noexcept
 Returns a const_iterator pointing beyond the last entry in the vertex map. More...
 
AnonHypergraph::VMap::const_iterator cendVertices () const noexcept
 Returns a const_iterator pointing beyond the last entry in the vertex map. More...
 
AnonHypergraph::ESetgetConnectedEdges (IDType vid)
 Returns the set of IDs of edges incident to the vertex with the given ID. More...
 
AnonHypergraph::ESet const * getConnectedEdges (IDType vid) const
 Returns the set of IDs of edges incident to the vertex with the given ID. More...
 
int getConnEdgesCount (IDType vid) const
 Returns the number of edges connected to the vertex with the given ID. More...
 
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 incident to the merging. More...
 
void mergeVertexIntoFirst (IDType id1, IDType id2)
 Same as mergeVertices(IDType,IDType), but it is guaranteed that the ID of the merged vertex will be the ID of the first vertex, i.e. More...
 
IDType mergeVertices (unordered_set< IDType > const &ids)
 Merges all vertices in the given vector into one vertex. More...
 
bool hasEdge (IDType id) const
 Returns true, iff this graph has an edge with the given ID. More...
 
IDType addEdge (string label, vector< IDType > const &attVertices=vector< IDType >())
 Adds an edge with the given label and incident vertices to this graph. More...
 
bool deleteEdge (IDType id)
 Deleted the edge with the given ID, if it exists (ignored if it does not exist). More...
 
vector< IDType > * getVerticesOfEdge (IDType edgeID)
 Returns the sequence of vertices incident to the edge with the given ID. More...
 
vector< IDType > const * getVerticesOfEdge (IDType edgeID) const
 Returns the sequence of vertices incident to the edge with the given ID. More...
 
EdgegetEdge (IDType id)
 Returns the edge with the given ID if it exists. More...
 
Edge const * getEdge (IDType id) const
 Returns the edge with the given ID if it exists. More...
 
int getEdgeArity (IDType id) const
 Returns the arity of the edge with the given ID, i.e. More...
 
size_t getEdgeCount () const
 Returns the number of edges of this graph. More...
 
AnonHypergraph::EMap::iterator beginEdges () noexcept
 Returns an iterator to the first entry in the edge map. More...
 
AnonHypergraph::EMap::const_iterator beginEdges () const noexcept
 Returns a const_iterator to the first entry in the edge map. More...
 
AnonHypergraph::EMap::const_iterator cbeginEdges () const noexcept
 Returns a const_iterator to the first entry in the edge map. More...
 
AnonHypergraph::EMap::iterator endEdges () noexcept
 Returns an iterator pointing beyond the last entry in the edge map. More...
 
AnonHypergraph::EMap::const_iterator endEdges () const noexcept
 Returns a const_iterator pointing beyond the last entry in the edge map. More...
 
AnonHypergraph::EMap::const_iterator cendEdges () const noexcept
 Returns a const_iterator pointing beyond the last entry in the edge map. More...
 
IDType mergeEdges (IDType id1, IDType id2)
 Merges the edges with the given IDs. More...
 
IDType mergeEdges (unordered_set< IDType > const &ids)
 Merges all edges in the given vector into one edge. More...
 
bool areParallelEdges (IDType id1, IDType id2) const
 Returns true if the given IDs are parallel edges, i.e. More...
 

Protected Attributes

IDType lastUsedID
 Stores the last ID assigned to a vertex or edge.
 
string name
 Stores the name of this graph.
 
AnonHypergraph::VMap vertices
 Stores a map of all vertices of this graph, where the key is their ID.
 
AnonHypergraph::EMap edges
 Stores a map of all edges of this graph, where the key is their ID.
 
unordered_map< IDType,
AnonHypergraph::ESet
connectedEdges
 Maps every vertex ID to a set containing all IDs of edges incident to them. More...
 

Detailed Description

An AnonHypergraph is a data structure storing a hypergraph.

It stores a name, a collection of vertices and a collection of edges connected to these vertices. Furthermore, it provides a large collection of functions to manipulate the graph structure, ranging from add- and delete-function to iterators. The Hypergraph class extends AnonHypergraph by additionally providing an unique identifier for the graph. Note that this class can be big; the use of pointers is recommended.

See Also
Hypergraph
Author
Jan Stückrath

Member Typedef Documentation

typedef map<IDType, Edge> EMap

Alias for an edge map returned by this class.

The keys are IDs and the values are edges.

typedef unordered_multiset<IDType> ESet

Alias for a set of edge IDs connected to a vertex.

An ID may occur more than once if an edge is connected to the same vertex more than once.

typedef map<IDType, Vertex> VMap

Alias for a vertex map returned by this class.

The keys are IDs and the values are vertices.

Constructor & Destructor Documentation

AnonHypergraph ( std::string  name = "")

Generates a new graph with the given name and an empty collection of vertices and edges.

Parameters
namea name for the graph, not necessarily unique
AnonHypergraph ( const AnonHypergraph graph)

Generates a new graph with data copied from the given graph.

The new graph is an independent copy of the given graph.

Parameters
graphthe graph to be copied

Member Function Documentation

IDType addEdge ( string  label,
vector< IDType > const &  attVertices = vector<IDType>() 
)

Adds an edge with the given label and incident vertices to this graph.

If an ID in the vector of incident vertices is not a vertex in this graph, an exception is thrown.

Parameters
labelthe label of the new edge
attVerticesthe sequence of incident vertices; order is important; if not given, an edge with no incident vertices is added
Returns
the ID of the new edge
Exceptions
InvalidInputExceptionif an incident ID is no vertex in this graph
IDType addVertex ( )

Adds a new vertex to this graph and returns the ID of the added vertex.

Returns
the ID of the added vertex
bool areParallelEdges ( IDType  id1,
IDType  id2 
) const

Returns true if the given IDs are parallel edges, i.e.

they have the same label, the same arity and the same sequence of vertices incident to them. Throws an exception if one of the IDs is not an edge.

Parameters
id1ID of an edge
id2ID of an edge
Returns
true, iff the edges with the given IDs are parallel
Exceptions
InvalidInputExceptionif one of the IDs is not an edge
AnonHypergraph::EMap::iterator beginEdges ( )
noexcept

Returns an iterator to the first entry in the edge map.

No order on the entries is guaranteed.

Returns
an iterator to the first entry in the edge map
AnonHypergraph::EMap::const_iterator beginEdges ( ) const
noexcept

Returns a const_iterator to the first entry in the edge map.

No order on the entries is guaranteed.

Returns
a const_iterator to the first entry in the edge map
AnonHypergraph::VMap::iterator beginVertices ( )
noexcept

Returns an iterator to the first entry in the vertex map.

No order on the entries is guaranteed.

Returns
an iterator to the first entry in the vertex map
AnonHypergraph::VMap::const_iterator beginVertices ( ) const
noexcept

Returns a const_iterator to the first entry in the vertex map.

No order on the entries is guaranteed.

Returns
a const_iterator to the first entry in the vertex map
AnonHypergraph::EMap::const_iterator cbeginEdges ( ) const
noexcept

Returns a const_iterator to the first entry in the edge map.

No order on the entries is guaranteed.

Returns
a const_iterator to the first entry in the edge map
AnonHypergraph::VMap::const_iterator cbeginVertices ( ) const
noexcept

Returns a const_iterator to the first entry in the vertex map.

No order on the entries is guaranteed.

Returns
a const_iterator to the first entry in the vertex map
AnonHypergraph::EMap::const_iterator cendEdges ( ) const
noexcept

Returns a const_iterator pointing beyond the last entry in the edge map.

No order on the entries is guaranteed.

Returns
a const_iterator pointing beyond the last entry in the edge map
AnonHypergraph::VMap::const_iterator cendVertices ( ) const
noexcept

Returns a const_iterator pointing beyond the last entry in the vertex map.

No order on the entries is guaranteed.

Returns
a const_iterator pointing beyond the last entry in the vertex map
bool deleteEdge ( IDType  id)

Deleted the edge with the given ID, if it exists (ignored if it does not exist).

Parameters
idthe ID of the edge to be deleted
Returns
true, iff an edge was deleted
bool deleteVertex ( IDType  id,
unordered_set< IDType > *  delEdges = nullptr 
)

Deletes the vertex with the given ID if it exists in this graph.

All edges incident to the deleted vertex will be deleted as well. Optionally a set can be given, in which the IDs of all deleted edges will be stored.

Parameters
idthe ID of the vertex to be deleted
delEdgesa set in which all IDs of deleted edges will be stored; use null if the IDs should not be stored
Returns
true, iff a vertex was deleted
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.

If there is an ID for which there is no vertex in the graph, the ID is simply ignored. Optionally a set can be given, in which the IDs of all deleted edges will be stored.

Parameters
idsa vector of all vertices which should be deleted
delEdgesa set in which all IDs of deleted edges will be stored; use null if the IDs should not be stored
Returns
true, iff at least one vertex was deleted
AnonHypergraph::EMap::iterator endEdges ( )
noexcept

Returns an iterator pointing beyond the last entry in the edge map.

No order on the entries is guaranteed.

Returns
an iterator pointing beyond the last entry in the edge map
AnonHypergraph::EMap::const_iterator endEdges ( ) const
noexcept

Returns a const_iterator pointing beyond the last entry in the edge map.

No order on the entries is guaranteed.

Returns
a const_iterator pointing beyond the last entry in the edge map
AnonHypergraph::VMap::iterator endVertices ( )
noexcept

Returns an iterator pointing beyond the last entry in the vertex map.

No order on the entries is guaranteed.

Returns
an iterator pointing beyond the last entry in the vertex map
AnonHypergraph::VMap::const_iterator endVertices ( ) const
noexcept

Returns a const_iterator pointing beyond the last entry in the vertex map.

No order on the entries is guaranteed.

Returns
a const_iterator pointing beyond the last entry in the vertex map
AnonHypergraph::ESet * getConnectedEdges ( IDType  vid)

Returns the set of IDs of edges incident to the vertex with the given ID.

If there is no such vertex, null is returned. The returned set contains every ID as often as it is connected to the vertex.

Parameters
vidthe ID of the vertex of which the incident edges should be returned
Returns
the set of edge IDs incident to the given vertex; null if there is no vertex with the given ID
AnonHypergraph::ESet const * getConnectedEdges ( IDType  vid) const

Returns the set of IDs of edges incident to the vertex with the given ID.

If there is no such vertex, null is returned. The returned set contains every ID as often as it is connected to the vertex.

Parameters
vidthe ID of the vertex of which the incident edges should be returned
Returns
the set of edge IDs incident to the given vertex; null if there is no vertex with the given ID
int getConnEdgesCount ( IDType  vid) const

Returns the number of edges connected to the vertex with the given ID.

If there is no vertex with the given ID, then -1 is returned.

Parameters
vidthe vertex ID of which the number of incident edges should be returned
Returns
the number of incident edges; -1 if the is no vertex with the given ID
Edge * getEdge ( IDType  id)

Returns the edge with the given ID if it exists.

Returns null, if it does not exist.

Parameters
idthe ID of the edge
Returns
the edge with the given ID or null if no such edge exists
Edge const * getEdge ( IDType  id) const

Returns the edge with the given ID if it exists.

Returns null, if it does not exist.

Parameters
idthe ID of the edge
Returns
the edge with the given ID or null if no such edge exists
int getEdgeArity ( IDType  id) const

Returns the arity of the edge with the given ID, i.e.

the number of vertices to which it is incident. A vertex to which the edge is incident multiple times, is counted multiple times. If no edge with the given ID exists, -1 is returned.

Parameters
idthe ID of the edge to be checked
Returns
the arity of the edge or -1 if no edge with the given ID exists
size_t getEdgeCount ( ) const

Returns the number of edges of this graph.

Returns
the number of edges of this graph
string getName ( ) const

Returns the name of this graph.

Returns
the name of this graph
size_t getVertexCount ( ) const

Returns the number of vertices of this graph.

Returns
the number of vertices of this graph
vector< IDType > * getVerticesOfEdge ( IDType  edgeID)

Returns the sequence of vertices incident to the edge with the given ID.

If there is no edge with the given ID, null is returned.

Parameters
edgeIDthe edge for which the sequence of incident vertices should be returned
Returns
the sequence of vertices incident to the edge with the given ID; null if no such edge esists
vector< IDType > const * getVerticesOfEdge ( IDType  edgeID) const

Returns the sequence of vertices incident to the edge with the given ID.

If there is no edge with the given ID, null is returned.

Parameters
edgeIDthe edge for which the sequence of incident vertices should be returned
Returns
the sequence of vertices incident to the edge with the given ID; null if no such edge esists
bool hasEdge ( IDType  id) const

Returns true, iff this graph has an edge with the given ID.

Parameters
idthe ID to be checked
Returns
true, iff this graph has an edge with the given ID
bool hasVertex ( IDType  id) const

Returns true if and only if this graph has a vertex with the given ID.

Parameters
idthe ID to be checked
Returns
true, iff this graph has a vertex with the given ID
IDType mergeEdges ( IDType  id1,
IDType  id2 
)

Merges the edges with the given IDs.

This automatically merges the i-th vertex incident to both edges, for every i up to the arity. An exception is thrown if the IDs do not represent two edges, the label differ or the arity differs.

Parameters
id1ID of an edge to be merged
id2ID of an edge to be merged
Returns
the ID of the new (merged) edge
Exceptions
InvalidInputExceptionif one of the IDs does not represent an edge or the edges differ in label or arity
IDType mergeEdges ( unordered_set< IDType > const &  ids)

Merges all edges in the given vector into one edge.

If an ID in the vector is not a valid edge ID, it is ignored, but if there are only invalid IDs, an exception is thrown.

Parameters
idsthe vector of IDs of edges which will be merged
Returns
the new ID of the merged edge
Exceptions
InvalidInputExceptionif all IDs in the given vector are non-valid edge IDs
void mergeVertexIntoFirst ( IDType  id1,
IDType  id2 
)

Same as mergeVertices(IDType,IDType), but it is guaranteed that the ID of the merged vertex will be the ID of the first vertex, i.e.

the second vertex will be merged into the first one.

Parameters
id1the ID of the vertex to which the other vertex is merged
id2the ID of the vertex which is merged into the other vertex
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 incident to the merging.

If one of the given IDs is not a vertex, an InvalidInputException is thrown. The ID of the new (merged) vertex is returned.

Parameters
id1the first vertex ID to be merged
id2the second vertex ID to be merged
Returns
the ID of the new (merged) vertex
Exceptions
InvalidInputExceptionif one of the given IDs is not a vertex
IDType mergeVertices ( unordered_set< IDType > const &  ids)

Merges all vertices in the given vector into one vertex.

If an ID in the vector is not a valid vertex ID, it is ignored, but if there are only invalid IDs, an exception is thrown.

Parameters
idsthe vector of IDs of vertices which will be merged
Returns
the new ID of the merged vertex
Exceptions
InvalidInputExceptionif all IDs in the given vector are non-valid vertex IDs
void setName ( string  s)

Sets the name of this graph to the given string.

Parameters
sthe new name of this graph
void streamTo ( std::ostream &  ost) const
overridevirtual

Prints a string representation of this graph to the given stream.

Parameters
ostthe stream to which the graph will be printed

Implements Streamable.

Reimplemented in Hypergraph.

Member Data Documentation

unordered_map<IDType, AnonHypergraph::ESet> connectedEdges
protected

Maps every vertex ID to a set containing all IDs of edges incident to them.

An edge is in the set as often as it is incident to the vertex.


The documentation for this class was generated from the following files: