D1,L3 Bin Packing Algorithm.ppt

download D1,L3 Bin Packing Algorithm.ppt

of 14

Transcript of D1,L3 Bin Packing Algorithm.ppt

  • Decision Maths Heuristic Algorithms

  • The Bin-packing problemThe Bin-packing problem deals with packing boxes of the same width and depth but different heights into bins.

    Clearly you can see that the depth and width of the bins remains the same so we can represent the problem in 2-dimensions.

  • The Bin-packing problemIts best to look at an example to understand how the Bin-packing problem works.Here are 10 boxes, A to J with heights (in cm) as follows.

    How would you pack the boxes into bins that are 15cm high.

  • The Bin-packing problemFirst-fit algorithmC(4)A(3)B(7)D(9)E(7)F(9)G(3)I(6)H(8)J(4)Bin 1Bin 2Bin 3Bin 4Bin 5

    The idea is that you place the first box in the first available space, working from the left every time.Here box A goes in to bin 1.Now box B and C will also fit in to bin 1.Box D does not fit in bin 1 so it goes in the next space which is bin 2.Box E will not go in bin 1 or 2 so it is placed in bin 3.Similar with F, it skips over Bins 1, 2 and 3 to go in bin 4.G cannot go in bin 1 but it does slot into bin 2.H will skip 1 and 2 and fill up bin 3.I skips 1, 2 and 3 to fill up 4.J must be placed in a new bin.

    15

    BoxABCDEFGHIJHeight3749793864

  • The Bin-packing problemFirst-fit decreasing algorithm.C(4)A(3)B(7)D(9)E(7)F(9)G(3)I(6)H(8)J(4)Bin 1Bin 2Bin 3Bin 4Bin 5

    This is exactly the same method as the first-fit algorithm with one exception.The difference this time is that the boxes are placed in descending order of size before the algorithm is applied. You should use one of the sorting algorithms from last lesson to do this.Now we can apply the algorithmThis algorithm is not guaranteed to give you the best (or optimal) solution. However it is more likely to do so than just the First-fit algorithm.15

    BoxDFHBEICJAGHeight9987764433

  • The Bin-packing problemFull bin combinations.

    This is not an algorithmic process but more common sense.You literally make sure that each bin is used to its full potential. If you start by placing box D in bin 1 (No particular reason).Now box I can also go in bin 1 and it will fill all the space because 9 + 6 = 15.What other combinations will create full bins?This is actually the optimal solution for this particular problem.

    C(4)A(3)B(7)D(9)E(7)F(9)I(6)H(8)J(4)Bin 1Bin 2Bin 3Bin 4Bin 515G(3)

    BoxDFHBEICJAGHeight9987764433

  • The Ferry Loading problemThis bin-packing problem can now be applied to lots of practical real life situations.You can change what the boxes and bins represent.We are going to look at how to load vehicles on to a ferry.Here the lanes on the ferry will be the bins and the vehicles will be the boxes.

  • The Ferry Loading problemA small car-ferry has three lanes, each 20m long.The following vehicles are waiting to be loaded.Oil tanker13mVan3mTruck7mTruck6m Coach12mCar4mCar4mLorry11m

    Use the first-fit decreasing algorithm to load all these vehicles on to the trip.Can all the vehicles be taken on the trip?

  • The Ferry Loading problemFirst we need to sort the numbers.Insertion sort algorithm

  • The Ferry Loading problemSolution

    First-fit decreasing

    Full Bin combinationsC(7)A(13)B(3)D(6)E(12)F(4)G(4)H(11)Lane 1Lane 2lane 3C(7)A(13)D(6)E(12)F(4)G(4)H(11)Lane 1Lane 2lane 3B(3)

  • The Disc storage problemA software company has a new program that they want to sell on CD`s.Broken down the program looks like this.

    Each of the CD`s they will use can hold 700mb. How many CD`s will the company need if they plan on producing 50 000 copies of the program.

  • The Disc storage problemSolution

    This can be solved using full bin combinations or by the first-fit decreasing algorithm.Here the solution is done using the first fit decreasing algorithm.The program will fit exactly on to 4 CD`s.The company will need 4 x 50 000 = 200 000 CD`s.

    C(450)A(600)B(200)D(250)E(300)LGIH(200)KDisc 1Disc 2Disc 3Disc 4F(250)J

  • The Plumbing ProblemA plumber is using lengths of pipes 12 feet long and wishes to cut these lengths.

    What is the best way of achieving this so that he wastes as little pipe as possible.

  • The Plumbing ProblemFirst change the table to assign each length of pipe a name.Now you can apply the first-fit decreasing algorithm.You can now easily see the full bin combinations.A(7)H(3)J(3)I(3)E(4)D(4)G(3)C(6)F(4)B(7)K(2)L(2)A(7)H(3)J(3)I(3)E(4)D(4)G(3)C(6)Pole 1Pole 2pole 3Pole 4F(4)B(7)K(2)L(2)