#include #include #include "Heuristics.h" #include "PriorityQueue.h" #include "FastPQ.h" #include "SlowPQ.h" using namespace std; /****************************************************************** * This routine is a utility to allocate a new priority queue object * based upon the chosen lowe level implementation, as directed by the * parameter. ******************************************************************/ template PriorityQueue* allocatePQ(bool useFast) { PriorityQueue *newqueue; if (useFast) newqueue = new FastPQ; else newqueue = new SlowPQ; return newqueue; } /****************************************************************** * This routine computes a bin-packing of the given set of weights. * The return value is the overall number of bins which were used. * * Params: * w -- an array of the original weights * * N -- the number of such weights * * decreasing -- If true, procedure will do worst-fit decreasing heuristic * If false, worst-fit heuristic (with original order) * * useFastPQ -- If true, will use a FastPQ as the underlying data structure * If false, will use a SlowPQ as the underlying data structure * * verbose -- If true, will generate output to cout listing the * contents and total weight of each bin. If false, does * not generate any output to cout (though still returns * the overall number of bins to the caller) * ******************************************************************/ int worstFit(double* w, int N, bool decreasing, bool useFastPQ, bool verbose) { /********************************************************************** * You will need a priority queue of grocery items yet to be * processed. You must decide on the Element type for the queue as * well as how to set a key appropriately. Our suggestion for the * declaration of this queue is as follows: * * Element type: double (the weight of the grocery item) * * Uncomment next two line to accept this declaration. **********************************************************************/ /* PriorityQueue *groceryQueue; groceryQueue = allocatePQ(useFastPQ); */ /********************************************************************** * You will also need a priority queue to keep track of all of the * (partially) packed bins. Again, you must decide on the Element * type. We suggest the use of std::vector to represent each * bin. However, in declaring the priority queue, there are two * reasonable choices for the precise type. * * A) The element inserted into priority queue is a POINTER to a vector * * B) The element inserted into priority queue is an actual vector, * in which case copies may be made when passing parameters and * return values. * * The above choice will effect the remaining syntax of your * program. Please accept one of the two by uncommenting one of the * following respective declarations. **********************************************************************/ /* Declaration for (A) as described above PriorityQueue*> *binQueue; binQueue = allocatePQ*>(useFastPQ); */ /* Declaration for (B) as described above PriorityQueue > *binQueue; binQueue = allocatePQ >(useFastPQ); */ /* Step 1: insert all groceries into the groceryQueue with appopriate keys */ /* Step 2: One-by-one, remove a grocery item from that queue, and then either insert it in an existing bin, if one suffices; otherwise create a new bin for this item. */ /* Step 3: If verbose was specified, output contents of resulting bins */ /* Step 4: Deallocate the queues. */ /* Step 5: return a count of the resulting number of bins */ return 0; // stub. you should return the true answer }