This project provides a solution for the 0/1 Knapsack problem using dynamic programming, implemented in PHP with the Laravel framework and styled with Tailwind CSS.
- Introduction
- Features
- Installation
- Usage
- Project Structure
- Dynamic Programming Explanation
- References
The 0/1 Knapsack problem is a classic optimization problem where the objective is to maximize the total value of items that can be carried in a knapsack of fixed capacity. This project demonstrates how to solve this problem using dynamic programming.
- Solve the 0/1 Knapsack problem using dynamic programming.
- Display the maximum value that can be achieved with the given capacity.
- Show the dynamic programming table used to solve the problem.
- User-friendly interface with Tailwind CSS for styling.
Follow these steps to set up the project locally.
- PHP >= 7.3
- Composer
- sqlite or any other supported database
-
Clone the repository:
git clone https://github.com/numbhill/knapsack-project.git cd knapsack-project
-
Install dependencies:
composer install
-
Set up the environment:
Copy the
.env.example
file to.env
and update the database configuration:cp .env.example .env
Update the
.env
file with your database details:DB_CONNECTION=sqlite
-
Generate the application key:
php artisan key:generate
-
Run the migrations:
php artisan migrate
-
Seed the database (optional):
php artisan db:seed --class=ItemSeeder
-
Serve the application:
php artisan serve
-
Access the application:
Open your web browser and go to
http://localhost:8000/knapsack
.
- Go to
http://localhost:8000/knapsack
. - Enter the capacity of the knapsack.
- Click the "Solve" button to get the maximum value.
- To view the dynamic programming table, use the appropriate form and submit.
knapsack-project/
├── app/
│ ├── Http/
│ │ └── Controllers/
│ │ └── KnapsackController.php
│ ├── Models/
│ │ └── Item.php
├── resources/
│ ├── views/
│ │ └── knapsack/
│ │ ├── index.blade.php
│ │ └── result.blade.php
│ │ └── welcome.blade.php
├── routes/
│ └── web.php
├── database/
│ ├── migrations/
│ │ └── xxxx_xx_xx_create_items_table.php
│ └── seeders/
│ └── ItemSeeder.php
└── .env.example