Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

School of Computing and Information Systems

comp20005 Engineering Computation


Semester 1, 2021
Assignment 2

Learning Outcomes
In this project you will demonstrate your understanding of structures and arrays of structures, and will
develop a computational solution for a non-trivial problem. You are expected to make extensive use of
functions; and to demonstrate that you have adopted a clear and elegant programming style. You will find
it difficult to create a working solution unless you plan your program carefully in advance, and develop
it incrementally.

Facility Location Problems


Phone companies want to find the right places to locate their cell-network towers; hamburger chains
want to find the right locations to build new drive throughs; governments want to put schools in the
right locations; and city councils want to locate recycling facilities at points where they will be used. In
general, we want facilities to be conveniently located, so that we can access them when we need them.
In this assignment we will be looking at the locations of shopping centers, but the principles involved
apply to many services and facilities.
Program input will again be a tab separated values file. For example, malls1.tsv contains:

name xloc yloc glam carp


f 6.3 15.2 13.6 1.9
u 17.5 3.4 13.3 0.8
n -8.3 -6.3 8.9 0.2
i -11.5 -1.5 16.3 0.3
y 0.5 -0.5 9.3 1.1

where name is a letter that identifies the shopping center; xloc and yloc are the (x, y) locations in
kilometers of a shopping center relative to the center of the city; glam is its glamour score, a measurement
of the attractiveness of that shopping center, see below; and carp is a measure of the difficulty of getting
a carpark at that shopping center. The city has as many as fifty different shopping centers.

Stage 1 – Control of Reading and Printing (marks up to 8/20)


You can base your program on your Assignment 1 solution, to get started. But note, for this assignment
you are required to define and use a struct to store the input data. In this first stage, you have to show
that you have successfully read the input data; on the file malls1.tsv the required output is

S1, 5 malls described in input file


S1, mall 0 = f, xloc = 6.3, yloc = 15.2, glam = 13.6, carp = 1.9
S1, mall 1 = u, xloc = 17.5, yloc = 3.4, glam = 13.3, carp = 0.8
S1, mall 2 = n, xloc = -8.3, yloc = -6.3, glam = 8.9, carp = 0.2
S1, mall 3 = i, xloc = -11.5, yloc = -1.5, glam = 16.3, carp = 0.3
S1, mall 4 = y, xloc = 0.5, yloc = -0.5, glam = 9.3, carp = 1.1

To obtain full marks you need to exactly reproduce the required output lines. Full examples can be found
on the FAQ page linked from the LMS. The input provided to your program will always be sensible and
correct, and you do not need to perform any data validation.

1
Stage 2 – Walking a Grid (marks up to 16/20)
The relative attractiveness of a shopping center to a resident of the city is determined by
glamour
RA = ,
distance + carpark
where distance is how far that person lives from the shopping center, calculated in kilometers based
on Euclidean straight-line travel (we might also consider using rectilinear distances if the road network
contains roads that only run north-south and east-west, but that is for another day).
Suppose that each resident always goes to the shopping center that has the greatest RA value, based
on where they live. So shopping centers that have higher glamour scores tend to draw people from
suburbs that might actually be closer to a less glamorous shopping center. People are also prepared to
drive further if the car parking is easier. For example, in malls1.tsv shopping center f is reasonably
glamorous, but its carparking situation is not so good.
No resident will go to any shopping center if its RA is below 1.0 at their address. This may mean
that some residents can’t go shopping, and have to rely on deliveries. Your program is intended to help
identify the business opportunities that these “no shopping nearby” spots create.
Suppose that the city stretches across a square range defined by x ∈ [−25.0, +25.0] kilometers and
y ∈ [−25.0, +25.0] kilometers, and that we wish to compute the “attraction zone” of each shopping
center as a percentage of the total space occupied by the city (which is 2500 square kilometers).
To do this, we split the city into 0.1 × 0.1 kilometer grid cells (that is, a grid containing 500 × 500 =
250,000 cells), and compute the preferred shopping center at the midpoint of each such cell. For example,
the south-west cell spans the area [−25.0, −24.9]×[−25.0, −24.9], and is represented by its central point
at (−24.95, −24.95). By computing a RA value for each known shopping center at that point, we can
determine which shopping center that point is attracted to, and then count that whole grid cell as going to
the same center. This will then give an approximation of the desired percentage attraction; if we wanted
to, we could decrease the edge size of each grid cell to get a more precise estimate.
The required output from your program from this stage for malls1.tsv is:

