Virus Epidemic Simulation ----- -------- ---------- Preface ------- You have been asked to simulate an ecology in which a viral disease exists. This virus is not very communicable: it does not pass from one host organism to another easily. The virus also kills its host organism very slowly, and it is hoped your simulation will shed some light on why this is so. Problem ------- The world you are simulating is an N x N matrix of geographical niche's. Each niche can hold zero or one organism. The organism, if it exists, can be healthy, infected, sick, or dying. The only illness is the virus being studied. Thus a niche can be in one of 5 states; NONE, HEALTHY, INFECTED, SICK, or DYING. Here NONE means there is no organism, and the other states indicate the state of one organism. The state of the world at any time is the probability of each niche being in each state: i.e. an N x N x 5 array of probabilities. In the simulated world time advances in cycles. For each cycle and for each niche there are probabilities of the niche transiting from one state to another. For niche (i,j) (the (i,j)'th cell in the world matrix) these are: Transition Probability NONE ---> HEALTHY birth(i,j) NONE ---> NONE 1 - birth(i,j) HEALTHY ---> INFECTED infect(i,j) HEALTHY ---> HEALTHY 1 - infect(i,j) INFECTED ---> SICK virulence INFECTED ---> INFECTED 1 - virulence SICK ---> DYING virulence SICK ---> SICK 1 - virulence DYING ---> NONE 1 DYING ---> DYING 0 where `virulence' is a simulation parameter and birth(i,j) and infect(i,j) are computed for the (i,j)'th niche and the particular cycle as described below. If the virulence is larger, a non-healthy organism dies faster. The above means that if pNONE, pHEALTHY, pINFECTED, pSICK, and pDYING are the probabilities of a niche being in the NONE, HEALTHY, INFECTED, SICK, or DYING states, then the action of a time cycle is: pNONE = pDYING + pNONE * ( 1 - birth(i,j) ) pHEALTHY = pNONE * birth(i,j) + pHEALTHY * ( 1 - infect(i,j) ) pINFECTED = pHEALTHY * infect(i,j) + pINFECTED * ( 1 - virulence ) pSICK = pINFECTED * virulence + pSICK * ( 1 - virulence ) pDYING = pSICK * virulence where the right sides of all these equations are calculated before any left side probabilities are reset. Initially, before the first time cycle, all niches have HEALTHY organisms except one corner, which has an INFECTED organism. This means all probabilities are zero except for pHEALTHY = 1.0 in all niches but one corner where pINFECTED = 1.0 instead. Note that the sum of the probabilities for the 5 states of any niche is always 1. The probabilities flow like a fluid around the 5 states of a niche. birth(i,j) and infect(i,j) are computed at the beginning of each time cycle as birth(i,j) = birthrate * {expected number of organisms in neighbors of niche (i,j)} infect(i,j) = communicability * {expected number of SICK organisms in neighbors of niche (i,j)} where birthrate and (disease) communicability are simulation parameters. The later may be made smaller to indicate that the viral disease spreads more slowly. A niche has up to 8 neighbors, in the same row, the same column, or the same diagonal as the niche. Corner niches have only 3 neighbors, edge niches have only 5, while interior niches have 8. The probability that a niche has an organism is just 1 - pNONE The probability that a niche has a SICK organism is just pSICK. Adding up the probabilities that several niches have an organism gets the expected number of organisms in the niches: so if their are 8 neighbors, the 8 values 1 - pNONE are added to get get the expected number of neighbor organisms. Similarly if there are 5 neighbors the 5 values of pSICK are added to get the expected number of SICK neighbor organisms. Input ----- The input consists of input for a sequence of runs. For each run the input is the following numbers: the number of cycles in the simulation the number of cycles between printouts the world matrix dimension size, N above (2 to 30) the virulence parameter (0 to 1.0) the communicability parameter (0 to 0.125) the birthrate parameter (0 to 0.125) The numbers are separated by whitespace, where whitespace is any combination of single space and newline characters. The numbers for one run need NOT all appear on the same line. Input ends with an end of file. Output ------ For each run, the first output line has the form: RUN #: where # is the run number. Runs are numbered 1, 2, 3, 4, ... . The remainder of a run output is lines describing the state of the simulation. Each line contains three numbers, as in the example: 40 1.127176 24.942356 The first number, an integer right adjusted in 5 columns, is the number of the time cycle just ended. The second number, right adjusted in 15 columns with exactly 6 decimal places, is the expected number of non-healthy organisms. This is just the sum of 1 - pNONE - pHEALTHY over all niches. This number goes to zero if the virus fails to survive in the geographical area being simulated. The third number, also right adjusted in 15 columns with exactly 6 decimal places, is the expected number of organisms. This is just the sum of 1 - pNONE over all niches. It goes to zero if the organism fails to survive. The spacing of the output must be exactly as described. The word RUN must start in the first column and be followed by exactly one space. There must be no extra spaces at the end of any line. If the number of cycles between printouts is S, then there is an output line at the end of cycles S, 2S, 3S, and so forth. Example Input ------- ----- 400 80 5 0.01 0.01 0.001 2000 500 5 0.05 0.01 0.001 2000 500 5 0.07 0.01 0.001 Example Output ------- ------ RUN 1: 80 1.437385 24.804468 160 2.659035 24.371091 240 5.187084 23.636264 320 9.099361 22.325362 400 12.568633 20.216380 RUN 2: 500 1.077656 20.448802 1000 0.815975 20.556315 1500 0.871784 20.641505 2000 0.861981 20.604059 RUN 3: 500 0.043551 24.231093 1000 0.008989 24.818821 1500 0.002187 24.956578 2000 0.000551 24.989243 File: virus.txt Author: Bob Walton Date: Thu Sep 19 03:16:08 EDT 2002 The authors have placed this file in the public domain; they make no warranty and accept no liability for this file. RCS Info (may not be true date or author): $Author: hc3 $ $Date: 2002/09/19 08:13:52 $ $RCSfile: virus.txt,v $ $Revision: 1.8 $