Bridges-Java  3.4.2
Bridges(Java API)
Public Member Functions | List of all members
bridges.base.GraphAdjList< K, E1, E2 > Class Template Reference
Inheritance diagram for bridges.base.GraphAdjList< K, E1, E2 >:
bridges.base.DataStruct

Detailed Description

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.

In most cases, you want all the three types to be the same, or in cases where you only care about the vertex key type, one can use the GraphAdjListSimple helper class.

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());

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, Integer, 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");

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

Parameters
Korderable key (String, Integer, etc) that is used to index into vertex
E1holds vertex specific information, defined by application
E2holds edge specific information, defined by application
See also
Example tutorial at https://bridgesuncc.github.io/tutorials/Graph.html
Author
Kalpathi Subramanian, Erik Saule
Date
6/29/15, 5/18/17, 4/24/18, 7/14/19, 1/5/21

Public Member Functions

 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. Note that the list can be traversed using iterators. See example at top of page. 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 ()
 

Additional Inherited Members

- Protected Attributes inherited from bridges.base.DataStruct
String QUOTE = "\""
 
- Package Attributes inherited from bridges.base.DataStruct
String COMMA = ","
 
String COLON = ":"
 
String OPEN_CURLY = "{"
 
String CLOSE_CURLY = "}"
 
String OPEN_PAREN = "("
 
String CLOSE_PAREN = ")"
 
String OPEN_BOX = "["
 
String CLOSE_BOX = "]"
 

Constructor & Destructor Documentation

◆ GraphAdjList()

Constructor

Member Function Documentation

◆ addEdge() [1/2]

void bridges.base.GraphAdjList< K, E1, E2 >.addEdge ( src,
dest 
)

adds a new edge to the graph.

Adds a new edge to the graph, adds it to that vertex's adjacency list; user is responsible for checking if the vertex already exists. This version assumes the edge data is null.

Parameters
src- source vertex of edge
dest- destination vertex of edge

◆ addEdge() [2/2]

void bridges.base.GraphAdjList< K, E1, E2 >.addEdge ( src,
dest,
E2  data 
)

adds a new edge to the graph.

Adds a new edge to the graph, adds it to that vertex's adjacency list; user is responsible for checking if the vertex already exists.

Parameters
src- source vertex of edge
dest- destination vertex of edge
data- edge data

◆ addVertex()

void bridges.base.GraphAdjList< K, E1, E2 >.addVertex ( k,
E1  e 
)

adds a new vertex to the graph.

Adds a new vertex to the graph, initializes the adjacency list; user is responsible for checking if the vertex already exists. This method will replace the value for this key

Parameters
k- vertex id
e- vertex info, currently used as a label by default
Returns
none

◆ forceLargeVisualization()

void bridges.base.GraphAdjList< K, E1, E2 >.forceLargeVisualization ( boolean  f)

Forces the graph use the large graph visualization.

This forces the rendering to a more bandwidth efficient at the cost of having less features. The large graph visualization only renders vertices that have specified locations. The only usable attribute for vertices and edges are colors.

Parameters
ftrue to force large visualization. Setting to false does not prevent large visualization to be used, just does not force it.

◆ forceSmallVisualization()

void bridges.base.GraphAdjList< K, E1, E2 >.forceSmallVisualization ( boolean  f)

Forces the graph to use the small graph visualization.

The small visualization uses more bandwidth, have more features, and support a force directed layout for vertices which do not have a specified location.

Parameters
ftrue to force using the small visualization. Setting to false does not prevent small visualization to be used, just does not force it.

◆ getAdjacencyList() [1/2]

HashMap<K, SLelement<Edge<K, E2> > > bridges.base.GraphAdjList< K, E1, E2 >.getAdjacencyList ( )

Gets the graph's adjacency list.

Returns
the graph's adjacency lists

◆ getAdjacencyList() [2/2]

SLelement<Edge<K, E2> > bridges.base.GraphAdjList< K, E1, E2 >.getAdjacencyList ( vertex)

Gets the adjacency list of a vertex. Note that the list can be traversed using iterators. See example at top of page.

Parameters
vertexthe key of the vertex
Returns
- the graph's adjacency list corresponding to this vertex

◆ getDataStructType()

String bridges.base.GraphAdjList< K, E1, E2 >.getDataStructType ( )

This method gets the data structure type.

Returns
The date structure type as a string

Reimplemented from bridges.base.DataStruct.

◆ getDataStructureRepresentation()

String bridges.base.GraphAdjList< K, E1, E2 >.getDataStructureRepresentation ( )

Reimplemented from bridges.base.DataStruct.

◆ getEdgeData()

E2 bridges.base.GraphAdjList< K, E1, E2 >.getEdgeData ( src,
dest 
)

Gets data for an edge.

Parameters
srcsource vertex of edge
destdestination vertex of edge
Returns
the edge data, or null if the edge does not exist

◆ getLinkVisualizer()

LinkVisualizer bridges.base.GraphAdjList< K, E1, E2 >.getLinkVisualizer ( src,
dest 
)

Access a LinkVisualizer associated with an edge.

This is a convenience method to simplify access to the link visualizer; the method assumes the vertex names point to existing vertices, else an exception is thrown

Parameters
srcsource vertex
destdestination vertex
Returns
the LinkVisualizer of an edge from src to dest, or null if the edge does not exist

◆ getVertex()

Element<E1> bridges.base.GraphAdjList< K, E1, E2 >.getVertex ( key)

returns a vertex from its key

This is a convenience method to retrieve a vertex given its key

Returns
graph vertex corresponding to its key (or null if the vertex does not exist)

◆ getVertexData()

E1 bridges.base.GraphAdjList< K, E1, E2 >.getVertexData ( src)

Gets data for an edge.

Parameters
src- source vertex of edge

◆ getVertices()

HashMap<K, Element<E1> > bridges.base.GraphAdjList< K, E1, E2 >.getVertices ( )

This method returns the graph vertices.

Returns
vertices held in the hashmap

◆ getVisualizer()

ElementVisualizer bridges.base.GraphAdjList< K, E1, E2 >.getVisualizer ( vertex)

Access the ElementVisualizer associated with a vertex.

This is a convenience method to simplify access to the element visualizer; the method assumes the vertex name points to an existing vertice, else an exception is thrown

Parameters
vertexgraph vertex
Returns
the element visualizer of this vertex

◆ outgoingEdgeSetOf()

Iterable<Edge<K, E2> > bridges.base.GraphAdjList< K, E1, E2 >.outgoingEdgeSetOf ( vertex)

returns an iterable set of outgoing edge of a vertex

Gets a vector of the outgoing edges from a graph vertex

Parameters
vertexvertex identifier
Returns
an iterable set of the outgoing edge of this vertex

◆ setEdgeData()

void bridges.base.GraphAdjList< K, E1, E2 >.setEdgeData ( src,
dest,
E2  edge_data 
)

Sets data for an edge.

Parameters
src- source vertex of edge
dest- destination vertex of edge
edge_data- edge data

◆ setVertexData()

void bridges.base.GraphAdjList< K, E1, E2 >.setVertexData ( src,
E1  vertex_data 
)

Sets data for a graph vertex.

Parameters
srcsource vertex of edge
vertex_datavertex data

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