codezonediitj / pydatastructs

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

Generic implementation of optimal grouping of objects using dynamic programming #272

Open pravalikavis opened 4 years ago

pravalikavis commented 4 years ago

References to other Issues or PRs or Relevant literature

fixes #230

Brief description of what is fixed or changed

  1. Added a file which has an optimal_grouping method which groups the given objects based on the cost input function.
  2. This function uses dynamic programing which reduces the time complexity
  3. It can be used on problems like Matrix chain multiplication, optimal binary search tree and on any other problem that follows the two rules of dynamic programming along with divide and conquer.

Other comments

czgdp1807 commented 4 years ago

The algorithm will work on an array of objects if I am not wrong. So, the code should be shifted to pydatastructs/pydatastructs/linear_data_structures/algorithms.py.

pravalikavis commented 4 years ago

I have moved the file to linear_data_structures.

czgdp1807 commented 4 years ago

Hi, The code is having too many checks. Can you please simplify it? And the code should be appended to https://github.com/codezonediitj/pydatastructs/blob/master/pydatastructs/linear_data_structures/algorithms.py

pravalikavis commented 4 years ago

Hi, I moved the code to the specified file and removed some type checks.

czgdp1807 commented 4 years ago

Add some tests for your patch. See tests folder under linear_data_structures. The build is failing. Make it work.

codecov[bot] commented 4 years ago

Codecov Report

Merging #272 into master will decrease coverage by 0.180%. The diff coverage is 89.583%.

@@              Coverage Diff              @@
##            master      #272       +/-   ##
=============================================
- Coverage   98.842%   98.662%   -0.181%     
=============================================
  Files           23        23               
  Lines         2420      2467       +47     
=============================================
+ Hits          2392      2434       +42     
- Misses          28        33        +5     
Impacted Files Coverage Δ
pydatastructs/linear_data_structures/__init__.py 100.000% <ø> (ø)
pydatastructs/linear_data_structures/algorithms.py 96.815% <89.583%> (-3.185%) :arrow_down:

Impacted file tree graph

pravalikavis commented 4 years ago

Hi, I have made the changes.

Smit-create commented 3 years ago

@pravalikavis Please resolve merge conflicts.

czgdp1807 commented 3 years ago

My only concern with dynamic programming problems is that they aren't that abstract and generalized. Moreover, they are pseudo-polynomial solutions to optimisation problems (mostly discrete). So possibly, we can add a separate optimisation module and put the dynamic programming solutions there. In fact they can also contain parametrised approximation algorithm. Anyways, we should first check if there is already a python package for solving these kind of formulations.

Smit-create commented 3 years ago

Agreed on this