template<typename K, typename E1 = K, typename E2 = E1>
class bridges::datastructure::GraphAdjList< K, E1, E2 >
This class provides methods to represent adjacency list based graphs.
The GraphAdjList class can be used to represent adjacency list
based graphs in BRIDGES; it takes 3 generic parameters: (1) K, which is an orderable key value used in accessing vertices (in constant time) using an STL map. This permits data sets that need to be accessed by keys that are strings, (2) E1, for maintaining vertex specific data, and (3) E2, for maintaining edge specific data. The class is a wrapper around the C++ unordered map class and, thus, derives all its operations from it. BRIDGES provides methods to visualize the graph and its contents.
The vertices of the graph are held in a C++ hashmap, for near constant time access; this enables us to use strings or integer ids for vertices. The adjacency lists are linked lists of SLelemnt type, The SLelement contains edge information (stored in its data as a generic). Each edge, of type Edge, contains the source, destination vertices and link attributes (color, opacity, thickness)
Convenience method addVertex() is provided to add vertices to the graph, and addEdge() is provided to add edges. Edges are retrieved by using the map and the adjcency list, given the vertex ids of the edge. Vertices can be styled directly from the vertex element returned by getVertex(), and edges are styled from a LinkVisualizer one can access through getLinkVisualizer(). Here is a simple example:
GraphAdjList<string, Integer, Double> graph = new GraphAdjList<string, int, double> ();
graph.addVertex("a");
graph.addVertex("b");
graph.addEdge("a", "b");
graph.getVertex("a").setShape("square");
graph.getLinkVisualizer("a", "b").setColor("yellow");
Adjacency lists are singly linked lists using the BRIDGES SLelement. Iterators are provided for easy traversal of the adjacency lists. For instance,
GraphAdjList<string, int, double> graph = something();
for (Edge<string, double> e : graph.outgoingEdgeSetOf("a"))
System.out.println(
"a -> "+
e.getTo());
Graphs can have their nodes and links affected by visual attributes. Nodes can have color, size, opacity and shape and detailed in the ElementVisualizer class. Edges support attributes such as color, thickness and opacity and are detailed in the LinkVisualizer class. Element and link attributes are set using the getVisualizer() and getLinkVisualizer() methods. For instance,
GraphAdjList<string, int, double> graph = something();
graph.addVertex("baskin");
graph.addVertex("robins");
graph.addEdge("baskin","robins");
graph.getVisualizer()->setColor("cyan");
graph.getVisualizer()->setShape("square");
graph.getLinkVisualizer("baskin", "robins")->setColor("green");
graph.getLinkVisualizer("baskin", "robins")->setOpacity("0.5f");
- Parameters
-
K | used as an index to retrieve vertices, |
E1 | data type used to store vertex specific information, |
E2 | data type used to store edge specific information |
- Author
- Kalpathi Subramanian, Erik Saule
- Date
- Last modified 4/22/18, 7/12/19, 12/28/20, 1/5/21
There is a tutorial about Graph Adjacency List : https://bridgesuncc.github.io/tutorials/Graph.html
There are two visualization engines available for graph. The small graph visualization supports all attributes of vertices and edges but is prohibitively slow on large graphs. The large graph visualization only supports locations (actually they are mandatory) and colors, all other attributes are ignored.
BRIDGES picks the rendering engine automatically. But it can be forced to pick one used forceLargeVizualization() and forceSmallVizualization()
|
| GraphAdjList ()=default |
|
| GraphAdjList (GraphAdjList &&gr)=default |
|
virtual | ~GraphAdjList () override |
|
virtual const string | getDStype () const override |
| Get the string representation of this data structure type. More...
|
|
void | addVertex (const K &k, const E1 &e=E1()) |
| Adds a vertex to the graph. More...
|
|
void | addEdge (const K &src, const K &dest, const E2 &data=E2()) |
|
bool | isEdge (const K &src, const K &dest) |
|
const E1 & | getVertexData (const K &src) & |
| Gets vertex data for a graph vertex. More...
|
|
void | setVertexData (const K &vertID, E1 const &data) |
| Loads vertex specific information for a graph vertex. More...
|
|
E2 & | getEdgeData (const K &src, const K &dest) |
| Gets edge data for the edge from "src" to "dest". More...
|
|
E2 const & | getEdgeData (const K &src, const K &dest) const |
| Gets edge data for the edge from "src" to "dest" - const version. More...
|
|
void | setEdgeData (const K &src, const K &dest, E2 &data) |
| Loads edge specific information for the edge from "src" to "dest". More...
|
|
unordered_map< K, Element< E1 > * > * | getVertices () |
| Return the graph nodes. More...
|
|
const unordered_map< K, Element< E1 > * > * | getVertices () const |
| Return the graph nodes - const version. More...
|
|
const Element< E1 > * | getVertex (const K &key) const |
| Return the vertex corresponding to a key. More...
|
|
Element< E1 > * | getVertex (const K &key) |
|
Edge< K, E2 > | getEdge (const K &src, const K &dest) |
| Get the edge between src and dest vertices. More...
|
|
const unordered_map< K, SLelement< Edge< K, E2 > > * > & | getAdjacencyList () const |
| Return the adjacency list. More...
|
|
SLelement< Edge< K, E2 > > * | getAdjacencyList (const K &k) |
| Returns adjacency list of a vertex with name k. More...
|
|
const SLelement< Edge< K, E2 > > * | getAdjacencyList (const K &k) const |
|
ElementVisualizer * | getVisualizer (const K &k) |
| Returns the visualizer corresponding to a graph vertex. convenient method to set attributes of the graph vertex. More...
|
|
LinkVisualizer * | getLinkVisualizer (const K &k1, const K &k2) |
| Returns the link visualizer corresponding to an edge. Returns the link visualizer corresponding to two graph nodes with an existing link; error returned if no link exists. More...
|
|
void | forceLargeVisualization (bool f) |
| Force the rendering engine to use large graph visualization. More...
|
|
void | forceSmallVisualization (bool f) |
| Force the rendering engine to use small graph visualization. More...
|
|
KeySet_helper | keySet () const |
|
SLelement< Edge< K, E2 > >::SLelement_listhelper | outgoingEdgeSetOf (K const &k) |
| This method is useful for iterating through a set of outgoing edges from a vertex. More...
|
|
SLelement< Edge< K, E2 > >::SLelement_constlisthelper | outgoingEdgeSetOf (K const &k) const |
| This method is useful for iterating through a set of outgoing edges from a vertex - const version. More...
|
|
VertexElementSet_listhelper | vertexSet () |
|
constVertexElementSet_listhelper | vertexSet () const |
|
virtual | ~DataStructure ()=default |
|