Here's a draft for your README.md
file:
This repository contains the implementation of the Galactic Cargo Management System (GCMS), which efficiently manages the allocation of cargo into space cargo bins using a custom AVL Tree-based approach.
In the vast expanse of the galaxy, interstellar shipping companies face the challenge of efficiently packing cargo into space cargo bins. This system assigns unique integer IDs to bins and objects and allocates cargo based on specific color-coded rules to optimize space usage.
- Blue Cargo (Compact Fit, Least ID): Assign to the bin with the smallest remaining capacity. If multiple bins have the same remaining capacity, the one with the least ID is chosen.
- Yellow Cargo (Compact Fit, Greatest ID): Similar to Blue Cargo, but the bin with the greatest ID is chosen.
- Red Cargo (Largest Fit, Least ID): Assign to the bin with the largest remaining capacity. If multiple bins have the same remaining capacity, the one with the least ID is chosen.
- Green Cargo (Largest Fit, Greatest ID): Similar to Red Cargo, but the bin with the greatest ID is chosen.
gcms.py
: Main GCMS class to manage bins and objects.bin.py
: Implementation of the Bin class that stores bin information.object.py
: Implementation of the Object class, storing the object details including color, ID, and size.avl.py
: Custom AVL Tree implementation for efficient data handling.node.py
: AVL Tree node implementation.exceptions.py
: Custom exceptions for error handling.main.py
: Script for testing and debugging purposes.
The solution utilizes custom AVL Trees to manage the cargo and bins efficiently. Here's a detailed breakdown of the approach:
-
AVL Tree Implementation (
avl.py
): Instead of using inbuilt data structures, the AVL Tree was implemented as a map to maintain efficient data handling. Comparators were created to manage different sorting requirements, and methods such asinsert
,delete
,search
, and traversal were implemented. The tree tracks its size and root. -
Bin Management (
bin.py
): Each bin object includes attributes like capacity, bin ID, and a nested AVL Tree to store objects. Methods such asadd_object
anddelete_object
update the bin's available space accordingly. -
Object Management (
object.py
): Objects are represented by their ID, size, and color. -
Nested AVL Tree for Efficient Sorting: A nested AVL Tree was used to manage bins with the same capacity, sorting them based on their ID. This allows the system to quickly access the most suitable bin for a given object based on the cargo color rules.
-
Main System (
gcms.py
): The core system manages three AVL Trees:object_by_ID
: Tracks which bin an object is stored in.bin_by_id
: Stores bins, indexed by their IDs.bin_by_capacity
: Uses a nested AVL Tree to group bins with the same available space, ordered by their IDs.
This custom AVL-based approach ensures efficient and organized management of cargo.
Let n
be the number of objects and m
be the number of bins.
- Space Complexity: The overall space complexity is
O(n + m)
. - Time Complexity: Each operation (like insert, delete, or search) operates in
O(log n)
time, ensuring that the system remains efficient even as the number of objects and bins grows.
This structure should effectively communicate your approach and implementation details. Let me know if you'd like any adjustments!