COMP20005 Engineering Computation Semester 2, 2022

The University of Melbourne
School of Computing and Information Systems
COMP20005 Engineering Computation
Semester 2, 2022
Assignment 1
Due: 4:00 pm Monday 3rd October 2022
Version 1.0
1 Learning Outcomes
In this assignment you will demonstrate your understanding of loops and if statements by writing a program
that sequentially processes a le of input data. You are also expected to make use of functions and arrays.
2 The Story…
Trac forecasting aims to forecast the trac conditions (such as trac speed or volume) of the future given
historical trac observations (such as speed sensor readings). It plays an important role in many applica-
tions. For example, accurate trac forecasting can help predict the travel times of dierent routes, such
that navigation apps such as Google Maps can recommend faster routes, hence improving fuel eciency and
travel experience. It can also help trac management systems make eective informed decisions (such as
to open or close some lanes) to reduce trac congestion.
Figure 1 shows an example, where each coloured dot represents a trac speed sensor in the freeway system
of the metropolitan areas of California, USA1. The dierent colours of the dots represent dierent average
trac speed values recorded by the sensors for the last ve minutes. A red colour suggests a low trac
speed while a green colour suggests a high trac speed. At 8:15 pm, 28 January, 2021 (Figure 1a), if a
navigation app can forecast the low trac speed for the two (red) dots enclosed by the two rectangles at
9:00 pm (Figure 1b), it can suggest alternative routes to help users avoid these congested locations.
(a) 8:15 pm, 28 January 2021 (b) 9:00 pm, 28 January 2021
Figure 1: Trac speed sensing (California, USA)
In this assignment, we are given a set of trac speed sensor readings (in km/hour) that represent the average
trac speed at 5-minute intervals for the past hour at dierent (sensor) locations. The aim is to forecast
the average trac speed for these locations in the next ve minutes2. You do not need to be an expert in
trac forecasting or sensor technologies to complete this assignment.
1Data source: https://pems.dot.ca.gov
2We consider short-term forecasting as we will only use simple forecasting algorithms. Accurate forecasting for a longer term
into the future requires state-of-the-art AI technology which is beyond our scope { if you are interested, see the manuscript \A
Graph and Attentive Multi-Path Convolutional Network for Trac Prediction" by Jianzhong Qi et al.
1
Below is a sample set of input data. The rst line contains a positive integer num_locations representing
the number of sensor locations in the input data. In the example below, num_locations = 10, meaning
that there are 10 sensor locations.
Starting from the second line, each line contains data of a sensor locations. Each line has 15 columns
separated by spaces (` '):
The rst column contains a unique 3-digit positive integer representing the ID of the sensor location.
The second and the third columns contain two positive integers representing the x- and y-coordinates
of the sensor location.
The rest of the 12 columns represent the average trac speed readings recorded by the sensor in
5-minute intervals for the past hour (that is, a total of 12 intervals and hence 12 columns). Suppose
the current time is 9:00 pm. Then, Column 4 is the average trac speed reading between 8:00 pm
and 8:05 pm; Column 5 is the average trac speed reading between 8:05 pm and 8:10 pm; : : :; and
Column 15 is the average trac speed reading between 8:55 pm and 9:00 pm. Our aim is to forecast
the average trac speed between 9:00 pm and 9:05 pm.
Each average trac speed is a positive real number with 2 digits after the decimal point.
10
104 83 99 34.31 83.29 77.35 66.66 44.12 49.65 60.72 78.76 29.45 15.16 35.70 26.56
106 52 73 99.36 99.33 97.02 90.86 96.57 99.04 99.77 90.75 99.54 92.33 93.42 98.34
114 19 14 90.85 11.50 66.26 84.71 90.63 17.01 70.02 54.95 92.38 28.54 69.71 97.08
121 22 24 53.65 10.47 91.25 57.63 13.60 94.24 17.20 93.32 74.15 89.60 24.25 99.00
124 44 82 51.13 56.52 24.10 69.71 28.05 16.02 32.55 15.17 76.31 70.95 40.39 13.25
132 61 16 29.42 15.55 30.03 29.92 22.67 21.25 11.80 23.48 25.30 23.52 22.90 20.66
201 52 53 03.27 06.62 00.43 02.28 01.59 02.42 02.72 02.11 07.61 01.36 07.77 03.73
221 52 83 75.16 48.13 44.73 73.19 89.57 67.68 39.90 69.93 85.13 65.58 11.50 81.63
351 98 82 77.83 86.72 82.94 85.29 85.66 85.58 81.95 94.71 88.00 89.49 84.69 85.93
797 39 42 32.11 30.26 56.67 34.44 67.17 57.29 22.07 94.14 40.30 10.67 84.16 21.69
The second line of the sample above represents sensor location #104 at (83, 99), and its past average trac
speed readings are: 34.31, 83.29, 77.35, 66.66, 44.12, 49.65, 60.72, 78.76, 29.45, 15.16, 35.70, 26.56.
You may assume that the input is always correctly formatted, 0 < num_locations < 101, and there will
not be two sensor locations with the exact same coordinates. The input is sorted by the sensor location ID
in ascending order.
3 Your Task
Your task is to write a program that reads the input data and outputs trac speed forecasts. The assignment
consists of four stages.
3.1 Stage 1 - Process the First Sensor Location (Marks up to 5/20)
Write a program that reads the rst two lines of the input data and prints out: num_locations, the ID and
the coordinates of the rst sensor location, and the historical average (HA) trac speed for the past hour
of the rst sensor location.
Given a sensor location L with m (m = 12 in our case) average trac speed readings s0; s1; : : : ; sm􀀀1, its
historical average trac speed is calculated as:
HA(L) =
1
m
mX􀀀1
i=0
si (1)
The output of this stage given the above sample input should be (where \mac:" is the command prompt):
mac: ./program < test0.txt
2
Stage 1

num_locations: 10
ID of the first sensor location: #104
At: (83, 99)
Historical average traffic speed: 50.14
Here, 50.14 is the historical average trac speed of the rst sensor location as calculated by Equation 1.
You should write functions to process this and the following stages where appropriate.
Hint: To ensure the result accuracy, use double’s for storing the trac speed readings and calculating the
historical average. Use %05.2f for the historical average output formatting. You may also read all input
data before printing out for Stage 1.
As this example illustrates, the best way to get data into your program is to save it in a text le (with a
.txt" extension, any text editor can do this), and then execute your program from the command line,
feeding the data in via input redirection (using <).
In your program, you will still use the standard input functions such as scanf() to read the data. Input
redirection will direct these functions to read the data from the le, instead of asking you to type it in by
hand. This will be more convenient than typing out the test cases manually every time you test your pro-
gram. Our auto-testing system will feed input data into your submissions in this way as well. To simplify
the marking, your program should not print anything except for the data requested to be output (as shown
in the output example).
We will provide a sample test le \test0.txt" on Canvas. You may download this le directly and use it
to test your code before submission. This le is created under Mac OS. Under Windows systems, the entire
le may be displayed in one line if opened in the Notepad app. You do not need to edit this le to add
line breaks. The `\n’ characters are already contained in the le. They are not displayed properly but the
scanf() function in C can still recognise them correctly.
3.2 Stage 2 - Forecast Based on Historical Average (Marks up to 10/20)
Now modify your program so that the historical average trac speed of each sensor location is computed and
visualised. You may assume that the historical average trac speed values are within the range of (0; 100)
(use %05.2f for the historial average output formatting). On the same sample input data, the additional
output for this stage should be (you need to work out how the visualisation works based on this example):
Stage 2

#104, HA: 50.14 |–±-+
#106, HA: 96.36 |–±-±-±
#114, HA: 64.47 |–±-±
#121, HA: 59.86 |–±-+
#124, HA: 41.18 |–±-
#132, HA: 23.04 |–+
#201, HA: 03.49 |-
#221, HA: 62.68 |–±-±
#351, HA: 85.73 |–±-±-+
#797, HA: 45.91 |–±-
This stage is actually a classic trac forecasting algorithm called the historical average (HA) algorithm,
that is, the historical average trac speed for the past hour is our forecast of the average trac speed in
the next ve minutes.
3.3 Stage 3 - Forecast Based on Nearby Sensor Locations (Marks up to 15/20)
In the HA algorithm, we have considered each sensor location on its own. Taking a step further, research
has shown that trac conditions at nearby locations are highly correlated. For example, congestion at an
intersection will soon propagate to its neighbouring intersections.
3
In this stage, your task is to calculate and visualise a forecast based on neighbours (FN) for each sensor
location L based on the following equation:
FN(L) =
1
jN (L)j + 1
X
L02N(L)[fLg
HA(L0) (2)
This equation calculates the historical average trac speed (using Equation 1) of L and each of the neigh-
bouring locations of L. The mean of these historical average values is FN(L). Here, N(L) represents the
set of neighbouring locations of L, and jN (L)j represents the number of neighbouring locations of L.
Given a sensor location L, another sensor location L0 is a neighbouring location of L if the (Euclidean)
distance between L and L0 is within 10 distance units (inclusive). Suppose the coordinates of L and L0 are
(x; y) and (x0; y0), respectively. Then, their (Euclidean) distance is calculated as:
distance(L;L0) =
p
(x 􀀀 x0)2 + (y 􀀀 y0)2 (3)
On the same sample input data, the additional output for this stage should be (using %05.2f for formatting):
Stage 3

#104, FN: 50.14 |–±-+
#106, FN: 79.52 |–±-±-
#114, FN: 64.47 |–±-±
#121, FN: 59.86 |–±-+
#124, FN: 51.93 |–±-+
#132, FN: 23.04 |–+
#201, FN: 03.49 |-
#221, FN: 66.74 |–±-±
#351, FN: 85.73 |–±-±-+
#797, FN: 45.91 |–±-
Here, location #106 at (52, 73) and location #221 at (52, 83) are within 10 distance units. The FN of
location #106 is thus calculated as the mean of the HA of these two locations: 79.52 = (96.36+62.68)/2.
Hint: You should store the HA values calculated in Stage 2 and reuse them for this stage.
3.4 Stage 4 - Identify Trac Incidents (Marks up to 20/20)
A large
uctuation (that is, standard deviation) in the trac speed for the past hour is an indication of
events such as accidents that have made a strong impact on the trac condition. In this stage, your task
is to calculate the standard deviation (based on the equation below) of the trac speed readings for each
sensor location L and print out the sensor locations in descending order of their standard deviation values.
SD(L) =
vuut
1
m
mX􀀀1
i=0

si 􀀀 HA(L)
2
(4)
On the same sample input data, the additional output for this stage should be (using %05.2f for formatting;
note a nal newline character `\n’ at the end of the output):
Stage 4

#121, SD: 33.69
#114, SD: 29.06
#797, SD: 24.97
#124, SD: 22.17
#104, SD: 21.88
#221, SD: 21.62
#132, SD: 05.27
#351, SD: 03.94
#106, SD: 03.39
#201, SD: 02.38
Hint: You may study the sample solution of Ex7.05 on Grok before starting on this stage.
4
4 Submission and Assessment
This assignment is worth 20% of the nal mark. A detailed marking scheme will be provided on Canvas.
Submitting your code. To submit your code, you will need to: (1) Log in to Canvas LMS subject site, (2)
Navigate to \Assignment 1" in the \Assignments" page, (3) Click on \Load Assignment 1 in a new window",
and (4) follow the instructions on the Gradescope \Assignment 1" page and click on the \Submit" link to
make a submission. You can submit as many times as you want to. Only the last submission made before the
deadline will be marked. Submissions made after the deadline will be marked with late penalties as detailed
at the end of this document. Do not submit after the deadline unless a late submission is intended. Two
hidden tests will be run for marking purpose. Results of these tests will be released after the marking is done.
You can (and should) submit both early and often { to check that your program compiles correctly on
our test system, which may have some dierent characteristics to your own machines.
Testing on your own computer. You will be given a sample test le test0.txt and the sample output
test0-output.txt. You can test your code on your own machine with the following command and compare
the output with test0-output.txt:
mac: ./program < test0.txt /* Here `<’ feeds the data from test0.txt into program */
Note that we are using the following command to compile your code on the submission testing system (we
name the source code le program.c).
gcc -Wall -std=c99 -o program program.c -lm
The
ag -std=c99" enables the compiler to use a modern standard of the C language { C99. To ensure
that your submission works properly on the submission system, you should use this command to compile
your code on your local machine as well.
Testing on Grok. You may also choose to develop your solution on Grok in the Assignment 1 module.
Your code on Grok will not be marked. Make sure to submit via Gradescope after you are satis ed with
your solution.
You may discuss your work with others, but what gets typed into your program must be individual work,
not from anyone else. Do not give (hard 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 won’t 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. See https://academichonesty.unimelb.edu.au for more information.
Deadline: Programs not submitted by 4:00 pm Monday 3rd October 2022 will lose penalty marks
at the rate of 3 marks per day or part day late. Late submissions after 4:00 pm Friday 7th October 2022
will not be accepted. Students seeking extensions for medical or other \outside my control" reasons should
email the lecturer at jianzhong.qi@unimelb.edu.au. If you attend a GP or other health care professional as a
result of illness, be sure to take a Health Professional Report (HRP) form with you (get it from the Special
Consideration section of the Student Portal), you will need this form to be lled out if your illness develops
into something that later requires a Special Consideration application to be lodged. You should scan the
HPR form and send it in connection with any non-Special Consideration assignment extension requests.
Special consideration due to COVID-19: Please refer to the \Special Consideration" section in this page:
https://students.unimelb.edu.au/your-course/manage-your-course/exams-assessments-and-results
And remember, C programming is fun!

c 2022 The University of Melbourne
Prepared by Jianzhong Qi based on an assignment template from Alistair Moat
5

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值