Bridges-Python  3.4.4
Bridges(Python API)
Public Member Functions | Public Attributes | Static Public Attributes | List of all members
bridges.graph_adj_list.GraphAdjList Class Reference

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

Convenience methods are provided to add vertices and edges to the graph as well as retrieve the adjacency list of a vertex, given its id. 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:

@code
graph = GraphAdjList()
graph.add_vertex("a");
graph.add_vertex("b");
graph.add_edge("a", "b");
graph.get_vertex("a").set_shape("square");
graph.get_link_visualizer("a", "b").set_color("yellow");
Edge add_edge(self, Union[str, Element] src, Union[str, Element] dest, str label=None, any data=None, Union[str, Color] color="blue", float thickness=1.0, float opacity=1.0)
Adds a new edge to the graph.
Definition: graph_adj_list.py:164
Element add_vertex(self, str id, str label=None, Any data=None, Union[str, Color] color="blue", float opacity=1.0, Element original=None)
Adds a new vertex to the graph.
Definition: graph_adj_list.py:134
Edge get_link_visualizer(self, Union[str, Element] src, Union[str, Element] dest)
This is a convenience method to simplify access to the link visualizer; the method assumes the vertex...
Definition: graph_adj_list.py:401
Element get_vertex(self, key)
Getter for a specific vertex in the dictionary of vertices.
Definition: graph_adj_list.py:256

Adjacency lists are singly linked lists using the BRIDGES SLelement. Iterators are provided for easy traversal of the adjacency lists. For instance,

@code
graph = GraphAdjList()

for (e : graph.out_going_edge_set_of("a"))

print("a -> "+e.tov());

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 get_visualizer() and get_link_visualizer() methods. For instance,

GraphAdjList graph = something();
@code
graph.add_vertex("baskin");
graph.add_vertex("robins");
graph.add_edge("baskin","robins");
graph.get_visualizer().set_color("cyan");
graph.get_visualizer().set_shape("square");
graph.get_link_visualizer("baskin", "robins").set_color("green");
graph.get_link_visualizer("baskin", "robins").set_opacity("0.5f");
@author Matthew Mcquaigue, Kalpathi Subramanian
@date 2018,  7/23/19, 1/5/21

\sa graph adjacency list tutorial, 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

Public Member Functions

None __init__ (self)
 Constructor for a graph adj list. More...
 
str get_data_structure_type (self)
 Getter for the data structure type. More...
 
Element add_vertex (self, str id, str label=None, Any data=None, Union[str, Color] color="blue", float opacity=1.0, Element original=None)
 Adds a new vertex to the graph. More...
 
Edge add_edge (self, Union[str, Element] src, Union[str, Element] dest, str label=None, any data=None, Union[str, Color] color="blue", float thickness=1.0, float opacity=1.0)
 Adds a new edge to the graph. More...
 
None set_vertex_data (self, str src, Any vertex_data)
 Set for the data for a given vertex. More...
 
Any get_vertex_data (self, str src)
 Get the data stored as part of this vertex. More...
 
None set_edge_data (self, Union[str, Element] src, Union[str, Element] dest, Any edge_data)
 Set edge specific data for the edge. More...
 
dict vertices (self)
 Getter for the graph nodes. More...
 
Element get_vertex (self, key)
 Getter for a specific vertex in the dictionary of vertices. More...
 
Any get_adjacency_list (self, vertex=None)
 Gets the adjacency list. More...
 
Iterable key_set (self)
 Gets the keys for all the graph vertices. More...
 
Iterable value_set (self)
 Gets the values for all the graph vertices. More...
 
Iterable out_going_edge_set_of (self, Any v)
 Get the outgoing set of edges from a given vertex. More...
 
Any get_edge_data (self, Union[str, Element] src, Union[str, Element] dest)
 Get edge specific data from this edge. More...
 
Any get_edge (self, Union[str, Element] src, Union[str, Element] dest)
 Get the edge given its vertices. More...
 
bool are_all_vertices_located (self)
 Check if all vertices in the graph have a valid location. More...
 
def force_large_visualization (self, bool f)
 Force the rendering engine to use large graph visualization. More...
 
def force_small_visualization (self, bool f)
 Force the rendering engine to use small graph visualization. More...
 
Edge get_link_visualizer (self, Union[str, Element] src, Union[str, Element] dest)
 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. More...
 
ElementVisualizer get_visualizer (self, vertex)
 This is a convenience method to simplify access to the element visualizer. More...
 
dict get_data_structure_representation (self)
 Get the data structure representation. More...
 
dict get_data_structure_large_graph (self)
 Gets the JSON of the large graph representation. More...
 

Public Attributes

 adj_list
 

Static Public Attributes

int LargeGraphVertSize = 1000
 
bool force_large_viz = False
 
bool force_small_viz = False
 

Constructor & Destructor Documentation

◆ __init__()

None bridges.graph_adj_list.GraphAdjList.__init__ (   self)

Constructor for a graph adj list.

Returns
None

Member Function Documentation

◆ add_edge()

Edge bridges.graph_adj_list.GraphAdjList.add_edge (   self,
Union[str, Element src,
Union[str, Element dest,
str   label = None,
any   data = None,
Union[str, Color]   color = "blue",
float   thickness = 1.0,
float   opacity = 1.0 
)

Adds a new edge to the graph.

Adds edge to that vertex's adjacency list; user is responsible for checking if the vertex already exists. This version assumes a default edge weight of 1.

Parameters
srcsource vertex of edge
destdestination vertex of edge
labellabel of edge,
colorcolor of edge,
thicknessthickness of edge,
opacityopacity of edge,
datadata the edge will hold
Returns
newly created Edge
Exceptions
ValueErrorif the src and dest vertices do not exist

◆ add_vertex()

Element bridges.graph_adj_list.GraphAdjList.add_vertex (   self,
str  id,
str   label = None,
Any   data = None,
Union[str, Color]   color = "blue",
float   opacity = 1.0,
Element   original = None 
)

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. Note: it is the user's responsibility to check for duplicate vertices

Parameters
idthe vertex id
labelvertex label
datathe vertex data
colorcolor of vertex
opacityopacity of vertex
originalan existing Element instance to copy, this will nullify other arguments
Returns
newly created Vertex

◆ are_all_vertices_located()

bool bridges.graph_adj_list.GraphAdjList.are_all_vertices_located (   self)

Check if all vertices in the graph have a valid location.

Returns
a boolean

◆ force_large_visualization()

def bridges.graph_adj_list.GraphAdjList.force_large_visualization (   self,
bool  f 
)

Force the rendering engine to use 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
fboolean set to true to force the visualization engine to use large graphs visualization. Setting to false does not prevent large visualization to be used, just does not force it.
Returns
None

◆ force_small_visualization()

def bridges.graph_adj_list.GraphAdjList.force_small_visualization (   self,
bool  f 
)

Force the rendering engine to use 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
fboolean set to true to force the visualization engine to use small graphs visualization. Setting to false does not prevent small visualization to be used, just does not force it.
Returns
None

◆ get_adjacency_list()

Any bridges.graph_adj_list.GraphAdjList.get_adjacency_list (   self,
  vertex = None 
)

Gets the adjacency list.

Parameters
vertexinput vertex
Returns
list adjacency list of this vertex

◆ get_data_structure_large_graph()

dict bridges.graph_adj_list.GraphAdjList.get_data_structure_large_graph (   self)

Gets the JSON of the large graph representation.

Returns
the data structure representation

◆ get_data_structure_representation()

dict bridges.graph_adj_list.GraphAdjList.get_data_structure_representation (   self)

Get the data structure representation.

Returns
dict, a JSON representation of the structure

◆ get_data_structure_type()

str bridges.graph_adj_list.GraphAdjList.get_data_structure_type (   self)

Getter for the data structure type.

Returns
str representing the type

◆ get_edge()

Any bridges.graph_adj_list.GraphAdjList.get_edge (   self,
Union[str, Element src,
Union[str, Element dest 
)

Get the edge given its vertices.

Parameters
srcsource vertex of edge
destdestination vertex of edge
Returns
edge corresponding to the source and dest vertices

◆ get_edge_data()

Any bridges.graph_adj_list.GraphAdjList.get_edge_data (   self,
Union[str, Element src,
Union[str, Element dest 
)

Get edge specific data from this edge.

Parameters
srcsource vertex of edge
destdestination vertex of edge
Returns
data stored on this edge

◆ get_link_visualizer()

Edge bridges.graph_adj_list.GraphAdjList.get_link_visualizer (   self,
Union[str, Element src,
Union[str, Element dest 
)

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 of edge
destdestination vertex of edge

◆ get_vertex()

Element bridges.graph_adj_list.GraphAdjList.get_vertex (   self,
  key 
)

Getter for a specific vertex in the dictionary of vertices.

Parameters
keyThe associated key for the vertex
Returns
vertex Element or None

◆ get_vertex_data()

Any bridges.graph_adj_list.GraphAdjList.get_vertex_data (   self,
str  src 
)

Get the data stored as part of this vertex.

Parameters
srcthe source vertex
Returns
data stored at this vertex

◆ get_visualizer()

ElementVisualizer bridges.graph_adj_list.GraphAdjList.get_visualizer (   self,
  vertex 
)

This is a convenience method to simplify access to the element visualizer.

   The method assumes the vertex name points to an existing vertex, else an exception is thrown
Parameters
vertexThe vertex for which visualizer is wanted

◆ key_set()

Iterable bridges.graph_adj_list.GraphAdjList.key_set (   self)

Gets the keys for all the graph vertices.

Returns
the keys for the vertices in the graph; used with iterators

◆ out_going_edge_set_of()

Iterable bridges.graph_adj_list.GraphAdjList.out_going_edge_set_of (   self,
Any  v 
)

Get the outgoing set of edges from a given vertex.

Parameters
vthe given vertex
Returns
outgoing edge set (used in iterartors)

◆ set_edge_data()

None bridges.graph_adj_list.GraphAdjList.set_edge_data (   self,
Union[str, Element src,
Union[str, Element dest,
Any  edge_data 
)

Set edge specific data for the edge.

Parameters
srcsource vertex of edge
destdestination vertex of edge
edge_dataedge specific data

◆ set_vertex_data()

None bridges.graph_adj_list.GraphAdjList.set_vertex_data (   self,
str  src,
Any  vertex_data 
)

Set for the data for a given vertex.

Parameters
srcthe source vertex
vertex_dataThe data for the vertex
Returns
None
Exceptions
ValueErrorif the source vertex doesnt exist

◆ value_set()

Iterable bridges.graph_adj_list.GraphAdjList.value_set (   self)

Gets the values for all the graph vertices.

Returns
the values for the vertices in the graph; used with iterators

◆ vertices()

dict bridges.graph_adj_list.GraphAdjList.vertices (   self)

Getter for the graph nodes.

Returns
dict

Member Data Documentation

◆ adj_list

bridges.graph_adj_list.GraphAdjList.adj_list

◆ force_large_viz

bool bridges.graph_adj_list.GraphAdjList.force_large_viz = False
static

◆ force_small_viz

bool bridges.graph_adj_list.GraphAdjList.force_small_viz = False
static

◆ LargeGraphVertSize

int bridges.graph_adj_list.GraphAdjList.LargeGraphVertSize = 1000
static

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