weighted_topsort module

It is an implementation of Topological sort using Depth First Search. The implementation provides a way to sort the nodes of the graph based on the weights assigned to each node. When a node is dependent on two other nodes the node with lowest weight is resolved first.

The input graph is a json structure with dependecies for the node are indicated as a list. The weights for the nodes are provided as a set of tag-value pairs.

exception weighted_topsort.CyclicGraphError(message)[source]

Bases: Exception

class weighted_topsort.TopSort(graph, weights)[source]

Bases: list

Topological sort with weighted nodes

Parameters
  • graph (json) – Directed graph to be sorted in json format with dependencies as values to nodes

  • weights (json) – The weights of nodes as json key value pairs

Return type

list