S2, 250000 grid cells processed, each 0.010 km^2


S2, mall f attracts 343.6 km^2 = 13.7% of city
S2, mall u attracts 360.3 km^2 = 14.4% of city
S2, mall n attracts 61.8 km^2 = 2.5% of city
S2, mall i attracts 614.3 km^2 = 24.6% of city
S2, mall y attracts 124.4 km^2 = 5.0% of city
S2, no shopping for 995.6 km^2 = 39.8% of city

Stage 3 – Drawing a Grid (marks up to 19/20)


Your boss is very pleased to know that around 40% of the city area does not have a good shopping center
handy, and plans to invest in a new one and capture more of the shopping market. So for your next task,
you are asked to generate a map showing the empty locations. So you switch to a different grid, now one
in which each cell is 1 km wide and 2 km tall, and compute the coverage regions again. But this time,
instead of adding them up, you draw them as a ”character map”, see Figure 1.
Once you have printed this you understand why each cell is twice as tall as it is wide – it approximates
the aspect ratio of typical terminal-style fixed-width fonts. (Best of all, when you boss sees your output
they have a nostalgia trip back to their own programming classes in the 1980s when they were nineteen
and learnt C from Alistair, and award you an immediate pay rise based on anticipated future profits.)

Stage 4 – Finding the Edges (marks up to 20/20)


In fact, your boss likes your map so much they print thousands of copies, and use up all the toner in
the printer. So, to be a environmentally responsible, you make one last change to your program, to

2
S3, +--------------------------------------------------+
S3, 24.0km | fffffffffffffff |
S3, 22.0km | fffffffffffffffffff |
S3, 20.0km | fffffffffffffffffffff |
S3, 18.0km | fffffffffffffffffffffff |
S3, 16.0km | fffffffffffffffffffffff |
S3, 14.0km | iiiiiii fffffffffffffffffffffuuuuuuuu |
S3, 12.0km | iiiiiiiiiiiiiiiiffffffffffffffffffuuuuuuuuuuu|
S3, 10.0km | iiiiiiiiiiiiiiiiiiiifffffffffffffffuuuuuuuuuuuuu|
S3, 8.0km | iiiiiiiiiiiiiiiiiiiiiiifffffffffffuuuuuuuuuuuuuuu|
S3, 6.0km |iiiiiiiiiiiiiiiiiiiiiiiiyyyyfffffuuuuuuuuuuuuuuuuu|
S3, 4.0km |iiiiiiiiiiiiiiiiiiiiiiiyyyyyyyyuuuuuuuuuuuuuuuuuuu|
S3, 2.0km |iiiiiiiiiiiiiiiiiiiiiiyyyyyyyyyyuuuuuuuuuuuuuuuuuu|
S3, 0.0km |iiiiiiiiiiiiiiiiiiiiiiyyyyyyyyyyuuuuuuuuuuuuuuuuuu|
S3, -2.0km |iiiiiiiiiiiiiiiiiiiiiiyyyyyyyyyyyuuuuuuuuuuuuuuuuu|
S3, -4.0km |iiiiiiiiiiiiiiiiinniiiiyyyyyyyyyyuuuuuuuuuuuuuuuuu|
S3, -6.0km |iiiiiiiiiiiiiinnnnnnnniiyyyyyyyy uuuuuuuuuuuuuuuu|
S3, -8.0km |iiiiiiiiiiiiiinnnnnnnniiiiiyy uuuuuuuuuuu |
S3, -10.0km |iiiiiiiiiiiiiinnnnnnnniiiii |
S3, -12.0km | iiiiiiiiiiiiiiinnnnniiiii |
S3, -14.0km | iiiiiiiiiiiiiiiiiii |
S3, -16.0km | iiiiiiiiiiiii |
S3, -18.0km | |
S3, -20.0km | |
S3, -22.0km | |
S3, -24.0km | |
S3, +--------------------------------------------------+
Figure 1: The required Stage 3 output.

“blank out” any cells in the map that have the same label as all of their eight neighboring cells – see the
Assignment video for details of this requirement. Now the map looks like Figure 2.

Modifications to the Specification


There are bound to be areas where this specification needs clarification or correction, and you should refer
to the “Assignment 2” LMS Discussion regularly and check for possible updates to these instructions.

The Boring Stuff...


This project is worth 20% of your final mark, and is due at 6:00pm on Friday 21 May.
Submissions that are made after that deadline will incur 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 ammoffat@unimelb.edu.au as soon as possible after those circumstances arise. If you
attend a GP or other health care service as a result of illness, be sure to take a Health Professional
Report (HPR) form with you (get it from the Special Consideration section of the Student Portal), you
will need this form to be filled out if your illness develops in to something that later requires a Special
Consideration application to be lodged. You should scan the HPR form and send it with any non-Special
Consideration assignment extension requests.
Submission: Programs (your .c file) must be submitted via the LMS. Don’t forget to include and to
“sign” and date the Authorship Declaration that is required at the top of your program.
Testing: You can also carry out pre-submission testing via a system known as submit, available at http:
//submit-web.eng.unimelb.edu.au. The submit system uses the same computer/compiler that will
be employed for post-submission testing (a Unix computer called dimefox which is very unforgiving of
uninitialized variables and out-of-bounds array accesses). Note that submit may become congested and
non-responsive in the final day or hours before the deadline.

3
S4, +--------------------------------------------------+
S4, 24.0km | fffffffffffffff |
S4, 22.0km | fff fff |
S4, 20.0km | ff ff |
S4, 18.0km | ff ff |
S4, 16.0km | f fff |
S4, 14.0km | iiiiiii ff fffuuuuuuuu |
S4, 12.0km | iiiiii iiiiiff fffuuu uu|
S4, 10.0km | iiii iifff fffuuu u|
S4, 8.0km | ii iiifffff fffuuu u|
S4, 6.0km |ii iiyyyyfffffuuu u|
S4, 4.0km |i iiyy yyyyuuu u|
S4, 2.0km |i iyy yyu u|
S4, 0.0km |i iy yuu u|
S4, -2.0km |i iiii iyy yyu u|
S4, -4.0km |i iiiinniiiiyy yyuu u|
S4, -6.0km |i innnnnnnniiyyyyyyyy uuuu uuu|
S4, -8.0km |i in niiiiiyy uuuuuuuuuuu |
S4, -10.0km |ii innn nni ii |
S4, -12.0km | iiii iiinnnnniiiii |
S4, -14.0km | iiii iiiiiiii |
S4, -16.0km | iiiiiiiiiiiii |
S4, -18.0km | |
S4, -20.0km | |
S4, -22.0km | |
S4, -24.0km | |
S4, +--------------------------------------------------+
Figure 2: The required Stage 4 output.

Marking Rubric: A rubric explaining the marking expectations is linked from the assignment’s LMS,
and you should study that rubric very closely. Feedback, marks, and a sample solution will be made
available approximately two weeks after submissions close.
Academic Honesty: 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, and not
developed jointly with anyone else. So, do not give hard copy or soft copy of your work to anyone else;
do not “lend” your “Uni backup” memory stick to others for any reason at all; and do not ask others to
give you their programs “just so that I can take a look and get some ideas, I won’t copy, honest”. The best
way to help your friends in this regard is to say a very firm “no” if they ask to see your program, pointing
out that your “no”, and their acceptance of that decision, are the only way to preserve your friendship. See
https://academicintegrity.unimelb.edu.au for more information. Note also that solicitation of
solutions via posts to “tutoring” sites or online forums, whether or not there is payment involved, and
whether or or not you actually employ any solutions that may result, is also serious misconduct. In the
past students have had their enrolment terminated for such behavior.

The LMS page links to a program skeleton that includes an Authorship Declaration that you must
“sign” and date and include at the top of your submitted program. Marks will be deducted (see the
rubric linked from the LMS page) if you do not include the declaration, or do not sign it, or do not
comply with its expectations. A sophisticated program that undertakes deep structural analysis of C
code identifying regions of similarity will be run over all submissions. Students whose programs are
identified as containing significant overlaps will have substantial mark penalties applied, or be
referred to the Student Center for possible disciplinary action, without further warning.

And remember, programming is fun!

c The University of Melbourne, 2021. Prepared by Alistair Moffat, ammoffat@unimelb.edu.au.

You might also like