A Flask-based web application that solves the 0/1 Knapsack Problem for optimal resource allocation in a company using Dynamic Programming.
- Input project details manually or via CSV file upload
- Dynamic Programming solution for the 0/1 Knapsack Problem
- Visual representation of results using matplotlib
- Modern, responsive UI with Bootstrap
- Real-time calculation and visualization
- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate- Install dependencies:
pip install -r requirements.txt- Run the application:
python app.py- Open your browser and navigate to
http://localhost:5000
When uploading a CSV file, ensure it has the following columns:
cost: The cost of each projectreturn: The expected return (profit) of each project
Example CSV:
cost,return
1000,500
2000,800
3000,1200- The Dynamic Programming solution for the 0/1 Knapsack Problem has a time complexity of O(nW), where:
- n is the number of projects
- W is the budget (knapsack capacity)
- The space complexity is also O(nW) for storing the DP table
- Main DP table: O(nW)
- Additional space for selected items: O(n)
- Total space complexity: O(nW)
- The solution is optimal for the 0/1 Knapsack Problem
- For very large datasets (n > 1000 or W > 1000000), consider using approximation algorithms
- The visualization component adds O(n) time complexity for plotting
.
├── app.py # Main Flask application
├── requirements.txt # Python dependencies
├── templates/ # HTML templates
│ └── index.html # Main page template
├── static/ # Static files (CSS, JS)
└── uploads/ # Temporary storage for uploaded files
Feel free to submit issues and enhancement requests!