SlideShare a Scribd company logo
1 of 24
Download to read offline
Bin Packing
Some slides adapted from slides from
• Professor C. L. Liu, Tsing Hua University
• Professor Teofilo F. Gonzalez, UCSB
Michael T. Goodrich
Bin Packing Example
.5 .7 .5 .2 .4 .2 .5 .1 .6
……
1
.1
.5
.4
.6
.2
.7
.2
.5 .5
Items to be packed
The bins;
(capacity 1)
Bin Packing Problem Definition
• Given n items with sizes s1, s2, ..., sn such that
0 ≤ si ≤ 1 for 1 ≤ i ≤ n, pack them into the
fewest number of unit capacity bins.
• Problem is NP-hard (NP-Complete for the
decision version).
• There is no known polynomial time algorithm
for its solution, and it is conjectured that none
exists.
Example Applications
Filling recycle bins
Loading trucks
Historical Application
• Mix tapes
Bin Packing Optimal Solution
Bin Packing Problem
.5 .7 .5 .2 .4 .2 .5 .1 .6
……
1
.1
.5
.4
.6
.2
.7
.2
.5
.5
MOpt = 4
Optimal Packing
Next-Fit (NF) Algorithm
• Check to see if the current item fits in the
current bin. If so, then place it there, otherwise
start a new bin.
Bin Packing Problem
Next Fit Packing Algorithm
.5
.7
.5
.2
.4
.2 .1
.5
M = 6
.5 .7 .5 .2 .4 .2 .5 .1 .6
.1
.5
.4
.2
.7
.2
.5
.5
MOpt = 4
.6
.6
Next Fit (NF) Packing
Algorithm Example
Approximation Ratios
• Approximation Algorithm:
– Not an optimal solution, but with some
performance ratio guarantee for a given problem
instance, I
(e.g., no worst than twice the optimal)
• Approx. Ratio = Alg(I)/Opt(I)
Next Fit (NF) Approximation Ratio
• Theorem: Let M be the number of bins
required to pack a list I of items optimally.
Next Fit will use at most 2M bins.
• Proof:
• Let s(Bi) be the sum of sizes of the items
assigned to bin Bi in the Next Fit solution.
• For any two adjacent bins (Bj and Bj+1), we
know that s(Bj) + s(Bj+1) > 1.
Next Fit (NF) Approximation Ratio
• Let k be the number of bins used by Next Fit
for list I. We prove the case when k is even
(odd case is similar).
Next Fit (NF) Lower Bound
• There exist sequences such that Next Fit uses
2M −2 bins, where M is the number of bins in
an optimal solution.
• Proof:
First Fit (FF) Algorithm
• Scan the bins in order and place the new item
in the first bin that is large enough to hold it. A
new bin is created only when an item does not
fit in the previous bins.
First Fit (FF) Packing
Algorithm Example
First Fit Packing Algorithm
.5
.7
.5 .2
.4
.2
.1
.5
M = 5
.5 .7 .5 .2 .4 .2 .5 .1 .6
Next Fit Packing Algorithm
.5
.7
.5
.2
.4
.2 .1
.5 .6
.6
Running Time for First Fit
• Easily implemented in O(n2) time
• Can be implemented in O(n log n) time:
– Idea: Use a balanced search tree with height
O(log n).
– Each node has three values: index of bin,
remaining capacity of bin, and best (largest) in
all the bins represented by the subtree rooted at
the node.
– The ordering of the tree is by bin index.
Faster First-Fit (FF) Algorithm
• 8 bins:
First-Fit (FF) Approx. Ratio
• Let M be the optimal number of bins required
to pack a list I of items. Then First Fit never
uses more than ⌈1.7M⌉.
• Proof:
– [omitted]
First-Fit (FF) Approx. Ratio
• There exist sequences such that First Fit uses
1.6666…(M) bins.
• Proof:
First-Fit (FF) Lower Bound
• First Fit uses 10M bins, but optimal uses 6M
Best Fit Algorithm (BF)
• New item is placed in a bin where it fits the
tightest. If it does not fit in any bin, then start a
new bin.
• Can be implemented in O(n log n) time, by
using a balanced binary tree storing bins
ordered by remaining capacity.
Example for Best Fit (BF)
• I = (0.2, 0.5, 0.4, 0.7, 0.1, 0.3, 0.8)
Other Heuristics
• First Fit Decreasing (FFD): First order the
items by size, from largest to smallest, then run
the First Fit Algorithm.
• Best Fit Decreasing (BFD): First order the
items by size, from largest to smallest, then run
the Best Fit Algorithm.
Experiments
• It is difficult to experimentally compute
approximation ratios.
– It requires that we know the optimal solution to an
NP-hard problem!
• But we can do experiments for a related
parameter:
• Define the waste, W(A), for a bin-packing
algorithm A to be the number of bins that it
uses minus the total size of all n items.
Experiments
• We are interested in experiments for
estimating the waste, W(A), as a function of n
and as n grows towards infinity, for random
items uniformly distributed in the interval
(0,1), for the following algorithms:
– A = Next Fit (NF)
– A = First Fit (FF)
– A = Best Fit (BF)
– A = First Fit Decreasing (FFD)
– A = Best Fit Decreasing (BFD)

