Skip to content

Fractional knapsack visualizer for profit-weight, max-profit, and min-weight optimization strategies.

Notifications You must be signed in to change notification settings

j4p51f7e3/fractional-knapsack-simulator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 

Repository files navigation

Fractional Knapsack Simulator

An interactive web-based visualization tool for the Fractional Knapsack algorithm, demonstrating optimal resource allocation in computer science.

image


Key Features

  • 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.

image


Usage Instructions

1. Setup

  1. Download the repository or copy index.html
  2. Open the file in any modern browser (Chrome, Firefox, Edge)

2. Running a Simulation

  1. Add Items:

    • Enter item details (Name, Weight, Profit)
    • Click "Add Item" to populate the list
  2. Configure Parameters:

    • Set knapsack capacity (e.g., 15 kg)
    • Select a packing strategy
  3. Execute:

    • Click "Run Simulation" to view results
    • Observe the packing sequence in the 3D view

3. Interpreting Results

  • 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

image


Technical Implementation

  • 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)

Educational Applications

This tool helps demonstrate:

  1. The efficiency of greedy algorithms for fractional problems
  2. Why profit-to-weight ratio yields optimal solutions
  3. Tradeoffs between different selection strategies
  4. Practical applications in resource allocation

About

Fractional knapsack visualizer for profit-weight, max-profit, and min-weight optimization strategies.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages