Representing social connections in your program

Assignment Help Python Programming
Reference no: EM132520194

FIT9136 Algorithms and programming foundations in Python - Monash University

Assignment Problem 1: Representing social connections in your program

You should write your code for this Assignment Problem within the a2-xxxxxxxx-task1.py template file provided (rename this file to replace xxxxxxxx with your student ID).
Person class
Create a Python program that defines a Person class with the following methods.:
• init (first_name, last_name)
# Constructor method to create a new Person object.
# where first_name and last_name are strings containing the person's name
• add_friend(friend_person)
# This method should add a new social connection to be stored in this Person object.
# friend_person is a reference to another Person object.
• get_name()
# This method returns a string containing the person's first and last name concatenated together;
e.g. "Jom Tones"
• get_friends()
# This method returns a list of Person objects for the social connections that have been added.

The purpose of the Person class is to represent a person who is linked to other people by social connections. The above description specifies what methods and form the Person class required to have, but not how to code them.
Therefore each Person object must be able to store a set of references to other Person objects. (You will need to think about a suitable data type for storing a set of objects, and how you would need to initialize the empty set within the class definition.) In addition to storing the person's friends, your Person class should also contain instance variables to keep track of the person's name. If you wish to do so, you can extend this class by adding more methods as needed to help you complete the rest of the assignment.

load_people function
After implementing this class, implement a separate function in your program named load_people() which does the following:
1. Opens the file a2_sample_set.txt which contains the data set given.
2. Creates a new Person object for each record (line) in the file, which contains the name of the person represented by that record.
3. Where a person's record indicates that they have friends, you should use the addFriend() method to add each friend to that Person object.3
4. Finally, return a list of all the Person objects that have been created from the file records (making sure to have closed the file first).

4. Assignment Problem 2: Simulate disease spread

You should write your code for this Assignment Problem within the a2-xxxxxxxx-task2.py template file provided (rename this file to replace xxxxxxxx with your student ID).
Patient class (a subclass of Person)
The Person class you defined in Assignment Problem 1 is fine for mapping social connections, but it does not contain appropriate methods for simulating disease spread or health of the people in our group.
Before you move to writing the simulation (later in this task), define a Patient class which inherits the methods of the Person class through inheritance. Your Patient class should add the following methods:
• init (first_name, last_name, initial_health)
# Constructor method to create a new Patient object by inheriting from the Person class.
# where first_name and last_name are strings containing the person's name
# and initial_health is the starting value of the person's health points.
• get_health()
# This method returns the patient's current health points.4
• set_health(new_health)
# This method changes the patient's current health points directly.
• is_contagious()
# This method should return a Boolean result of True if the person's health points are in the range of being contagious (able to spread disease) as defined in section 2. It should return False if the person is not currently contagious.
• infect(viral_load)
# This method infects the Patient object with a viral load. It causes the patient to receive the viral load specified in the method's argument (given as a floating point number).
# After receiving a viral load, the person may or may not become sick enough to be contagious.
# Calling this method should adjust the person's health points according to the rules defined in section
2. Note that the person's health cannot go below 0 as discussed in section 2.
• sleep()
# Calling this method causes the person to recover some health points (one night's sleep) according to the rule defined in section 2.

To implement these methods, your Patient class should also contain an instance variable to keep track of the person's current health points.5 If you wish to do so, you can extend this class further by adding more methods as needed to help you complete the rest of the assignment.

load_patients function (a new version of the load_people function in Assignment Problem 1)
You will also need to write a slightly different version of the function you wrote to load data from the file, since we really need a list of Patient objects, not a list of Person objects. Write a function named load_patients(default_health) which does the following:6
1. Reads from the file a2_sample_set.txt.
2. Creates a new Patient object for each record (line) in the file, which contains the name of the person represented by that record. For each Patient object created, you should assign the health value given by the default_health argument, since the initial health of each person is not listed in the file.
3. Where a person's record indicates that they have friends, you should use the inherited add_friend
method to add each friend to that Person object.
4. Finally, return a list of all the Patient objects that have been created from the file records.
In other words, this function should do the same thing as load_people, except that it should create Patient
objects (with a specified default health value) instead of Person objects.

run_simulation function - implement the simulation logic...
Now implement a run_simulation(days, meeting_probability, patient_zero_health) function which should implement the following behaviour:
1. Take in the following arguments:
a. days: the integer number of days the simulation should run for.
b. meeting_probability: the fractional probability that any person may visit a certain friend on a certain day. 0.0 means 0% chance, 1.0 means 100% chance. (This was explained in section 2.)
c. patient_zero_health: the initial health of the first person in the file. (See below.) If the (rounded) initial health is less than or equal to 49, this person is contagious and there may be the chance of a disease outbreak.
2. Use your load_patients() function from Assignment Problem 1 to load person data from the disk. The first patient in the returned list (who we will call ‘patient zero') should be given the starting health value specified in the patient_zero_health argument. The remaining patients should be given an initial health value of 75, which is the average health of the population from section 2.
3. Run through each day of the simulation. For each day, do the following:
a. For each patient in the group, look at each of the person's friends, and randomize whether the person should meet that friend today.7 The probability for this to happen is given by the meeting_probability argument. If the meeting takes place, each person in that pair who is contagious8 should spread a viral load to the other person, by calling the infect() method on the other person. You will need to calculate what viral load to infect each friend with according to the rules in section 2.
b. After all meetings have completed for the day, check how many people are now contagious in the simulation.

c. After the end of each day, all people should sleep() to recover some health.
4. Finally, the function should return a list with the daily number of contagious cases through the duration of the simulation. (as measured in 3.b.) For example, if your simulation runs for 30 days, the list should contain 30 integers containing the number of people who were contagious at the end of each day, from the first day of the simulation (element [0]) to the last day of the simulation (element [29]).
You may write your own code within the main block to test your simulation. Note that due to random probability, you may get a different result each time you run your simulation, depending on your parameters.

Assignment Problem 3: Visualise the curve

Complete this Assignment Problem in the a2_xxxxxxxx_task3.py template file (change xxxxxxxx to your student ID).
visual_curve function

Write a function named visual_curve(days, meeting_probability, patient_zero_health) which runs the simulation using the specified arguments, and then does the following:
1. Runs the simulation by calling the run_simulation function with the specified arguments for days, meeting_probability,

patient_zero_health.

2. After the simulation is complete, prints the whole daily list of contagious patient counts from the returned data.

3. Then, using functionality from either the matplotlib or pandas library, plot a curve showing the daily number of contagious patients over the number of days of the simulation. The days of the simulation should be on the X axis and the contagious patient count on the Y axis. Your graph should have the X and Y axis labelled accordingly.

Attachment:- Algorithms and programming foundations in Python.rar

Reference no: EM132520194

Questions Cloud

Successfully implementing international strategy : What are the three basic benefits firms can gain by successfully implementing an international strategy?
Describe the activity of chromosomes : Describe the activity of chromosomes in each stage of Meiosis I and Meiosis II.
Calculate the cost of one hockey stick : Calculate the cost of one hockey stick assuming that 1,900 sticks were completed during June. Round your answer to the nearest cent.
Explain what scientism is and describe arguments against it : In 250-300 words, explain what scientism is and describe two of the main arguments against it. In 750-1,000 words, answer each of the worldview questions.
Representing social connections in your program : Representing social connections in your program - implement these methods, your Patient class should also contain an instance variable to keep track
Cloning for generating many copies of a dna fragment : PCR is a technology that has many useful applications with biotechnology. What are some of those applications?
Activity of chromosomes in each stage of mitosis : Describe the activity of Chromosomes in each stage of Mitosis.
Completed CITI training : You completed CITI training. Upon completion of the training you will receive a certificate you have to turn into me.
Would be centralized or decentralized : Would be centralized or decentralized? List the advantages and disadvantages of both and talk about the one would choose one versus the other.

Reviews

Write a Review

Python Programming Questions & Answers

  Write program that read a text file and prints only odd line

Write a program that reads a text file and prints out only odd lines to the screen. Thus, lines 1, 3, 5,... only printed. Update your odd lines program (Q1) to write odd lines to the screen and write then lines to another file.

  Accept a single integer argument and calculate the factorial

Create a Python file that a single function called cachedfactorial. The function will accept a single integer argument and calculate the factorial value.

  Add an option for the computer to guess as well as the user

You will add quite a bit of code to your project. You will add an option for the computer to guess as well as the user to guess a number.

  Write test and debug the program using Python

Write an algorithm for a program that shows the use of all 6 math functions. Write, test, and debug the program using Python

  ITS320 Basic Programming Question - Create a program

ITS320 Basic Programming assignment help and assessment help, Colorado State University - Create a program that will calculate the weekly average tax.

  Write a Python script that allows the user to enter a number

COMS 104 Introduction to Programming Assignment, Iowa State University, USA. Write a Python script that allows the user to enter a number greater than 100

  Compute the sum of the first n prime numbers

Write the statements needed to compute the sum of the first n prime numbers. The sum should be associated with the variable total.

  Design part of the code for the haunted house game

Create a cheat commands in the game so player can teleport to any location in the map - You are tasked with improving and designing part of the code for the Haunted House game.

  Calculate the amount of county sales tax

A retail company must file a monthly sales tax report listing the total sales for the month and the amount of state and county sales tax collected.

  Exploring the potential of natural language processing

For Reading Purposes. EXPLORING THE POTENTIAL OF NATURAL LANGUAGE PROCESSING AND MACHINE LEARNING IN CHILD LANGUAGE DISORDERS DIAGNOSIS, Preprocessing data from conti-4 : cleaning the raw dataset into structured form for subsequent processing and ana..

  Project will be a simple, working program

This programming project will be a simple, working program, using Python language, which utilizes a good design process and includes:Sequential, selection, and repetitive programming statements as well as,At least one function call.

  Write your own functions to rewire the network

Write your own functions to rewire the network according to the G(N;M) and Configuration Model random networks.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd