1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
olga_2 [115]
3 years ago
11

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
Computers and Technology
1 answer:
ipn [44]3 years ago
4 0

xekksksksksgBcjqixjdaj

You might be interested in
There are a few simple rules that you can follow to store and manage files and folders in your computer. What is the most import
Nitella [24]
You should avoid deleting the unknown files to store your personal files and folders because if you delete that files it may be critical position with computer.
8 0
3 years ago
Read 2 more answers
Harold wants to create a design that would depict the innocent and evil sides of human nature. Which colors can Harold use to de
belka [17]

Answer:

Usually good and evil are depicted as black and white or red and white. White being good, or pure.

Explanation:

8 0
3 years ago
Steven is in a meeting and he is sharing a graph on his monitor with fifty other people. So that the others do not need to crowd
nevsk [136]
The answer is D) Projector because with a projector, its in the name project so it can anything u put on their, and put it on a virtual screen that can be put on a wall, so everyone can see.
8 0
3 years ago
which of the following statements about servers is correct A. servers are computers on a network that share their resources with
givi [52]
A server can have many definitions, but in this particular case, the answer is A.  
7 0
3 years ago
Read 2 more answers
What are the pros and cons of using ICT​
Setler79 [48]

Answer:

Communication - Speed / time – money can be saved because it's much quicker to move information around. ...

Globalization - Video conferencing saves money on flights and accommodation. ...

Cost effectiveness - It feels free to send an email (although it isn't); it's without doubt cheaper than phone calls.

Explanation:

4 0
2 years ago
Other questions:
  • It is a good idea to use more than one typeface in a document when _____.
    8·2 answers
  • A publisher has a text-only leader board on top of a page, and a text-only small square ad slot within the content of that page.
    7·1 answer
  • How to build an arch bridge​
    5·1 answer
  • you are concerned with security at your company and want to implement a technology that requires no configuring on the users sid
    15·1 answer
  • _____________ describes the abstraction of web-based computers, resources, and services that system developers can utilize to im
    9·1 answer
  • How should you set the OHMS ADJust control on a multitester of analog VOM, for resistance measurements?
    12·1 answer
  • Alexi is writing a program which prompts users to enter their age. Which function should she use?
    6·2 answers
  • Write a program that will generate a personalized invitation within a text file for each guest in the guest list file using the
    15·1 answer
  • Every single device can be connected to every other device on network, making the network mesh. This statement is True or False?
    8·1 answer
  • True or False? The background color block should be inserted after all the images are added.
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!