More Related Content

Recently uploaded

Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfragupathi90
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptamrabdallah9
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxMustafa Ahmed
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological universityMohd Saifudeen
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxMustafa Ahmed
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfJNTUA
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxKarpagam Institute of Teechnology
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.benjamincojr
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxkalpana413121
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...Amil baba
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationEmaan Sharma
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...archanaece3
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfKira Dess
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docxrahulmanepalli02
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfJNTUA
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsVIEW
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalSwarnaSLcse
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdfKamal Acharya
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxMustafa Ahmed
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailingAshishSingh1301
 

Recently uploaded (20)

Interfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdfInterfacing Analog to Digital Data Converters ee3404.pdf
Interfacing Analog to Digital Data Converters ee3404.pdf
 
Passive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.pptPassive Air Cooling System and Solar Water Heater.ppt
Passive Air Cooling System and Solar Water Heater.ppt
 
Augmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptxAugmented Reality (AR) with Augin Software.pptx
Augmented Reality (AR) with Augin Software.pptx
 
21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university21scheme vtu syllabus of visveraya technological university
21scheme vtu syllabus of visveraya technological university
 
Worksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptxWorksharing and 3D Modeling with Revit.pptx
Worksharing and 3D Modeling with Revit.pptx
 
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdfInvolute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
Involute of a circle,Square, pentagon,HexagonInvolute_Engineering Drawing.pdf
 
analog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptxanalog-vs-digital-communication (concept of analog and digital).pptx
analog-vs-digital-communication (concept of analog and digital).pptx
 
electrical installation and maintenance.
electrical installation and maintenance.electrical installation and maintenance.
electrical installation and maintenance.
 
UNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptxUNIT 4 PTRP final Convergence in probability.pptx
UNIT 4 PTRP final Convergence in probability.pptx
 
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
NO1 Best Powerful Vashikaran Specialist Baba Vashikaran Specialist For Love V...
 
History of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & ModernizationHistory of Indian Railways - the story of Growth & Modernization
History of Indian Railways - the story of Growth & Modernization
 
5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...5G and 6G refer to generations of mobile network technology, each representin...
5G and 6G refer to generations of mobile network technology, each representin...
 
Artificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdfArtificial intelligence presentation2-171219131633.pdf
Artificial intelligence presentation2-171219131633.pdf
 
21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx21P35A0312 Internship eccccccReport.docx
21P35A0312 Internship eccccccReport.docx
 
Diploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdfDiploma Engineering Drawing Qp-2024 Ece .pdf
Diploma Engineering Drawing Qp-2024 Ece .pdf
 
What is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, FunctionsWhat is Coordinate Measuring Machine? CMM Types, Features, Functions
What is Coordinate Measuring Machine? CMM Types, Features, Functions
 
CLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference ModalCLOUD COMPUTING SERVICES - Cloud Reference Modal
CLOUD COMPUTING SERVICES - Cloud Reference Modal
 
Insurance management system project report.pdf
Insurance management system project report.pdfInsurance management system project report.pdf
Insurance management system project report.pdf
 
Dynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptxDynamo Scripts for Task IDs and Space Naming.pptx
Dynamo Scripts for Task IDs and Space Naming.pptx
 
handbook on reinforce concrete and detailing
handbook on reinforce concrete and detailinghandbook on reinforce concrete and detailing
handbook on reinforce concrete and detailing
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

