1

I have a list of objects say bag which has Quantity, Volume and weight. I want to split or join multiple object on the user input which will be max weight and max volume , So we want to split the list of bag further into more bag which has maximum weight and maximum volume provided by the user in best way so that no weight and volume of bag is left. What I have achieved so far is, splitting the bag according to volume or weight, So first I split according to weight and that's totally optimized but when I apply same algorithm to split volume the split is not best. Algorithm I applied:

  1. Insert all the bag in priority queue
  2. Take the first element with least weight per quantity and insert it into a bag.
  3. If the bag is full, create a new bag or else poll the next bag and insert that also.
  4. If a bag can't be inserted completely then divide the quantity and insert the quantity that can be inserted and leave the rest as it is in the priority queue.

bag.class

public class bag {
    int quantity; 
    int weightPerQty;
    int volumePerQty;
  }
Java Programmer
  • 179
  • 1
  • 12

0 Answers0