Sie sind auf Seite 1von 4

Department of Computing and Information Systems

COMP20005 Engineering Computation Semester 1, 2014 Assignment 1


Learning Outcomes
In this project you will demonstrate your understanding of loops and if statements by writing a program that sequentially processes a le of text data. You are also expected to make use of functions; and in the third stage of the project, will need to make use of arrays (covered in Weeks 6 and 7, and in Chapter 7).

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.

Stage 1 Sequential Allocation (marks up to 5/10)


In the rst instance, we will suppose that only one cutting machine is available. It gets loaded up with a coil of steel, and then items are cut from that coil in the exact sequence that they are listed in the input le. To keep it simple, we will also assume that components are always laid out along the bottom edge of the coil, as shown in Figure 1. If an item cannot be cut from what is left on the current coil, the remainder of that coil is scrapped, and a new coil commenced. The required outputs of your program at this stage are the coil number associated with each component, together with the initial point of the allocation. For example, the four lines of input above would give rise to the following output:

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,

( 4.0, (10.0, ( 8.0, ( 3.0,

2.5) 1.0) 3.0) 3.5)

starting starting starting starting

( 0.0, ( 4.0, (14.0, ( 0.0,

0.0) 0.0) 0.0) 0.0)

on on on on

coil coil coil coil

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.

Stage 2 Computing Wastage (marks up to 7/10)


Now add in functionality that computes and reports the end wastage and internal wastage for each coil that is used, including the last partially consumed one. The total wastage for the fabrication run should also be computed. On the same input data, your output should match: Stage 1+2 --------component 1, ( 4.0, 2.5) starting ( 0.0, 0.0) on coil 1 component 2, (10.0, 1.0) starting ( 4.0, 0.0) on coil 1 component 3, ( 8.0, 3.0) starting (14.0, 0.0) on coil 1 coil 1, internal wastage 33.0 m^2, end wastage 7.0 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 40.0 m^2 Note that this is combined output for Stage 1 and Stage 2; you should not retain separate Stage 1 output. Further examples of the required output for each stage appear on the LMS.

Stage 3 Non-Sequential Allocation (marks up to 10/10)


If there was a fth component specied: 3.5 1.8

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.

Purely for Fun (and not for submission)


Of course, in a real factory the requirement that all of the components be aligned against the long edge of the coil would be regarded as being ridiculously wasteful, and arrangements like the one shown in Figure 2 would be employed. In this arrangement, all ve components can be allocated to the same coil.
3.5 3.0 2.5 1.8

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

The boring stuff...


This project is worth 10% of your nal mark. A rubric explaining the expectations that you will be marked against is available on the LMS. You need to submit your program for assessment; detailed instructions on how to do that will be posted on the LMS once submissions are opened. Submission will not be done via the LMS; instead you will need to log in to a Unix server and submit your les to a software system known as submit. You can (and should) use submit both early and often to get used to the way it works, and also to check that your program compiles correctly on our test system, which has some different characteristics to the lab machines. Only the last submission that you make before the deadline will be marked. You may discuss your work during your workshop, and with others in the class, but what gets typed into your program must be individual work, not copied from anyone else. So, do not give hard copy or soft copy of your work to anyone else; do not lend your memory stick to others; and do not ask others to give you their programs just so that I can take a look and get some ideas, I wont copy, honest. The best way to help your friends in this regard is to say a very rm no when they ask for a copy of, or to see, your program, pointing out that your no, and their acceptance of that decision, is the only thing that will preserve your friendship. A sophisticated program that undertakes deep structural analysis of C code identifying regions of similarity will be run over all submissions in compare every pair mode. Deadline: Programs not submitted by 10:00am on Monday 28 April will lose penalty marks at the rate of two marks per day or part day late. Students seeking extensions for medical or other outside my control reasons should email Alistair, ammoffat@unimelb.edu.au as soon as possible after those circumstances arise. Marks and a sample solution will be available on the LMS by Monday 12 May. And remember, programming is fun!

Das könnte Ihnen auch gefallen