Professional Documents
Culture Documents
Assignment 1
Assignment 1
Assignment 1
Optimization Problems
Optimization problems are very common in engineering and scientic applications; the idea is to use as little as possible of some sort of input quantity in order to generate a required amount of output quantity. For example, the University seeks to build as few lecture theatres as possible, consistent with the requirement that the required volume of classes can be scheduled; and a rental car company seeks to own as few cars as possible, consistent with the need to full all their bookings. Consider a fabrication plant that manufactures components from coils of stainless steel. Each coil is placed on a cutting machine and then unrolled as required so that at components can be created; coils are 3.5 meters wide and 24 meters long. Each component to be cut is described by a bounding rectangle given as an (x, y ) tuple, with both dimensions expressed in meters. For example, the following lines describe four such components, the rst of which is 4.0 2.5 meters. You may assume that the longer dimension will always be given rst. 4.0 10.0 8.0 3.5 2.5 1.0 3.0 3.0
Figure 1 shows one way the rst three of those components might be laid out on a single coil of steel. The fourth component cannot be cut from this rst sheet if this arrangement is used. With this allocation of three components to the coil, there are 2.0 meters at the end that are unused, and so the end wastage on this coil is 2.0 3.5 = 7.0 m2 . There is also internal wastage caused by the fact that the full width of the sheet is not being used; the internal wastage for this sheet is calculated as (22.0 3.5) (4.0 2.5) (10.0 1.0) (8.0 3.0) = 33.0 m2 . The total wastage is the sum of the internal and end wastage values for all coils that have been completed as part of a fabrication run, plus the internal wastage (but not the end wastage) of the last coil. Total wastage measures the area of the coils consumed that was discarded during the fabrication run.
internal wastage
3.5 3.0 2.5
end wastage
1.0
0.0
4.0
14.0
22.0
24.0
Figure 1: Possible layout of three components on one coil. Stage 1 ------component component component component
1, 2, 3, 4,
on on on on
1 1 1 2
Note the use of %4.1f for all oating point numbers, and %2d for all integers; you are expected to exactly reproduce this output, including the heading and the spaces. Note also that the fourth item was rotated before being placed end wastage is preferable to internal wastage, especially in the last coil. To get the data into your program reliably, edit it in to a text le, and then execute your program from a command-line, piping the le in using input redirection (using <). Instructions on how to do this appear on the LMS. You should also construct other test inputs too, of course. Because all input data will come from a le (including during our post-submission testing), you should not print any prompts at all.
the allocation rules governing your Stage 1 and Stage 2 program would place that item on coil 2, starting at (3.0, 0.0). But there is actually room for that component within the end wastage of coil 1. The problem is that coil 1 has already been terminated so that coil 2 could be commenced. 2
To resolve this dilemma, a non-sequential allocation of components is required. In this mode, all of the components details are read in to arrays at the start of the program, and then batches of components are output. Each component has to appear somewhere in the output in one of the batches, but components dont have to appear in the same order as they were input. The actual process then followed is that a coil is loaded in to a single machine; all of the components assigned to one of the batches are cut; and then whatever is left of that coil is scrapped. A fresh coil is then loaded so that the next batch of components can be cut. The allocation rule to be used in this stage is at each step, scan all of the remaining unallocated components, nd the longest one that can t in to the current batch, and assign it to that batch; if none of the remaining components t this batch, then start a new batch. In the case of ties, you are to take the lowest numbered component of that maximal length. Each batch should be output as a block, in decreasing length order of components, that is, in the order that the components are selected and assigned to the batch. You may assume that at most 1,000 components will be input. The additional output for the combined ve input lines should now be: Stage 3 ------component 2, (10.0, 1.0) starting ( 0.0, 0.0) on coil 1 component 3, ( 8.0, 3.0) starting (10.0, 0.0) on coil 1 component 1, ( 4.0, 2.5) starting (18.0, 0.0) on coil 1 component 5, ( 1.8, 3.5) starting (22.0, 0.0) on coil 1 coil 1, internal wastage 33.0 m^2, end wastage 0.7 m^2 component 4, ( 3.0, 3.5) starting ( 0.0, 0.0) on coil 2 coil 2, internal wastage 0.0 m^2, end wastage 73.5 m^2 overall, total wastage 33.7 m^2 Note that you are also expected to retain your Stage 1+2 output; the ones shown here are additional output lines for Stage 3. More examples of the full output that is required are provided on the LMS. To complete this stage, your program will need to read all of the input data in to arrays as its rst action, so that the data can be processed twice, rst to do Stage 1+2, and then a second time to do Stage 3. Hence, no output will appear from this program until all of the input data has been read; in seeking to make better cutting assignments, it is no longer an on line, or interactive, process. Wherever appropriate, code should be shared between Stage 1+2 and Stage 3 through the use of functions. In particular, there shouldnt be long stretches of same or similar code appearing in different places in your program.
0.0
4.0
7.5
10.0
18.0
21.0
24.0
Figure 2: Possible layout of ve components on one coil, purely for fun. If you arent exhausted yet, and dont have any work to do in other subjects, see if you can come up with two-dimensional heuristics that generate efcient layouts. But please dont submit these programs. 3