I also wrote a spread of the epidemic simulation program

Written in .NET spread of the epidemic simulation program

A while ago to see someone make a "spread of the epidemic simulation program" is used Javato do. Which according to many practical situations, such as residents move will, medical capabilities, the ability to spread the virus to simulate the development of the epidemic. After reading it, I secretly amazed, especially combined with some video and photos, is really very good.

Since there is a need, 2月6号that night I went ahead and decided, after two nights of thinking and coding, has an initial effect ...... operating results as follows:

This effect can be so interpreted, if not any control, the epidemic will soon spread to the entire city, only the 8:1000bed of the city, will soon be out of control, one year after the operation results are as follows (very bitter):

Parameters and use

There are many parameters of the actual code may be operable:

static double MoveWilling = 0.90f; // 移动意愿,0-1
static bool WearMask = false; // 是否戴口罩
static int HospitalBeds = 40; // 床位数

const float InffectRate = 0.8f; // 靠得够近时,被携带者感染的机率
const float SecondsPerDay = 0.3f; // 模拟器的秒数,对应真实一天
const float MovingDistancePerDay = 10.0f; // 每天移动距离
const int InitialInfectorCount = 5; // 最初感染者数
const double DeathRate = 0.021; // 死亡率

// 要靠多近,才会触发感染验证
static float SafeDistance() => WearMask ? 1.5f : 3.5f;

// 住院治愈时间,最短5天,最长12.75天,平均约7天
static float GenerateCureDays() => random.NextFloat(5, 12.75f);
// 潜伏期,1-14天
static float GenerateShadowDays() => random.Next(1, 14);
// 发病后,就医时间,0-3天
static float GenerateToHospitalDays() => random.Next(0, 3);

Because too many parameters, it is difficult to run when all make adjustments, I chose whether to wear a mask , moving the will , number of hospital beds as a parameter, as follows:

protected override void OnKeyPress(KeyPressEventArgs e)
{
    switch (e.KeyChar)
    {
        case '1': MoveWilling = 0.10f; break;
        case '2': MoveWilling = 0.50f; break;
        case '3': MoveWilling = 0.90f; break;
        case 'M': WearMask = !WearMask; break;
        case 'A': HospitalBeds += 40; break;
        case 'D': HospitalBeds -= 40; break;
        case 'R':
            {
                if (MessageBox.Show("要重来吗?", "确认", MessageBoxButtons.YesNo) == DialogResult.Yes)
                {
                    City = City.Create();
                }
                break;
            }
    }
}

Among them, press the number keys 1, 2, 3you can specify a different mobile willingness , which 1represents most residents do not want to go out, 3express our willingness to press Mcan control whether residents to wear masks, according to Ayou can add the number of patients the hospital can accept.

Some demo

Super Multi beds

Here I will tune into bed 240one (ratio 48: 1000):

static int HospitalBeds = 240; // 床位数

May also increase the bed operation, the keyboard Acan (do not change the code), the following operating results:
www.wityx.com

After the visible bed increases, the mortality rate will be reduced, the number of cure greatly improved, but still unable to control the development of the epidemic.

"Ideal" 1. Without incubation period

It can be configured:

// 0潜伏期
static float GenerateShadowDays() => 0;

Operating results are as follows:
www.wityx.com

可见就算潜伏期为0,由于没有及时就医,疫情仍会失去控制。

“理想”情况2·没有潜伏期、且立刻隔离就医

像那个Java版中,会先介绍一个“理想”情况,即感染即发病,发病即就就医。此种模型的参数,可以这样配置:

// 0潜伏期
static float GenerateShadowDays() => 0;
// 发病后,立即就医。
static float GenerateToHospitalDays() => 0;

在这种情况下,运行效果如下:
www.wityx.com

可见,由最初的5人,最终只感染了6人,理想情况下局势很快就被控制。当然这种情况是不存在的。

戴口罩出门

假如居民都戴口罩出门,可以用如下配置(也可以运行时按下M键):

static bool WearMask = true; // 一定戴口罩

运行效果如下:
www.wityx.com

坚持了107天,疫情发展速度大大降低,但由于医疗资源的匮乏,死亡率仍然居高不下,最终仍会失去控制。

居民呆在家中不出门,且戴口罩

配置如下:

static bool WearMask = true; // 一定戴口罩
static double MoveWilling = 0.10f; // 每天只有10%的人愿意出门

运行效果如下:
www.wityx.com

病毒在最初的5人身上,只感染了2人。效率可谓惊人。

模拟现实模型

我想贴近现实,模拟一些现实情况,然后看看效果如何,我的脚本如下:

  1. 20天,不作任何控制
  2. 20天,全民戴口罩,移动意愿降低至50%,床位增加40个(模拟进入重大突发公共卫生事件Ⅰ级响应
  3. 25天,移动愿意降低至10%,床位增加80个(模拟火神山医院)
  4. 30天,床位再增加80个,共240个(模拟雷神山医院)

为了尽可能短地截取gif,我将时间缩短了,真实时间可能会和这个比例为1:2(也就是相当于前40天不作任何控制),脚本如下:

void StepDay()
{
    if (day < 20)
    {
        WearMask = false;
        MoveWilling = 0.9;
        HospitalBeds = 40;
    }
    if (day >= 20)
    {
        WearMask = true;
        MoveWilling = 0.5;
        HospitalBeds = 80;
    }
    if (day >= 25)
    {
        MoveWilling = 0.1;
        HospitalBeds = 160;
    }
    if (day >= 30)
    {
        HospitalBeds = 240;
    }

    // 其它代码
}

运行效果如下:
www.wityx.com

可见这真是与病毒的一部史诗级斗争。

20天,没有任何控制,病毒疯狂肆虐,前期只花了9天,就把医院给挤满了;

20之后,居民带上口罩,传播进度迅速下降,但由于潜伏期较长,发病人数仍然持续上升;

30天之后,由于5天前床位(医护资源)的跟进,发病人数增速降低;

35天后,发病人数开始下降;

68天后,除了医院中的病人,城市中已经没有病人;

78天,已经没有被病毒感染的人了。

总结

所有这些代码,我都上传到了我的博客数据网站,各们可以下载代码,通过LINQPad 6直接模拟运行,或者拷到Visual Studio中亦可。各位也可以或者提出您的想法,Github链接如下:
https://github.com/sdcb/blog-data/tree/master/2020/20200207-2019-ncov-simulate

写完这个东西,给我最大的感受就是震撼,模拟起来就是一些数据而已,但背后是千千万万有血有肉的病人和医务工作者,向那些伟大的“逆行者”们致敬!

从上面的数据也可以看出,任何单项指标做好,都是不能完全阻止疫情的。我们要相互信任,做好自己。我们能做的有:尽可能呆在家,别出门,就是对国家最好的贡献;出门一定要戴口罩,这样可以明显降低感染率。

最后,在新的一年里,祝大家阖家欢乐,鼠年大吉!

Published 132 original articles · won praise 15 · views 10000 +

Guess you like

Origin blog.csdn.net/ling_76539446/article/details/104236999
Recommended