1.41k likes | 1.9k Views
Bin packing First-fit algorithm. Bin packing First-fit algorithm. A B C D E F. Each block will be fitted into the first bin that has room for it. 6. 5. 4. 3. 3. 3. 2. 2. 1. Bin packing First-fit algorithm. 4.
E N D
Bin packing First-fit algorithm A B C D E F Each block will be fitted into the first bin that has room for it. 6 5 4 3 3 3 2 2 1
Bin packing First-fit algorithm 4 A B C D E F The first block fits into the first bin. 6 5 3 3 3 2 2 1
Bin packing First-fit algorithm 1 4 A B C D E F The second block fits into the first bin. 6 5 3 3 3 2 2
Bin packing First-fit algorithm 2 1 4 2 A B C D E F The third block will not fit in the first bin But there is room in the second bin. 6 5 3 3 3 2
Bin packing First-fit algorithm 5 5 1 5 4 2 A B C D E F The third bin is the first one the 5 will fit into. 6 3 3 3 2
Bin packingFirst-fit algorithm 3 1 3 5 4 2 A B C D E F The second bin has room for the 3. 6 3 3 2
Bin packingFirst-fit algorithm 2 2 2 1 3 5 4 2 2 A B C D E F The fourth bin is the first one with room for the 2. 6 3 3
Bin packingFirst-fit algorithm 3 3 3 3 5 3 1 4 2 2 A B C D E F The 3 also fits into the fourth bin. 6 3
Bin packingFirst-fit algorithm 6 6 6 6 6 1 3 5 3 4 2 2 A B C D E F 3 No room until the fifth bin for the 6.
Bin packingFirst-fit algorithm 3 3 3 3 3 6 1 3 5 3 4 3 2 2 A B C D E F The 3 has to start a new bin Total usage is 6 bins.
Bin Packing Examples of first-fit algorithm
Example 1Pack the following items into bins of size 20:11, 7, 3, 4, 3, 5, 1, 8, 9How many bins are required?
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 Bins 11 9 8 7 5 4 3 3 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 11 Bins 9 8 7 5 4 3 3 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 7 11 Bins 9 8 5 4 3 3 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 3 7 11 Bins 9 8 5 4 3 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 7 11 3 Bins 9 8 5 4 3 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 7 11 4 3 Bins 9 8 5 3 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 7 3 11 4 3 Bins 9 8 5 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 5 7 3 11 4 3 Bins 9 8 1
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 1 5 7 3 11 4 3 Bins 9 8
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 8 1 5 7 3 11 4 3 Bins 9
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 1 5 7 3 11 4 8 3 Bins 9
11, 7, 3, 4, 3, 5, 1, 8, 9 Bin size 20 1 5 9 7 3 11 4 8 3 Bins We need 3 bins.
Example 2Pack the following items into bins of size 20:5, 8, 12, 4, 11, 17, 7, 9, 7How many bins are required?
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 Bins 17 12 11 9 8 7 7 5 4
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 5 Bins 17 12 11 9 8 7 7 4
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 8 5 Bins 17 12 11 9 7 7 4
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 12 8 5 Bins 17 11 9 7 7 4
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 8 12 5 Bins 17 11 9 7 7 4
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 4 8 12 5 Bins 17 11 9 7 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 11 4 8 12 5 Bins 17 9 7 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 4 8 12 11 5 Bins 17 9 7 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 17 4 8 12 11 5 Bins 9 7 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 17 4 8 12 11 5 Bins 9 7 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 7 17 4 8 12 11 5 Bins 9 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 9 7 17 4 8 12 11 5 Bins 7
5, 8, 12, 4, 11, 17, 7, 9, 7Bin size 20 9 7 17 4 8 12 11 7 5 Bins We need 5 bins.
Example 3A wholesale greengrocer is packing the following items into crates that will carry 24 kg: How many crates will the greengrocer need?