pyrival.graphs¶
pyrival.graphs.bfs¶
-
pyrival.graphs.bfs.
bfs
(graph, start=0)¶
-
pyrival.graphs.bfs.
layers
(graph, start=0)¶
pyrival.graphs.dijkstra¶
-
pyrival.graphs.dijkstra.
dijkstra
(n, graph, start)¶ Uses Dijkstra’s algortihm to find the shortest path between in a graph.
pyrival.graphs.dinic¶
pyrival.graphs.find_path¶
-
pyrival.graphs.find_path.
find_path
(start, end, parents)¶ Constructs a path between two vertices, given the parents of all vertices.
pyrival.graphs.hopcroft_karp¶
Produces a maximum cardinality matching of a bipartite graph
Example:
- 0—0
- 1—1
- /
- /
/
- 2 2
//
/
3
>>>> n = 4 >>>> m = 3 >>>> graph = [[0, 1], [1, 2], [1], [2]] >>>> match1, match2 = hopcroft_karp(graph, n, m) >>>> match1 [0, 1, -1, 2] >>>> match2 [0, 1, 3]
- Meaning
0—0
1—1
- 2 2
- /
/
/
3
pyrival.graphs.maximum_matching¶
-
pyrival.graphs.maximum_matching.
maximum_matching
(edges, mod=1073750017)¶ Returns the maximum cardinality matching of any simple graph (undirected, unweighted, no self-loops) Uses a randomized algorithm to compute the rank of the Tutte matrix The rank of the Tutte matrix is equal to twice the size of the maximum matching with high probability The probability for error is not more than n/mod
Complexity: O(n ^ 3) worst case, O(n * |matching_size|) on average
Parameters: - edges – a list of edges, assume nodes can be anything numbered from 0 to max number in edges
- mod – optional, a large random prime
Returns: the maximum cardinality matching of the graph