An interactive web-based visualization tool for the Fractional Knapsack algorithm, demonstrating optimal resource allocation in computer science.
- Interactive Controls: Dynamically add items with custom weights and profits.
- Multiple Selection Strategies:
- Profit-to-Weight Ratio (Optimal Solution)
- Highest Profit First
- Lightest Weight First
- Visual Feedback: Real-time 3D knapsack rendering and capacity metrics.
- Comparative Analysis: Detailed results table showing fractional selections.
- Download the repository or copy
index.html
- Open the file in any modern browser (Chrome, Firefox, Edge)
-
Add Items:
- Enter item details (Name, Weight, Profit)
- Click "Add Item" to populate the list
-
Configure Parameters:
- Set knapsack capacity (e.g., 15 kg)
- Select a packing strategy
-
Execute:
- Click "Run Simulation" to view results
- Observe the packing sequence in the 3D view
- Visualization Area: Shows items packed with color-coded proportions
- Metrics Panel: Displays total profit and capacity utilization
- Results Table: Lists exact fractions and profit contributions
- Algorithm: Greedy method with O(n log n) sorting complexity
- Frontend: Vanilla JavaScript with Bootstrap 5 for responsive layout
- Visualization: CSS 3D transforms for knapsack rendering
- Compatibility: Cross-browser support (no external dependencies)
This tool helps demonstrate:
- The efficiency of greedy algorithms for fractional problems
- Why profit-to-weight ratio yields optimal solutions
- Tradeoffs between different selection strategies
- Practical applications in resource allocation