codezonediitj / pydatastructs

A python package for data structures and algorithms
https://pydatastructs.readthedocs.io/en/stable/
Other
202 stars 270 forks source link

#289 add floyd warshall algorithm #302

Closed Kiran-Venkatesh closed 4 years ago

Kiran-Venkatesh commented 4 years ago

References to other Issues or PRs or Relevant literature Fixes #289

Brief description of what is fixed or changed I added _floyd_warshall_adjacency_list function and _floyd_warshall_adjacency_matrix function in pydatastructs.graphs.algorithms to determine the distances and predecessors for given source and target. Added shortest_path construction function to construct the shortest path from the predecessor's details determined using the function _floyd_warshall_adjacency_list or _floyd_warshall_adjacency_matrix. In that floyd_warshall algorithm, function added conditions for checking infinity cases to avoid unnecessary computations when adding with other valid numbers. Other comments The Floyd-Warshall algorithm can be applied on a graph in a way similar to that of the Bellman-Ford algorithm. Example: shortest_paths(G, 'floyd_warshall', 'V1') A small modification will be required in the shortest_paths function in order to utilize the all pair shortest path advantage of the Floyd-Warshall algorithm. The current implementation of shortest_paths function supports only the single-source shortest path nature of the Bellman-Ford algorithm. It works for both Source and target cases and also Dynamic programming approach is used. That condition checking of infinity helps to avoid key_error problems.

czgdp1807 commented 4 years ago

Could you please resolve the conflicts?

Kiran-Venkatesh commented 4 years ago

What things to change?

codecov[bot] commented 4 years ago

Codecov Report

Merging #302 (db2ab80) into master (8877bf7) will increase coverage by 0.011%. The diff coverage is 100.000%.

@@              Coverage Diff              @@
##            master      #302       +/-   ##
=============================================
+ Coverage   98.855%   98.866%   +0.011%     
=============================================
  Files           25        25               
  Lines         2970      2999       +29     
=============================================
+ Hits          2936      2965       +29     
  Misses          34        34               
Impacted Files Coverage Δ
pydatastructs/graphs/__init__.py 100.000% <ø> (ø)
pydatastructs/graphs/algorithms.py 99.491% <100.000%> (+0.040%) :arrow_up:

Impacted file tree graph

czgdp1807 commented 4 years ago

We need to define, pair_wise_shortest_path(graph: Graph) and that should call, __floyd_warshall_adjacency_list. APIs for bellman_ford and dijsktra will not work because they are single source shortest path algorithms.