Ejemplo n.º 1
0
        public static void doIteration(GridUnit grid, double deltaT, float k, float deathRate, float b)
        {
            /*
             * S = S(t)	is the number of susceptible individuals,
             * I = I(t)	is the number of infected individuals, and
             * R = R(t)	is the number of recovered individuals.
             * s(t) = S(t)/N,	the susceptible fraction of the population,
             * i(t) = I(t)/N,	the infected fraction of the population, and
             * r(t) = R(t)/N,	the recovered fraction of the population.
             * S' = -b s(t)I(t)
             * s' = -b s(t)i(t)
             * r' = k i(t)
             * s' + i' + r' = 0
             * i' = b s(t) i(t) - k i(t)
             */


            // calculate the rate of change for this iteration
            double sPrime = -(b) * grid.s * grid.i;
            double iPrime = b * grid.s * grid.i - (k * grid.i);
            double rPrime = k * grid.i;

            // apply the change to the population
            grid.s         += (sPrime * deltaT);
            grid.i         += (iPrime * deltaT);
            totalInfected  += Convert.ToInt64(iPrime * grid.N);
            grid.r         += (rPrime * deltaT);
            totalRecovered += Convert.ToInt64(rPrime * grid.N);

            // calculate losses
            long theDead = Convert.ToInt64(rPrime * grid.N * deltaT * deathRate);

            grid.D    += theDead;
            totalDead += theDead;
            grid.N    -= theDead; // remove losses from total population, needs testing.]

            if (grid.I <= 0 || grid.N <= 0 || grid.R == grid.N)
            {
                activeGridUnits.Remove(grid);
            }
        }
Ejemplo n.º 2
0
        public void parseCSV(string input, string output, GridUnit[,] array, List<GridUnit> airportGridUnits, List<GridUnit> activeGridUnits)
        {
            using (StreamWriter outputFile = new StreamWriter(output))
            {
                using (StreamReader inputFile = new StreamReader(input))
                {

                    string[] lineArr;
                    string line;
                    string writeLine = String.Empty;
                    int lineCounter = 850;
                    bool oneAdded = true;

                    while ((line = inputFile.ReadLine()) != null && lineCounter > topLattitude)
                    {
                        lineCounter--; // remove the top data
                    }
                    while ((line = inputFile.ReadLine()) != null && lineCounter > bottomLattitude)
                    {
                        writeLine = String.Empty;
                        lineArr = line.Split(',');

                        for (int i = 0; i < lineArr.Length; i++)
                        {

                            if (i < westernLongitude)
                            {
                                // do nothing
                            }
                            else if (i > easternLongitude - 1)
                            {
                                break;
                            }
                            else
                            {
                                writeLine += lineArr[i] + ",";

                                if (lineArr[i] != "99999.0" && lineArr[i] != "1.0369266")
                                {
                                    array[i - westernLongitude, lineCounter - bottomLattitude - 1] = new GridUnit(Convert.ToInt64(Convert.ToSingle(lineArr[i]) * 100), 0, 0, Convert.ToInt64(Convert.ToSingle(lineArr[i]) * 100), i - westernLongitude, lineCounter - bottomLattitude - 1);
                                    if (array[i - westernLongitude, lineCounter - bottomLattitude - 1].N > 300000)
                                    {
                                        if (oneAdded)
                                        {
                                            //activeGridUnits.Add(array[i - westernLongitude, lineCounter - bottomLattitude - 1]);
                                            //activeGridUnits.ElementAt(0).i = .01;
                                            oneAdded = false;
                                        }
                                        airportGridUnits.Add(array[i - westernLongitude, lineCounter - bottomLattitude - 1]);
                                    }
                                }
                                else
                                {
                                    array[i - westernLongitude, lineCounter - bottomLattitude - 1] = new GridUnit(0, 0, 0, 0, i - westernLongitude, lineCounter - bottomLattitude - 1);

                                }
                            }

                        }
                        outputFile.WriteLine(writeLine);
                        lineCounter--;
                    }
                }
            }
        }
Ejemplo n.º 3
0
        public void parseCSV(string input, string output, GridUnit[,] array, List <GridUnit> airportGridUnits, List <GridUnit> activeGridUnits)
        {
            using (StreamWriter outputFile = new StreamWriter(output))
            {
                using (StreamReader inputFile = new StreamReader(input))
                {
                    string[] lineArr;
                    string   line;
                    string   writeLine   = String.Empty;
                    int      lineCounter = 850;
                    bool     oneAdded    = true;

                    while ((line = inputFile.ReadLine()) != null && lineCounter > topLattitude)
                    {
                        lineCounter--; // remove the top data
                    }
                    while ((line = inputFile.ReadLine()) != null && lineCounter > bottomLattitude)
                    {
                        writeLine = String.Empty;
                        lineArr   = line.Split(',');

                        for (int i = 0; i < lineArr.Length; i++)
                        {
                            if (i < westernLongitude)
                            {
                                // do nothing
                            }
                            else if (i > easternLongitude - 1)
                            {
                                break;
                            }
                            else
                            {
                                writeLine += lineArr[i] + ",";

                                if (lineArr[i] != "99999.0" && lineArr[i] != "1.0369266")
                                {
                                    array[i - westernLongitude, lineCounter - bottomLattitude - 1] = new GridUnit(Convert.ToInt64(Convert.ToSingle(lineArr[i]) * 100), 0, 0, Convert.ToInt64(Convert.ToSingle(lineArr[i]) * 100), i - westernLongitude, lineCounter - bottomLattitude - 1);
                                    if (array[i - westernLongitude, lineCounter - bottomLattitude - 1].N > 300000)
                                    {
                                        if (oneAdded)
                                        {
                                            //activeGridUnits.Add(array[i - westernLongitude, lineCounter - bottomLattitude - 1]);
                                            //activeGridUnits.ElementAt(0).i = .01;
                                            oneAdded = false;
                                        }
                                        airportGridUnits.Add(array[i - westernLongitude, lineCounter - bottomLattitude - 1]);
                                    }
                                }
                                else
                                {
                                    array[i - westernLongitude, lineCounter - bottomLattitude - 1] = new GridUnit(0, 0, 0, 0, i - westernLongitude, lineCounter - bottomLattitude - 1);
                                }
                            }
                        }
                        outputFile.WriteLine(writeLine);
                        lineCounter--;
                    }
                }
            }
        }
Ejemplo n.º 4
0
        public static void calculateSpreadToNeighbors(GridUnit centerGrid, float borderTravelRate, float airportTravelRate) // spreads infection out, one way, from each infected grid
        {
            long infectedOut    = Convert.ToInt64(centerGrid.i * borderTravelRate * centerGrid.N);
            long recoveredOut   = Convert.ToInt64(centerGrid.r * borderTravelRate * centerGrid.N);
            long susceptableOut = Convert.ToInt64(centerGrid.s * borderTravelRate * centerGrid.N);

            // readjust populations due to people leaving

            // calculate each direction
            if (!(centerGrid.yCoord <= 0)) // go down
            {
                GridUnit target = array[centerGrid.xCoord, centerGrid.yCoord - 1];
                if (target.N > 0)
                {
                    target.N += infectedOut + recoveredOut + susceptableOut;
                    target.i += Convert.ToSingle(infectedOut) / target.N;
                    target.r += Convert.ToSingle(recoveredOut) / target.N;
                    target.s += Convert.ToSingle(susceptableOut) / target.N;

                    centerGrid.N -= infectedOut + recoveredOut + susceptableOut;
                    centerGrid.i -= Convert.ToSingle(infectedOut) / centerGrid.N;
                    centerGrid.r -= Convert.ToSingle(recoveredOut) / centerGrid.N;
                    centerGrid.s -= Convert.ToSingle(susceptableOut) / centerGrid.N;

                    if (target.i > 0 && (!activeGridUnits.Contains(target)))
                    {
                        activeGridUnits.Add(target);
                    }
                }
            }
            if (!(centerGrid.yCoord >= gridYLength - 1)) // go up
            {
                GridUnit target = array[centerGrid.xCoord, centerGrid.yCoord + 1];
                if (target.N > 0)
                {
                    target.N += infectedOut + recoveredOut + susceptableOut;
                    target.i += Convert.ToSingle(infectedOut) / target.N;
                    target.r += Convert.ToSingle(recoveredOut) / target.N;
                    target.s += Convert.ToSingle(susceptableOut) / target.N;

                    centerGrid.N -= infectedOut + recoveredOut + susceptableOut;
                    centerGrid.i -= Convert.ToSingle(infectedOut) / centerGrid.N;
                    centerGrid.r -= Convert.ToSingle(recoveredOut) / centerGrid.N;
                    centerGrid.s -= Convert.ToSingle(susceptableOut) / centerGrid.N;

                    if (target.i > 0 && (!activeGridUnits.Contains(target)))
                    {
                        activeGridUnits.Add(target);
                    }
                }
            }
            if (!(centerGrid.xCoord <= 0)) // go left
            {
                GridUnit target = array[centerGrid.xCoord - 1, centerGrid.yCoord];
                if (target.N > 0)
                {
                    target.N += infectedOut + recoveredOut + susceptableOut;
                    target.i += Convert.ToSingle(infectedOut) / target.N;
                    target.r += Convert.ToSingle(recoveredOut) / target.N;
                    target.s += Convert.ToSingle(susceptableOut) / target.N;

                    centerGrid.N -= infectedOut + recoveredOut + susceptableOut;
                    centerGrid.i -= Convert.ToSingle(infectedOut) / centerGrid.N;
                    centerGrid.r -= Convert.ToSingle(recoveredOut) / centerGrid.N;
                    centerGrid.s -= Convert.ToSingle(susceptableOut) / centerGrid.N;

                    if (target.i > 0 && (!activeGridUnits.Contains(target)))
                    {
                        activeGridUnits.Add(target);
                    }
                }
            }
            if (!(centerGrid.xCoord >= gridXLength - 1)) // go right
            {
                GridUnit target = array[centerGrid.xCoord + 1, centerGrid.yCoord];
                if (target.N > 0)
                {
                    target.N += infectedOut + recoveredOut + susceptableOut;
                    target.i += Convert.ToSingle(infectedOut) / target.N;
                    target.r += Convert.ToSingle(recoveredOut) / target.N;
                    target.s += Convert.ToSingle(susceptableOut) / target.N;

                    centerGrid.N -= infectedOut + recoveredOut + susceptableOut;
                    centerGrid.i -= Convert.ToSingle(infectedOut) / centerGrid.N;
                    centerGrid.r -= Convert.ToSingle(recoveredOut) / centerGrid.N;
                    centerGrid.s -= Convert.ToSingle(susceptableOut) / centerGrid.N;

                    if (target.i > 0 && (!activeGridUnits.Contains(target)))
                    {
                        activeGridUnits.Add(target);
                    }
                }
            }
            if (airportGridUnits.Contains(centerGrid))
            {
                foreach (GridUnit otherAirport in airportGridUnits)
                {
                    if (otherAirport != centerGrid)
                    {
                        otherAirport.N += Convert.ToInt64((infectedOut + recoveredOut + susceptableOut) * airportTravelRate);
                        otherAirport.i += Convert.ToSingle(infectedOut * airportTravelRate) / otherAirport.N;
                        otherAirport.r += Convert.ToSingle(recoveredOut * airportTravelRate) / otherAirport.N;
                        otherAirport.s += Convert.ToSingle(susceptableOut * airportTravelRate) / otherAirport.N;

                        if (otherAirport.i > 0 && (!activeGridUnits.Contains(otherAirport)))
                        {
                            activeGridUnits.Add(otherAirport);
                        }

                        centerGrid.N -= Convert.ToInt64((infectedOut + recoveredOut + susceptableOut) * airportTravelRate);
                        centerGrid.i -= Convert.ToSingle(infectedOut * airportTravelRate) / centerGrid.N;
                        centerGrid.r -= Convert.ToSingle(recoveredOut * airportTravelRate) / centerGrid.N;
                        centerGrid.s -= Convert.ToSingle(susceptableOut * airportTravelRate) / centerGrid.N;
                    }
                }
            }
        }