CSE 11 Winter 2021 PA4 - Covid Transmission-2

Background

Disclaimer: These are sample statistics that do not accurately reflect COVID transmission. Please follow the CDC guidelines to stay up to date on the COVID-19 pandemic: https://www.cdc.gov/

UC San Diego is taking many actions to slow the spread of COVID-19, but they don't have a way of assessing how successful their preventative measures are. Given the skills you have demonstrated so far in CSE 11, they have tasked you with running transmission simulations and gathering data regarding how the virus would spread if all students went about their lives without taking any preventative measures. UCSD will then be able to use your results as a baseline and successfully assess how effective their preventative measures have been.

For this task, you will perform operations based on a file containing important information regarding the students involved in the simulation: their names, their locations at the start of the simulation, their movement patterns, and their COVID-19 infection statuses. We'll model the world as a one-dimensional array, so a student's location is their index in this array and their movement pattern is the number of indices that the student moves per day.

You will then be able to use our understanding of the virus to model how the virus would spread for the given scenario, and track important statistics about that spread.

After being briefed by Chancellor Khosla himself on the overall goal and why you were recruited, he assigns you several tasks to quickly get started with the problem at hand.

 

Part 0: Validity Checking and Variable Names

Throughout this assignment, we will be referencing specific variables by their specific name in each method. You may want to read Parts 1 and 2 for more background first.

names represents the array of student names.

locations represents the array of student locations in the 1-dimensional world.

movements represents the movement amounts of students.

infections represents the infection status of students.

worldSize (which will be introduced in Part 2) represents the size/length of the 1-dimensional world. Note that worldSize can be larger than the length of the parallel arrays.

Furthermore, we will always need to do validity checks for our inputs. Some methods will have extra checks needed, but for every method, the following constitute invalid input:

Any of the input arrays ( names , locations , movements , infections ) does not match any of the others in length.

Any of the input arrays is null .

Any of the values in the input array is not either or 1 .

 

Any of the values in the input array is not in the range [0, worldSize -1]. When worldSize is not

provided as an argument, there is no upper bound on the values in the input array locations . Non-positive input worldSize .

We won't require it, but it might be helpful for you to write (private) helper methods to do the validity checks.

 

Part 1: Reading Input File and Populating Arrays

You are asked to bring each student's information into your program from a file to create 4 Parallel Arrays describing the students involved in the simulation. Parallel Arrays are essentially multiple arrays of the same size such that the ith elements across all of the arrays combined represent a single entity, a student's properties in our case.

This file, if it exists, will have the following format:

 

Each line of the file will represent a single student

Each line is comma-separated and has the format Name,Location,Movement,Infection.

