A web application that solves the Knapsack Problem using genetic algorithms. The project consists of a Flask backend API for computational logic and a Streamlit frontend for user interaction.
- Interactive web interface for managing items and parameters
- Genetic algorithm implementation for optimizing item selection
- Real-time visualization of results using Plotly
- RESTful API for solving knapsack problems
- Cross-Origin Resource Sharing (CORS) support
- Python 3.7+
- pip (Python package manager)
- Clone the repository:
git clone [your-repository-url]
cd knapsack-solver- Install the required dependencies:
pip install -r requirements.txtRequired packages:
- Flask
- Flask-CORS
- Streamlit
- Plotly
- Pandas
- Requests
- Start the Flask backend server:
python app.pyThe API server will run on http://127.0.0.1:5000
- In a new terminal, launch the Streamlit frontend:
streamlit run frontend.pyThe web interface will be accessible at http://localhost:8501
-
Add items using the item management interface:
- Enter item name
- Specify weight
- Set value
- Click "Add Item"
-
Configure algorithm parameters in the sidebar:
- Maximum Weight (5-100)
-
Click "Solve Knapsack Problem" to run the algorithm
-
View results:
- Selected items table
- Total value and weight visualization
- Value/weight ratio analysis
Solves the knapsack problem using genetic algorithms.
{
"max_weight": integer,
"items": [
{
"name": string,
"weight": integer,
"value": integer
}
]
}{
"selected_items": [
{
"name": string,
"weight": integer,
"value": integer
}
],
"total_value": integer,
"total_weight": integer
}- Implements genetic algorithm for knapsack problem optimization
- Uses dataclasses for structured data handling
- Includes classes for:
Item: Represents individual itemsIndividual: Represents a possible solution
- Features genetic algorithm operations:
- Selection (tournament selection)
- Crossover
- Mutation
- Elite preservation
- Built with Streamlit for interactive UI
- Features:
- Dynamic item management
- Parameter configuration
- Real-time result visualization
- Error handling and user feedback
- Uses Plotly for data visualization
- Implements session state management
- Fork the repository
- Create a feature branch (
git checkout -b feature/improvement) - Commit your changes (
git commit -am 'Add new feature') - Push to the branch (
git push origin feature/improvement) - Create a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.