BinPacking.pdf Dfghhjkkjjjjmkkkjnjjjjmmmk

  • 1. Bin Packing Some slides adapted from slides from • Professor C. L. Liu, Tsing Hua University • Professor Teofilo F. Gonzalez, UCSB Michael T. Goodrich
  • 2. Bin Packing Example .5 .7 .5 .2 .4 .2 .5 .1 .6 …… 1 .1 .5 .4 .6 .2 .7 .2 .5 .5 Items to be packed The bins; (capacity 1)
  • 3. Bin Packing Problem Definition • Given n items with sizes s1, s2, ..., sn such that 0 ≤ si ≤ 1 for 1 ≤ i ≤ n, pack them into the fewest number of unit capacity bins. • Problem is NP-hard (NP-Complete for the decision version). • There is no known polynomial time algorithm for its solution, and it is conjectured that none exists.
  • 6. Bin Packing Optimal Solution Bin Packing Problem .5 .7 .5 .2 .4 .2 .5 .1 .6 …… 1 .1 .5 .4 .6 .2 .7 .2 .5 .5 MOpt = 4 Optimal Packing
  • 7. Next-Fit (NF) Algorithm • Check to see if the current item fits in the current bin. If so, then place it there, otherwise start a new bin.
  • 8. Bin Packing Problem Next Fit Packing Algorithm .5 .7 .5 .2 .4 .2 .1 .5 M = 6 .5 .7 .5 .2 .4 .2 .5 .1 .6 .1 .5 .4 .2 .7 .2 .5 .5 MOpt = 4 .6 .6 Next Fit (NF) Packing Algorithm Example
  • 9. Approximation Ratios • Approximation Algorithm: – Not an optimal solution, but with some performance ratio guarantee for a given problem instance, I (e.g., no worst than twice the optimal) • Approx. Ratio = Alg(I)/Opt(I)
  • 10. Next Fit (NF) Approximation Ratio • Theorem: Let M be the number of bins required to pack a list I of items optimally. Next Fit will use at most 2M bins. • Proof: • Let s(Bi) be the sum of sizes of the items assigned to bin Bi in the Next Fit solution. • For any two adjacent bins (Bj and Bj+1), we know that s(Bj) + s(Bj+1) > 1.
  • 11. Next Fit (NF) Approximation Ratio • Let k be the number of bins used by Next Fit for list I. We prove the case when k is even (odd case is similar).
  • 12. Next Fit (NF) Lower Bound • There exist sequences such that Next Fit uses 2M −2 bins, where M is the number of bins in an optimal solution. • Proof:
  • 13. First Fit (FF) Algorithm • Scan the bins in order and place the new item in the first bin that is large enough to hold it. A new bin is created only when an item does not fit in the previous bins.
  • 14. First Fit (FF) Packing Algorithm Example First Fit Packing Algorithm .5 .7 .5 .2 .4 .2 .1 .5 M = 5 .5 .7 .5 .2 .4 .2 .5 .1 .6 Next Fit Packing Algorithm .5 .7 .5 .2 .4 .2 .1 .5 .6 .6
  • 15. Running Time for First Fit • Easily implemented in O(n2) time • Can be implemented in O(n log n) time: – Idea: Use a balanced search tree with height O(log n). – Each node has three values: index of bin, remaining capacity of bin, and best (largest) in all the bins represented by the subtree rooted at the node. – The ordering of the tree is by bin index.
  • 16. Faster First-Fit (FF) Algorithm • 8 bins:
  • 17. First-Fit (FF) Approx. Ratio • Let M be the optimal number of bins required to pack a list I of items. Then First Fit never uses more than ⌈1.7M⌉. • Proof: – [omitted]
  • 18. First-Fit (FF) Approx. Ratio • There exist sequences such that First Fit uses 1.6666…(M) bins. • Proof:
  • 19. First-Fit (FF) Lower Bound • First Fit uses 10M bins, but optimal uses 6M
  • 20. Best Fit Algorithm (BF) • New item is placed in a bin where it fits the tightest. If it does not fit in any bin, then start a new bin. • Can be implemented in O(n log n) time, by using a balanced binary tree storing bins ordered by remaining capacity.
  • 21. Example for Best Fit (BF) • I = (0.2, 0.5, 0.4, 0.7, 0.1, 0.3, 0.8)
  • 22. Other Heuristics • First Fit Decreasing (FFD): First order the items by size, from largest to smallest, then run the First Fit Algorithm. • Best Fit Decreasing (BFD): First order the items by size, from largest to smallest, then run the Best Fit Algorithm.
  • 23. Experiments • It is difficult to experimentally compute approximation ratios. – It requires that we know the optimal solution to an NP-hard problem! • But we can do experiments for a related parameter: • Define the waste, W(A), for a bin-packing algorithm A to be the number of bins that it uses minus the total size of all n items.
  • 24. Experiments • We are interested in experiments for estimating the waste, W(A), as a function of n and as n grows towards infinity, for random items uniformly distributed in the interval (0,1), for the following algorithms: – A = Next Fit (NF) – A = First Fit (FF) – A = Best Fit (BF) – A = First Fit Decreasing (FFD) – A = Best Fit Decreasing (BFD)