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

Detailed Description

The GraphAdjMatrix class can be used to represent adjacency matrix based graphs in BRIDGES.

The GraphAdjMatrix class can be used to represent adjacency matrix based graphs in BRIDGES; it takes 2 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, and (2) E, an application defined type, and used in the Edge representation. The class is simply 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 lets us use strings or integral ids for vertices. The edges are accessed by a second hashmap from each vertex, again assuring near constant access time. Each edge contains the terminating vertex id and weight, as defined by the Edge class structure.

Convenience methods are provided to add vertices and edges to the graph. Edges are retrieved by using the dual hashmap, given the vertex ids of the edge. Methods to access the element and link visualizer are now provided, indexed vertex ids, making it easier to set visual attributes to graph nodes and links.

See also
Example tutorial at https://bridgesuncc.github.io/tutorials/Graph_AM.html
Author
Kalpathi Subramanian, Mihai Mehedint
Date
7/12/15, 5/18/17, 4/23/18
Parameters
Korderable key (string, int, etc) that is used to index into vertex
E1vertex specific information, for graph vertices
E2edge specific information, for graph vertices

Public Member Functions

 GraphAdjMatrix ()
 
String getDataStructType ()
 
void addVertex (K k, E1 e)
 
void addEdge (K src, K dest)
 
void addEdge (K src, K dest, int weight)
 
void setVertexData (K src, E1 vertex_data)
 Sets data for a graph vertex. More...
 
E1 getVertexData (K src)
 
void setEdgeData (K src, K dest, E2 data)
 
E2 getEdgeData (K src, K dest)
 
HashMap< K, Element< E1 > > getVertices ()
 
HashMap< K, HashMap< K, Integer > > getAdjacencyMatrix ()
 
HashMap< K, Integer > getAdjacencyMatrix (K key)
 
LinkVisualizer getLinkVisualizer (K src, K dest) throws Exception
 
ElementVisualizer getVisualizer (K vertex) throws Exception
 
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

◆ GraphAdjMatrix()

Constructor

Member Function Documentation

◆ addEdge() [1/2]

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

Adds a new edge to the graph, adds it to the index corresponding to the source, destination vertex ids; this version of the method assumes an edge weight of 1 (unweighted graph); user is responsible for checking if the vertices already exist, else an exception is thrown.

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

◆ addEdge() [2/2]

void bridges.base.GraphAdjMatrix< K, E1, E2 >.addEdge ( src,
dest,
int  weight 
)

Adds a new edge of weight 'weight' to the graph, adds it to the index corresponding to the source, destination vertex ids; user is responsible for checking if the vertices already exist, else an exception is thrown.

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

◆ addVertex()

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

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 key value
e- user specified data, part of the vertex data

◆ getAdjacencyMatrix() [1/2]

HashMap<K, HashMap<K, Integer> > bridges.base.GraphAdjMatrix< K, E1, E2 >.getAdjacencyMatrix ( )

Gets the adjacency matrix

Returns
- the graph's adjacency matrix

◆ getAdjacencyMatrix() [2/2]

HashMap<K, Integer> bridges.base.GraphAdjMatrix< K, E1, E2 >.getAdjacencyMatrix ( key)

Gets the row of the adjacency matrix corresponding to the key

Parameters
keykey value
Returns
- the graph's adjacency matrix

◆ getDataStructType()

String bridges.base.GraphAdjMatrix< 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.GraphAdjMatrix< K, E1, E2 >.getDataStructureRepresentation ( )

Reimplemented from bridges.base.DataStruct.

◆ getEdgeData()

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

Gets data for an edge

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

◆ getLinkVisualizer()

LinkVisualizer bridges.base.GraphAdjMatrix< K, E1, E2 >.getLinkVisualizer ( src,
dest 
) throws Exception

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

◆ getVertexData()

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

Gets data for a vertex

Parameters
srcsource vertex of edge

◆ getVertices()

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

This method returns the graph nodes

return – vertices held in an unordered map

◆ getVisualizer()

ElementVisualizer bridges.base.GraphAdjMatrix< K, E1, E2 >.getVisualizer ( vertex) throws Exception

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

◆ setEdgeData()

void bridges.base.GraphAdjMatrix< K, E1, E2 >.setEdgeData ( src,
dest,
E2  data 
)

Sets data for an edge

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

◆ setVertexData()

void bridges.base.GraphAdjMatrix< 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: