snowdrop.src.info package

Submodules

snowdrop.src.info.graph module

Python class that demonstrates the essential facts and functionalities of graphs. This class represents a directed graph using adjacency list representation It finds biconnected components in a given undirected graph with complexity : O(V + E)

Original version of the code can be found at:

https://www.python-course.eu/graphs_python.php https://tutorialspoint.dev/data-structure/graph-data-structure/biconnected-components

Modified by A.Goumilevski

class snowdrop.src.info.graph.Graph(graph_dict={}, m=None, weights=None)[source]

Bases: object

Graph class.

BCC()[source]

Function to do DFS traversal. It uses recursive BCCUtil().

BCCUtil(u, parent, low, disc, st)[source]

A recursive function that finds and prints strongly connected components using DFS traversal

u –> The vertex to be visited next disc[] –> Stores discovery times of visited vertices low[] – >> earliest visited vertex (the vertex with minimum

discovery time) that can be reached from subtree rooted with current vertex

st – >> To store visited edges

Delta()[source]

Get the maximum degree of the vertices.

addEdge(x, y)[source]

Function to add an edge to graph.

add_edge(edge, w=None)[source]

Add an edge.

It is assumed that edge is of type set, tuple or list; between two vertices can be multiple edges!

add_vertex(vertex)[source]

Add graph vertex.

If the vertex is not in self.__graph_dict, a key “vertex” with an empty list as a value is added to the dictionary. Otherwise nothing has to be done.

connected(t)[source]

Return connected vertices of a minimum spanning tree.

Args:
tlist

List of vertices.

Returns:

Connected vertices of a minimum spanning tree.

degree_sequence()[source]

Calculate the degree sequence.

delta()[source]

Get the minimum degree of the vertices.

density()[source]

Calculate the density of a graph.

diameter()[source]

Calculate the diameter of the graph.

edges()[source]

Return the edges of a graph.

static erdoes_gallai(dsequence)[source]

Check if the condition of the Erdoes-Gallai inequality is fullfilled.

find(parent, i)[source]

Find a set of an element i.

This algorithm uses path compression technique.

Args:
parentlist

Parent list.

iint

Element.

Returns:

Set of an element i.

find_all_paths(start_vertex, end_vertex, path=[])[source]

Find all paths from start_vertex to end_vertex in graph.

find_distance(start_vertex, end_vertex)[source]

Find number of edges from start_vertex to end_vertex.

find_isolated_vertices()[source]

Return a list of isolated vertices.

find_path(start_vertex, end_vertex, path=[])[source]

Find a path from start_vertex to end_vertex in graph.

find_shortest_path(start_vertex, end_vertex, path=[])[source]

Find shortest path from start_vertex to end_vertex.

getBiconnectedComponents()[source]

Get biconnected components in a graph.

getMinimumSpanningTree()[source]

Kruskal’s algorithm to find Minimum Spanning Tree (MST)of a given connected, undirected and weighted graph.

Time Complexity: O(ElogE) or O(ElogV). Here E is the number of edges and V is the number of vertices. Sorting of edges takes O(ELogE) time. After sorting, we iterate through all edges and apply find-union algorithm. The find and union operations can take atmost O(LogV) time. So overall complexity is O(ELogE + ELogV) time. The value of E can be atmost O(V2), so O(LogV) are O(LogE) same. Therefore, overall time complexity is O(ElogE) or O(ElogV).

https://www.geeksforgeeks.org/kruskals-minimum-spanning-tree-algorithm-greedy-algo-2/

Args:

self: Graph object.

Returns:

None.

get_components()[source]

Find isolated components of a graph.

get_connected_vertices(start_vertex, vertices_encountered=None, gdict=None)[source]

Determine if graph is connected.

get_vertices()[source]

Get graph vertices.

Returns:
verticeslist

List of vertices.

isCyclic()[source]

Check whether a given graph contains a cycle or not.

Returns:
bool

True if graph is cyclic and False otherwise.

is_connected(vertices_encountered=None, start_vertex=None)[source]

Determine if graph is connected.

static is_degree_sequence(sequence)[source]

Find degree sequence.

Method returns True, if the “sequence” is a degree sequence, i.e. a non-increasing sequence. Otherwise returns False.

printBiconnectedComponents()[source]
summary()[source]
union(parent, rank, x, y)[source]

Return union of two sets of x and y.

This algoritm sorts uses union by rank.

Args:
parentlist

Parent list of vertices.

ranklist

Rank of tree.

xlist

Graph vertices.

ylist

Graph vertices.

Returns:

None.

vertex_degree(vertex)[source]

Find vertex degree.

The degree of a vertex is the number of edges connecting it, i.e. the number of adjacent vertices. Loops are counted double, i.e. every occurence of vertex in the list of adjacent vertices.

vertices()[source]

Return the vertices of a graph.

class snowdrop.src.info.graph.LinkedList(sequence=None)[source]

Bases: object

A Simple linked list class.

append(new_data)[source]

Append a new node at the end.

static display(self)[source]

Display the linked list.

getNode(v)[source]

Return node of a linked list by value.

getParentNode(v)[source]

Get previous node in the linked list.

insertAfter(prev_node, new_data)[source]

Insert a new node after the given prev_node.

insertBefore(node, new_data)[source]

Insert a new node before the given node.

push(new_data)[source]

Insert a new node at the beginning.

static toList(self)[source]

Convert a linked list to a list.

class snowdrop.src.info.graph.Node(value, next=None)[source]

Bases: object

Node class.

next = None
value = None

snowdrop.src.info.graphs module

Created on Sat Apr 18 13:01:21 2020

@author: A.Goumilevski

snowdrop.src.info.graphs.createClusters(model, img_file_name='Minimum_Spanning_Tree.png')[source]

Create graph of components of model equations endogenous variables.

Parameters:
param model:

The Model object.

type model:

Instance of class Model.

snowdrop.src.info.graphs.createGraph(model, img_file_name='Equations_Graph.png')[source]

Create a graph of endogenous variables of a model.

Parameters:
param model:

The Model object.

type model:

Instance of class Model.

snowdrop.src.info.graphs.getInfo(model)[source]

Get information on components of a graph’ model equations variables.

Parameters:
param model:

The Model object.

type model:

Instance of class Model.

snowdrop.src.info.graphs.plot_image(G, pos, fpath)[source]
snowdrop.src.info.graphs.save_image(G, pos, fpath, colors, size)[source]
snowdrop.src.info.graphs.summary(components, b=False)[source]

snowdrop.src.info.test module

Created on Sun Apr 19 16:16:04 2020

@author: Alexei

Module contents