![bezar77](/avatars/34856.jpg)
bezar77
08.06.2020 •
Computers and Technology
C++ Problem: In the bin packing problem, items of different weights (or sizes) must be packed into a finite number of bins each with the capacity C in a way that minimizes the number of bins used. The decision version of the bin packing problem (deciding if objects will fit into <= k bins) is NPcomplete. There is no known polynomial time algorithm to solve the optimization version of the bin packing problem. In this homework you will be examining three greedy approximation algorithms to solve the bin packing problem.
- First-Fit: Put each item as you come to it into the first (earliest opened) bin into which it fits. If there is no available bin then open a new bin.
- First-Fit-Decreasing: First sort the items in decreasing order by size, then use First-Fit on the resulting list.
- Best Fit: Place the items in the order in which they arrive. Place the next item into the bin which will leave the least room left over after the item is placed in the bin. If it does not fit in any bin, start a new bin.
Implement the algorithms in C++. Your program named bins.cpp should read in a text file named bin.txt with multiple test cases as explained below and output to the terminal the number of bins each algorithm calculated for each test case. Example bin.txt: The first line is the number of test cases, followed by the capacity of bins for that test case, the number of items and then the weight of each item. You can assume that the weight of an item does not exceed the capacity of a bin for that problem.
3
10
6
5 10 2 5 4 4
10
20
4 4 4 4 4 4 4 4 4 4 6 6 6 6 6 6 6 6 6 6
10
4
3 8 2 7
Sample output: Test Case 1 First Fit: 4, First Fit Decreasing: 3, Best Fit: 4
Test Case 2 First Fit: 15, First Fit Decreasing: 10, Best Fit: 15
Test Case 3 First Fit: 3, First Fit Decreasing: 2, Best Fit: 2
Solved
Show answers
More tips
- H Health and Medicine How to Treat Whooping Cough in Children?...
- L Leisure and Entertainment Unlocking the Secrets of Fast and Effective Tectonic Learning...
- A Animals and plants Уход за джунгариками: полезные советы и рекомендации...
- S Style and Beauty How to knit a hooded cowl?...
- S Style and Beauty How to Break in New Shoes: 7 Simple Methods...
- D Dating, Love, Relationships 10 Useful Tips on How to Survive a Breakup?...
- A Art and Culture How to Learn Screaming: Step-by-Step Guide for Beginners...
- A Art and Culture Attention, the Final Episode of Margo is Almost Here!...
- H Health and Medicine Novomin: What is it and how to use it?...
- L Leisure and Entertainment How to Land on the Moon: Your Comprehensive Guide...
Answers on questions: Computers and Technology
- B Business To bypass regulations imposed by the Sherman Antitrust Act and engage in monopolistic behavior, businesses would participate in which of the following activities? mergers perfect...
- C Chemistry What is the best description of the Big Bang Theory? a massive explosion that created everything in the universe two planets collided, creating the Sun and other planets a rapid...
- M Mathematics Please help meee! If the points (-9, ) and (-8, -9) fall on a line with a slope of -5. What is the value of f?...
- M Mathematics Simplify the complex fraction ((3x-7)/x^2)/(x^2/2)+(2/x) i really need steps on how to do this properly cause i really can t figure it out...
- M Mathematics According to the graph, what is the value of the constant in the equation below? ...
Ответ: