Skip to content

Improve Knapsack 0/1 Implementation #740

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jul 7, 2024

Conversation

sozelfist
Copy link
Contributor

@sozelfist sozelfist commented Jun 9, 2024

Type of change πŸ–ŠοΈ

Refactor Knapsack 0/1 implementation

Checklist πŸš€

  • I ran bellow commands using the latest version of rust nightly.
  • I ran cargo clippy --all -- -D warnings just before my last commit and fixed any issue that was found.
  • I ran cargo fmt just before my last commit.
  • I ran cargo test just before my last commit and all tests passed.
  • I added my algorithm to the corresponding mod.rs file within its own folder, and in any parent folder(s).
  • I added my algorithm to DIRECTORY.md with the correct link.
  • I checked COUNTRIBUTING.md and my code follows its guidelines.

@sozelfist sozelfist requested review from imp2002 and vil02 as code owners June 9, 2024 12:38
@codecov-commenter
Copy link

codecov-commenter commented Jun 9, 2024

Codecov Report

All modified and coverable lines are covered by tests βœ…

Project coverage is 95.04%. Comparing base (5f0eab8) to head (f58a5ef).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #740      +/-   ##
==========================================
- Coverage   95.05%   95.04%   -0.01%     
==========================================
  Files         306      306              
  Lines       22733    22720      -13     
==========================================
- Hits        21609    21595      -14     
- Misses       1124     1125       +1     

β˜” View full report in Codecov by Sentry.
πŸ“’ Have feedback on the report? Share it here.

@sozelfist sozelfist changed the title ref: improve knapsack implementation Improve Knapsack 0/1 Implementation Jun 9, 2024
@sozelfist
Copy link
Contributor Author

sozelfist commented Jul 2, 2024

In this PR:

  • I have rewritten the implementation of the knapsack_table (renamed to generate_knapsack_matrix) using iterators and higher-order functions to make the implementation more streamlined.
  • Rename function to more descriptive names and rewrite tests using macro.
  • Organize the code in a structural form.

If you have any suggestions, feel free to do so.

@sozelfist
Copy link
Contributor Author

Can you have a look on this PR, @vil02?

@sozelfist
Copy link
Contributor Author

Can you review this PR, @vil02?

- Create `Item` struct to represent the knapsack item, which always has a weight and a value
- Create `KnapsackSolution` struct to represent the solution
- Add suggessted tests
- Update documentation
@sozelfist sozelfist requested a review from vil02 July 7, 2024 03:46
@vil02 vil02 merged commit 70b20f2 into TheAlgorithms:master Jul 7, 2024
4 checks passed
@sozelfist sozelfist deleted the ref/dp/knapsack branch July 7, 2024 23:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants