def simWithDrug_Delay_300(numViruses, maxPop, maxBirthProb, clearProb, resistances, mutProb, numTrials): finalPop = [] # a list containing 150 elements; the i-th element #records the i-th trial's final population of viruses for i in range(numTrials): finalPop.append(0.0) virList = [] # a list which contains all the ResistantVirus for num in range(numViruses): a_virus = ResistantVirus(maxBirthProb, clearProb, resistances, mutProb) virList.append(a_virus) for trial in range(numTrials): thePoorGuy = TreatedPatient(virList, maxPop) for i in range(300): thePoorGuy.update() thePoorGuy.addPrescription('guttagonol') #add guttagonol for j in range(300, 450): thePoorGuy.update() finalPop[trial] += thePoorGuy.getTotalPop() return finalPop[:]
def simWithDrug_Delay_0(numViruses, maxPop, maxBirthProb, clearProb, resistances, mutProb, numTrials): """ return a list containing the final population of each trail viruses, a list of 100 ResistantVirus instances maxPop, maximum sustainable virus population = 1000 Each ResistantVirus instance in the viruses list should be initialized with the following parameters: maxBirthProb, maximum reproduction probability for a virus particle = 0.1 clearProb, maximum clearance probability for a virus particle = 0.05 resistances, The virus's genetic resistance to drugs in the experiment = {'guttagonol': False} mutProb, probability of a mutation in a virus particle's offspring = 0.005 """ finalPop = [] # a list containing 150 elements; the i-th element #records the i-th trial's final population of viruses for i in range(numTrials): finalPop.append(0.0) virList = [] # a list which contains all the ResistantVirus for num in range(numViruses): a_virus = ResistantVirus(maxBirthProb, clearProb, resistances, mutProb) virList.append(a_virus) for trial in range(numTrials): thePoorGuy = TreatedPatient(virList, maxPop) thePoorGuy.addPrescription('guttagonol') #add guttagonol for i in range(150): thePoorGuy.update() finalPop[trial] += thePoorGuy.getTotalPop() return finalPop[:]
def simulationWithDrug(numViruses, maxPop, maxBirthProb, clearProb, resistances, mutProb, numTrials): """ Runs simulations and plots graphs for problem 5. For each of numTrials trials, instantiates a patient, runs a simulation for 150 timesteps, adds guttagonol, and runs the simulation for an additional 150 timesteps. At the end plots the average virus population size (for both the total virus population and the guttagonol-resistant virus population) as a function of time. numViruses: number of ResistantVirus to create for patient (an integer) maxPop: maximum virus population for patient (an integer) maxBirthProb: Maximum reproduction probability (a float between 0-1) clearProb: maximum clearance probability (a float between 0-1) resistances: a dictionary of drugs that each ResistantVirus is resistant to (e.g., {'guttagonol': False}) mutProb: mutation probability for each ResistantVirus particle (a float between 0-1). numTrials: number of simulation runs to execute (an integer) """ popPerStep = [] # a list containing 300 elements; the i-th element ResPerStep = [ ] #records the i-th step's virus and viruses with resistance population for i in range(300): popPerStep.append(0.0) for i in range(300): ResPerStep.append(0.0) virList = [] # a list which contains all the ResistantVirus for num in range(numViruses): a_virus = ResistantVirus(maxBirthProb, clearProb, resistances, mutProb) virList.append(a_virus) for trial in range(numTrials): thePoorGuy = TreatedPatient(virList, maxPop) for i in range(150): thePoorGuy.update() popPerStep[i] += thePoorGuy.getTotalPop() ResPerStep[i] += thePoorGuy.getResistPop(['guttagonol']) thePoorGuy.addPrescription('guttagonol') #add guttagonol for j in range(150, 300): thePoorGuy.update() popPerStep[j] += thePoorGuy.getTotalPop() ResPerStep[j] += thePoorGuy.getResistPop(['guttagonol']) for i in range(300): popPerStep[i] = float(popPerStep[i]) / numTrials ResPerStep[i] = float(ResPerStep[i]) / numTrials pylab.plot(popPerStep, 'ro', label='total viruses') pylab.plot(ResPerStep, 'bo', label='viruses with resistance to guttagonol') pylab.xlabel('Time Steps') pylab.ylabel('Average Viruses Population') pylab.title('Average Viruses Population over ' + str(numTrials) + ' trials') pylab.legend(loc='best') pylab.show()