Skip to content

Solving knapsack problem where data is read from a file. This solution can be further extended to implement other approaches to solve knapsack problem

Notifications You must be signed in to change notification settings

madeehagh/knapsack-problem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Constraints

Exposing static method

public static String pack(String filePath) throws APIException

Plugins and Technologies Used

  • Java 18
  • Maven
  • TDD
  • Integration Testing
  • JUnit5, Mockito
  • Lombok
  • Jacoco
  • log4J

Assumption

This project could be used as external library or mvn plugin. The API only process List of items in the given format in src/main/test/resources/example_input

Expected Input/Output

Input: Absolute File Path Name, UTF-8 format Output: String as mentioned in path src/main/test/resources

file data is empty or invalid, the API call throws FileNotFound Exception If anything else goes wrong, the API call throws APIException

Data Structure & Implementation Details

There can be many ways to solve this problem like using dynamic programming and priority queue. I chose to solve this problem by priority queue keeping in mind of lightweight solution. I am using the mix of Heap (PriorityQueue) of java and Map I created in this customized data structures into a class name KnapSackQueue, which is a class that collects and sort products keeping in mind of knapsack algorithm. Since this problem can be solved in multiple ways, I created an interface KnapSack which can have multiple implementations.

Entry point

call static method pack(fileName) with reference to Packer class Packer.pack("some_file_name")

Build And Test

  • mvn clean install
  • mvn clean test The detailed test coverage can be seen in target->jacoco->site->index.html

NFR

Added CodeQL workflow to scan code for security vulnerabilities

About

Solving knapsack problem where data is read from a file. This solution can be further extended to implement other approaches to solve knapsack problem

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published