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 NP-complete. 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.
a) Randomly generate at least 20 bin packing instances. Summarize the results for each algorithm. Which algorithm performs better? How often? Note: Submit a description of how the inputs were generated not the code used to produce the random inputs.
Given that,
In the bin packing problem, items of different weights must be packed into a finite number of bins each with the capacity C in a way that minimizes the number of bins used. There is no known polynomial time algorithmo to solve the optimization version of the bin packing problem.
Program:
#include<iostream>
using namespace std;
void swapping(int &a,int &b){
int t=a;
a=b;
b=t;
}
int partitioned(int arr[],int l,int h){
int p=h,i=l,j=l-1;
while(i<p){
if(arr[i]>arr[p]){
j++;
swapping(arr[i],arr[j]);
i++;
}
else{
i++;
}
}
j++;
swapping(arr[p],arr[j]);
return j;
}
void quicksort(int *a,int low,int high){
int pivot;
if(low<high){
pivot=partitioned(a,low,high);
quicksort(a,low,pivot-1);
quicksort(a,pivot+1,high);
}
}
int firstfit(int arr[] ,int size ,int capacity){
int bin[size];
for(int i=0;i<size;i++)bin[i]=capacity;
bin[0]-=arr[0];
int j=0,k;
for(int i=1;i<size;i++){
for( k=0;k<=j;k++){
if(bin[k]>=arr[i]){
bin[k]-=arr[i];
break;
}
}
if(k==j+1){
j++;
if(bin[j]>=arr[i]) bin[j]-=arr[i];
}
}
return j+1;
}
int main(){
int t,n,c;
cin>>t;
int j=1;
while(j<=t){
cin>>c>>n;
int arr[n];
for(int i=0;i<n;i++)
cin>>arr[i];
cout<<"testcase "<< j <<" : ";
cout<<"FirstFit : "<<firstfit(arr,n,c)<<"
";
quicksort(arr,0,n-1);
cout<<"FirstFitDecreasing :
"<<firstfit(arr,n,c)<<"\n";
j++;
}
return 0;
}

In the bin packing problem, items of different weights (or sizes) must be packed into a...
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 NP-complete. There is no known polynomial time algorithm to solve the optimization version of the bin packing problem. In this practice problem you will be examining three...
Give an algorithm that minimizes the maximum load of bins for
the following description:
We are given a list of n items with sizes s1, 82,. . , Sn A sequential bin packing of these at in sad ins (That is, each bin has items si, si+1,. , s, for some indices i < j.) Bins have unbounded capacities. The load of a bin is the sum of the elements in it. Give an algorithm that determines a sequential packing...
This is all I have
2. Consider the following approximation algorithm for the bin packing problem. Algorithm Last Fit(1,S) Input: Set I of items and set S of item sizes; item I; E I has size S; Output: A packing of I into unit size bins B {} for each item I; e I do { if I; fits in one of the bins of B then Put I; in the last bin where it fits else { Add a...
Consider the following four problems: Bin Packing: Given n items with positive integer sizes s1,s2,...,sn, a capacity C for bins and a positive integer k, is it possible to pack the n items using at most k bins? Partition: Given a set S of n integers, is it possible to partition S into two subsets S1 and S2 so that the sum of the integers in S1 is equal to the sum of the integers in S2? Longest Path: Given...
Recall that in the "Knapsack Problem", there are n items having respective values V1..n) and weights W1..n), all greater than 0 and one needs to maximize the total value of the subset of the items placed in the knapsack limited by a weight capacity of W In the 0-1 Knapsack Problem, each item must be either be included or excluded in its entirety, in light of the fact that this problem is to be "NP-Complete", how can one solve the...
"Greedy, but Better": Given a knapsack problem with a weight capacity C, and n items, and each item has a weight W[1:n] and monetary value P[1:n]. You have to determine which items to take so that the total weight is C, and the total value (profit) is maximized. In this case we are considering an integer problem, so you can either take an item, or not take an item, you cannot take it fractionally. If you recall, the greedy algorithm...
5) (10 pts) Greedy Algorithms The 0-1 Knapsack problem is as follows: you are given a list of items, each item has an integer weight and integer value. The goal of the problem is to choose a subset of the items which have a sum of weights less than or equal to a given W with a maximal sum of values. For example, if we had the following five items (each in the form (weight, value)): 11(6, 13), 2(4, 10),...
3. [10 marks] Suppose we would like to buy n items from SuperCheapStore (SCS); all items are currently priced at 1 CAD. Unfortunately there is no delivery and we have to deliver them home. The bad news are: we can fit only 1 item in our truck: it takes one day to drive home and back. There is even worse news -SCS charges us for the storage of undelivered items and the charge for storage of te i growth exponentially...
You are consulting for a trucking company that does a large amount of business shipping packages between New York and Boston. The volume is high enough that they have to send a number of trucks each day between the two locations. Trucks have a fixed limit w on the maximum amount of weight they are allowed to carry. Boxes arrive at the New York station one by one, and each package i has a weight wi. The trucking station is...
Please help me with this answer. Performance Comparison for Dijkstra Algorithm and Bellman-Ford Algorithm Problem Description The shortest path problem is one of most important problems in graph theory and computer science in general. Shortest path problem is one of typical optimization problems. Given a graph G = (V,E), the goal is to nd a minimum cost path from s → t, s,t ∈ V . This variant is called one-to-one shortest path problem. Other variants are one-to-all (compute shortest...