(the file will not contain quotation marks will be the student's first name and is a though).

 

Location describes where the student currently is in our one dimensional world and is an int .

Movement describes the amount of distance the student will move each day and is an int .

 

 

You can assume that the file is formatted properly and follows the following format, each line will always

be a with no spaces or symbols, a comma ( ',' ), an int -parsable number, a comma ( ',' ), an int -

parsable number, a comma ( ',' ), and either or 1 .

 

 

 

TODO: Method to Implement for Parsing Input

 

Read from the input file found at pathToFile and parse its data into the respective parallel arrays. You should use/import java.util.Scanner and java.io.File for this. You will also need to import java.io.IOException .

The student order (index in the array) should be as they are found in the file.

The four arrays ( names , locations , movements , and infections ) will be passed in by reference. Populate these directly.

If the arrays are populated successfully, return the maximum location value of the students + 1 (so if the

largest location value is then return 316 ), otherwise return -1 . Note that if the file IO results in an

exception, it is acceptable to not return -1 and throw an IOException instead (do either).

 

The arrays also cannot be populated successfully if any of their lengths does not exactly match the number of students in the file or if any array is null .

 

In any case where you would return -1 , you do not need to worry about restoring the input arrays to their original states.

Note that you can always assume the file is properly formatted, you don't need to check any of the values.

Example of populateArrays()

 

Suppose the file has the following content:

Then a call to populateArrays("Students.csv", names, locations, movements, infections) should return the

value (largest location value + 1) and the arrays after the call should have the elements:

All of Greg's information is at index 0, all of Paul's information is at index 1, etc.

Another Example of populateArrays()

A file containing

Jim,7,3,0 

Greg,5,2,1 

Sally,1,-2,0

Paul,1,-5,1 

Mary,8,4,0 

Fred,5,3,0 

Sara,1,1,1 

Sam,3,5,0

Rob,9,-6,0

will populate the arrays to look like the diagram on the next page:

 

Part 2: Update Locations and Infections

Now that you have a convenient way of representing the students in your program, Chancellor Khosla wants you to simulate students moving around and how infections spread when students come into contact with another student infected with COVID-19.

TODO: Methods to Implement for Movement and Infection Spreading

Given the locations and movements arrays, which hold the students' current locations and their movement values, move all students' locations by their respective movement amount.

An update to a student at index i should be made as follows: 

(the length of the world we are modeling), use the modulo operator (%) to wrap around in the arrays. For example, if the world is 20 units long ( worldSize is 20 ) and a student has location 2 and their movement value -5, their updated location should be 17. Note that in Java, the result of a%b is not always non-negative (it will depend on the sign of the operand). You will need to account for this difference when dealing with negative locations, which should wrap to the end of the "world."

Important edge cases to test include:

locationsi + movementsi >= locationsi + movementsi < 0

Do not change any values in movements .

On invalid inputs, do not change any values in locations , i.e., this method should return without doing anything.

Invalid inputs include the normal invalid inputs mentioned in Part 1.

 

This function will serve two purposes. Firstly, it will update the infection status of students who come in contact with infected students. Secondly, it will create and return a new array that stores the number of infections caused by each of the students.

Updating Infection Status:

update every student's infection status.

A student's infection value should be updated from 0 -> 1 if and only if they currently share a location with one or more students who have an infection value of 1.

Students who have an infection value of 1 will not experience an infection value change in this method.

These updates should be directly made to the array that is passed in.

Create/return array:

Create a new array which stores the number of infections caused by each student. This array should follow the same format as the parallel arrays, so the number of infections caused by student 0 should

be stored in.

The number of people an infected student will infect is equal to the number of non-infected individuals this student shares a location with at the start of this method (before any updates).

A non-infected student will have a value of 0.

If there are multiple infected students sharing the same location with non-infected students, all infected students will have their values increased to equal the number of non-infected students they share a location with. 

Since we know the worldSize, make sure that any positive value in world.

Do not make any changes to the values in the array.

 

On invalid inputs, return without doing anything.

Example Input:

 

and do not change any values in infections, i.e., this method should return

All students on locations 1, 3, and 4 must have their infection status updated to 1 as there are infected students on these locations. In this example, only locations 1 and 3 have both infected and non infected students, so we must update those students accordingly.

Updated infections Array:

returned numStudentsInfected Array:

The infected student on location 1 will have infected two individuals as they share location 1 with two non-infected students. The infected students at location 3 share the location with one non-infected student, so their numStudentsInfected values will both be one.

 

Part 3: Simulate Spread

Chancellor Khosla is really pleased with the progress you've made so far, and he's ready for you to fully simulate how COVID-19 will spread on campus when students go about their daily lives. He wants you to write a method that can simulate student movement and infections, and count the number of infections each student causes, as he believes this will provide powerful insight into the virus's spread.

TODO: Methods to Implement for Simulation

 

Each day, all students will move once by their movement amount (as defined in and by calling updateLocations() ) and infect or get infected by whoever comes in contact with them at their new location (as defined in and by calling updateInfections(). Note that at the beginning, even if an uninfected student is at the same location as an infected one, the uninfected student will not be infected (infections only happen after the first movement step).

This method should update simulation runs for.

This method should not update movements.

This method should additionally return an array parallel to the array where each element represents the total number of other students the student infected (as defined in

updateInfections() ) for the whole simulation.

If there are any invalid inputs, return null. Invalid inputs include the normal invalid inputs mentioned in

 

Part 1 but also additionally include days being negative. updating (so nobody is infected).

Example Input:

is valid and means no location/infection

Return:

 

 

Part 4: Analyze Results

The UC San Diego administration is really happy with the work you've done so far, and is excited to see how effective their preventative measures have been when compared to your model. They have two final tasks for you, one of which is to analyze the results a little more deeply, to gain a better understanding of what took place, and the other of which is to be able to interact with the program from the command line.

TODO: Methods to Implement To Analyze Results and Interact with Program

R0 or RNaught tells you the average number of people who will contract a contagious disease from one person with that disease.

Given the array, which gives us details regarding how many infections were caused by

each student (in the format of the returned value from countInfectionsByStudent() ), find the average infections per student. Return the smallest integer greater than or equal to this value (the ceiling of the value)

On invalid inputs, return -1. Invalid inputs include:

infectionRecord being null or length  0. Any value in infectionRecord being negative.

Example Input:

Return Value:

This method will take in the array, which gives us details regarding how many infections

were caused by each student (in the format of the returned value from countInfectionsByStudent() ), and the array which holds the first names of the students, to return the name of the student who caused the

most amount of infections.

If there is a tie among multiple students, return the student who appears first in the names array. On invalid inputs, return null . Invalid inputs include:

and/or names   being or length 0 .

and names have different lengths.

Any value in

Example Input:

Return Value:

This method is only a suggestion to help you in debugging your code, we will not be grading your main method. This is OPTIONAL. However, if you do submit it, make sure you have an appropriate method header.

The main method will be used to facilitate the interactions of your methods, and generate a print statement summarizing the results.

Your main function should read the command line inputs (passed in as args ), which will be of the form "pathToFile numberOfDays numberOfStudents", and call the respective functions with the necessary inputs. The order of the command line arguments should be the pathTofile , the days (to run thesimulation), and information for).

 

Initialize the four parallel arrays with length numberOfStudents .

Once you have parsed the command line inputs, and have initialized your arrays, you can test your methods and make sure you have accounted for all of the edge cases.

This method will not be graded, but you will need to write a main method to conduct your own testing for this PA.

 

Need a custom answer at your budget?

This assignment has been answered 6 times in private sessions.

© 2024 Codify Tutor. All rights reserved