The GraphAdjList class can be used to represent adjacency list based graphs in BRIDGES.
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 a hashmap. 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 Java Hashmap 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 Java hashmap, for near constant time access; this enables to use strings or integer ids for vertices. The adjacency lists, also a Java hashmap are built for each vertex and contain the edge (source, destination vertices) in the Edge structure, defined separately.
Convenience method addVertex() is provided to add vertices to the graph, and addEdge() is provided to add edges. Edges are retrieved by using the dual hashmap, 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, Integer, 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, Integer, Double> graph = something();
for (Edge<String, Double> e : graph.outgoingEdgeSetOf("a"))
System.out.println("a -> "+e.getTo());
- See also
- Example tutorial at http://bridgesuncc.github.io/tutorials/Graph_AL.html
- Author
- Kalpathi Subramanian, Erik Saule
- Date
- 6/29/15, 5/18/17, 4/24/18, 7/14/19
- Parameters
-
K | orderable key (string, int, etc) that is used to index into vertex |
E1 | holds vertex specific information, defined by application |
E2 | holds edge specific information, defined by application |
|
| GraphAdjList () |
|
String | getDataStructType () |
| This method gets the data structure type. More...
|
|
void | addVertex (K k, E1 e) |
| adds a new vertex to the graph. More...
|
|
void | addEdge (K src, K dest) |
| adds a new edge to the graph. More...
|
|
void | addEdge (K src, K dest, E2 data) |
| adds a new edge to the graph. More...
|
|
void | setVertexData (K src, E1 vertex_data) |
| Sets data for a graph vertex. More...
|
|
E1 | getVertexData (K src) |
| Gets data for an edge. More...
|
|
void | setEdgeData (K src, K dest, E2 edge_data) |
| Sets data for an edge. More...
|
|
E2 | getEdgeData (K src, K dest) |
| Gets data for an edge. More...
|
|
HashMap< K, Element< E1 > > | getVertices () |
| This method returns the graph vertices. More...
|
|
Element< E1 > | getVertex (K key) |
| returns a vertex from its key More...
|
|
HashMap< K, SLelement< Edge< K, E2 > > > | getAdjacencyList () |
| Gets the graph's adjacency list. More...
|
|
SLelement< Edge< K, E2 > > | getAdjacencyList (K vertex) |
| Gets the adjacency list of a vertex. More...
|
|
Iterable< Edge< K, E2 > > | outgoingEdgeSetOf (K vertex) |
| returns an iterable set of outgoing edge of a vertex More...
|
|
LinkVisualizer | getLinkVisualizer (K src, K dest) |
| Access a LinkVisualizer associated with an edge. More...
|
|
ElementVisualizer | getVisualizer (K vertex) |
| Access the ElementVisualizer associated with a vertex. More...
|
|
void | forceLargeVisualization (boolean f) |
| Forces the graph use the large graph visualization. More...
|
|
void | forceSmallVisualization (boolean f) |
| Forces the graph to use the small graph visualization. More...
|
|
String | getDataStructureRepresentation () |
|
abstract String | getDataStructType () |
|
abstract String | getDataStructureRepresentation () |
|