Question: i want the whole solution in c++ Assignment Purpose and Overview The purpose of this assignment is to implement a container packing algorithm. In this




i want the whole solution in c++
Assignment Purpose and Overview The purpose of this assignment is to implement a container packing algorithm. In this simplified version of container packing, we will consider a two-dimensional (2D) version of the packing problem, where given a set of boxes (i.e., rectangles) and a container (i.e., bounding box), we want to find one placement configuration that places all boxes within the container without overlap. To facilitate our description, consider the following four boxes (illustrated with their respective width and length sizes (WxL), and a container of size 44 : The algorithm should deliver one or more solutions (i.e., placement configurations) to solve the problem appropriately. For example, The following placement configurations are some of the valid solutions to the problem. In this assignment, the Container will be represented by a two-dimensional character array. For example, the figure below shows the first solution and how this should be represented in the container. For the purposes of this assignment, a text file will be provided as input to allow your program to load box(es) and container configurations. Overall, in this assignment, you are asked to: - Evaluate different data structures for storing box configurations and implement the most efficient one. - Develop a program for storing and manipulating container and box configurations and solutions (placement configurations). - Design and develop algorithms that solve the placement configuration using backtracking, using simple and complex configurations. - Design and implement appropriate data structures for supporting the algorithm's backtracking operation. - Develop a program that orchestrates all the above to solve the container packing problem. Your program must also investigate if there are inconsistencies in the input file and if indeed there is at least one valid placement configuration. Assignment Requirements and Constraints The assignment starts by defining the Box and Packer Problem data structures to load box configurations and assign a size to the container. To this end, you will need to define the following: - Box data structure: to store the width, length and name of the box - PackerProblem data structure to store the width and length of the container, the number of boxes and all box configurations, and to print all box configurations. To initialize the PackerProblem data structure you will use the following function, which will read a text file (named filename) and use dynamic memory allocation to create an instance of the PackerProblem data structure as described above: PackerProblem* loadPackerProblem(string filename) The structure of the input text file is described below, and an example is presented on the right: - the first line includes two numbers, which indicate the size of the container (e.g., 4 4) - the second number indicates the number of boxes (e.g., 4) - the remaining lines represent the box configurations, which are triplets composed of two numbers and one character (e.g., 23 A), which represent the width, height, and name of the box respectively. In the example, you can observe that 4 box configurations have been provided. When the file has been read properly (see section Error Control), you should then print using the console the container configuration and boxes, as illustrated below (following the above example). Container Configuration (4 4 ) 4 Boxes to be placed A (23) AAA AAA B (22) BB BB C (22) CC CC D (2x1) D D A number of input files are provided in Appendix 1 for you to test your implementation. The program should initialize a PackerSolver data structure with the loaded configuration (i.e., PackerProblem) and call the solveProblem method in order to proceed to find a valid placement for all boxes, if it exists. The algorithm must employ a backtracking approach according to the following high-level concept: - Start placing boxes in the configuration in a manner of your choice (e.g., sequentially, randomly). - As soon as you reach a state where you cannot place any of the remaining boxes, the algorithm should backtrack to a previous state and try a different placement route. See below an example of backtracking to better understand the assignment concept. Available boxes and container Sequential Placement will place Box A, then Box B, Box C and D and will not have place for E. Depending on your backtracking strategy, one can select to make the last step before the dead-end (i.e., placing Box D) invalid and proceed with a different configuration. This of course leads us to a new dead-end, which means we need to back-track again to the previous valid configuration and back-track even more. In the presented example, we will need to go back to where we placed the first box (i.e., Box A) and proceed with a different Box (i.e., Box C). The resulting valid configuration should be exported to the user in a format similar to the printing of the initial empty container. Below we see an example of a valid configuration and the required console printing. +-w+ACBDOBEEE++ If your algorithm cannot find a solution, then the program should print that there is no solution. It is compulsory that you implement a stack data structure to enable the backtracking functionality. The stack data structure must be designed and implemented using dynamic memory allocation and generic programming techniques and should implement the following functions: - isEmpty: checks if the stack is empty - push: inserts an element to the top of the stack - pop: removes an element from the top of the stack, if it exists, without returning it - topa returns the element located on the top of the stack, if it exists Error control In your assignment, you will also need to implement appropriate controls to ensure that the input is correct, and the problem presented is valid. In particular, you will need to check for the following: - The structure of the file is correct. For example, the first two number should correspond to valid width and length of the container. If you identify that there are letters (e.g. ' a ') or inconsistent numbers (e.g., 0 or -1), you should stop processing and report an error. - The number of box configurations should be equal to the number of the boxes read in the file. For example, if you read from the file that there are 5 box configurations then you should report an error and stop processing when there are less. - If there is no solution to the problem, you should report an error that there is no solution. Time Performance You will need to time your solver algorithm (not the loading of the file) using the high_resolution_clock library taught during the labs. The total time required for the solution to be printed should be printed at after the discovered solution. IMPORTANT: The program must satisfy all the requirements and constraints described in this section. However, the requirements may not be sufficiently defined. During the specifications, you will need to record your assumptions and how these have influenced your models
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
