Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加了治愈功能 #50

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# VirusBroadcast
一个基于java的模拟仿真程序,由于启动的时候时间仓促,数据不足,所以模型和推演过程过于简单,如果有好的想法或者能提供相关数据支持的朋友请提issues。
如果您也是一名java程序员,可以直接修改并给我提交pr,我之前已经启动每日疫情数据的每日抓取工作,希望在疫情结束后有机会通过这些精准的的数据做一个复盘。

2020.2.6:
病毒变异过程是一个不断适应的过程,可以尝试简单的DNN对病毒进行建模,已经开始着手实施。
# Virus Broadcast
本项目fork自一位优秀的Java工程师,同时也是一位B站UP主。
本分支修改如下:
* 修正原项目中入院隔离人员不再死亡的bug
* 增加治愈的功能
># VirusBroadcast
>一个基于java的模拟仿真程序,由于启动的时候时间仓促,数据不足,所以模型和推演过程过于简单,如果有好的想法或者能提供相关数据支持的朋友请提issues。
>如果您也是一名java程序员,可以直接修改并给我提交pr,我之前已经启动每日疫情数据的每日抓取工作,希望在疫情结束后有机会通过这些精准的的数据做一个复盘。
>
>2020.2.6:
>病毒变异过程是一个不断适应的过程,可以尝试简单的DNN对病毒进行建模,已经开始着手实施。
6 changes: 4 additions & 2 deletions src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
*/
public class Constants {

public static int ORIGINAL_COUNT = 50;//初始感染数量
public static int ORIGINAL_COUNT = 25;//初始感染数量
public static float BROAD_RATE = 0.8f;//传播率
public static float SHADOW_TIME = 140;//潜伏时间,14天为140
public static int HOSPITAL_RECEIVE_TIME = 10;//医院收治响应时间
Expand All @@ -21,9 +21,11 @@ public class Constants {
*/
public static float u = 0.99f;
public static int CITY_PERSON_SIZE = 5000;//城市总人口数量
public static float FATALITY_RATE = 0.50f;//fatality_rate病死率,根据2月6日数据估算(病死数/确诊数)为0.02
public static float FATALITY_RATE = 0.05f;//fatality_rate病死率,根据2月6日数据估算(病死数/确诊数)为0.02
public static int DIE_TIME = 100;//死亡时间均值,30天,从发病(确诊)时开始计时
public static double DIE_VARIANCE = 1;//死亡时间方差
public static int CURE_TIME = 150;//治愈时间均值
public static double CURE_VARIANCE = 20;//治愈时间方差
/**
* 城市大小即窗口边界,限制不允许出城
*/
Expand Down
10 changes: 8 additions & 2 deletions src/MyPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ public void paint(Graphics g) {
g.setColor(new Color(0x000000));
break;
}
case Person.State.CURED: {
//治愈患者
g.setColor(new Color(0x00ff00));
}
}
person.update();//对各种状态的市民进行不同的处理
g.fillOval(person.getX(), person.getY(), 3, 3);
Expand Down Expand Up @@ -95,10 +99,12 @@ public void paint(Graphics g) {
- PersonPool.getInstance().getPeopleSize(Person.State.FREEZE);

g.drawString("急需病床:" + (needBeds > 0 ? needBeds : 0), captionStartOffsetX, captionStartOffsetY + 6 * captionSize);
g.setColor(new Color(0xccbbcc));
g.setColor(new Color(0x000000));
g.drawString("病死人数:" + PersonPool.getInstance().getPeopleSize(Person.State.DEATH), captionStartOffsetX, captionStartOffsetY + 7 * captionSize);
g.setColor(new Color(0x00ff00));
g.drawString("治愈人数:" + PersonPool.getInstance().getPeopleSize(Person.State.CURED), captionStartOffsetX, captionStartOffsetY + 8 * captionSize);
g.setColor(new Color(0xffffff));
g.drawString("世界时间(天):" + (int) (worldTime / 10.0), captionStartOffsetX, captionStartOffsetY + 8 * captionSize);
g.drawString("世界时间(天):" + (int) (worldTime / 10.0), captionStartOffsetX, captionStartOffsetY + 9 * captionSize);

}

Expand Down
22 changes: 19 additions & 3 deletions src/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public interface State {

//已治愈出院的人转为NORMAL即可,否则会与作者通过数值大小判断状态的代码冲突
int DEATH = FREEZE + 1;//病死者
//int CURED = DEATH + 1;//治愈数量用于计算治愈出院后归还床位数量,该状态是否存续待定
int CURED = DEATH + 1;//治愈数量用于计算治愈出院后归还床位数量,该状态是否存续待定
}

public Person(City city, int x, int y) {
Expand Down Expand Up @@ -86,6 +86,7 @@ public void setState(int state) {
int infectedTime = 0;//感染时刻
int confirmedTime = 0;//确诊时刻
int dieMoment = 0;//死亡时刻,为0代表未确定,-1代表不会病死
int cureMoment = 0;//治愈时刻


public boolean isInfected() {
Expand Down Expand Up @@ -195,7 +196,7 @@ private void action() {
public void update() {
//@TODO找时间改为状态机

if (state == State.FREEZE || state == State.DEATH) {
if (state == State.DEATH) {
return;//如果已经隔离或者死亡了,就不需要处理了
}

Expand All @@ -213,8 +214,20 @@ public void update() {

}
}
//TODO 暂时缺失治愈出院市民的处理。需要确定一个变量用于治愈时长。由于案例太少,暂不加入。
//治愈
if (state == State.FREEZE && cureMoment == 0) {
int cureTime = (int) MathUtil.stdGaussian(Constants.CURE_VARIANCE, Constants.CURE_TIME);
if (cureTime > dieMoment - MyPanel.worldTime && dieMoment > 0) {
cureMoment = -1; //来不及治好,死亡时间在治愈时间之前
} else {
cureMoment = MyPanel.worldTime + cureTime;
}
}

if (state == State.FREEZE && cureMoment > 0 && MyPanel.worldTime >= cureMoment) {
state = State.CURED;
Hospital.getInstance().returnBed(useBed);
}

if (state == State.CONFIRMED
&& MyPanel.worldTime - confirmedTime >= Constants.HOSPITAL_RECEIVE_TIME) {
Expand All @@ -237,6 +250,9 @@ public void update() {
//处理病死者
if ((state == State.CONFIRMED || state == State.FREEZE) && MyPanel.worldTime >= dieMoment && dieMoment > 0) {
state = State.DEATH;//患者死亡
// 随机丢弃尸体,没有火葬场和墓地,暂时这样处理
super.setX((int) MathUtil.stdGaussian(100, city.getCenterX()));
super.setY((int) MathUtil.stdGaussian(100, city.getCenterY()));
Hospital.getInstance().returnBed(useBed);//归还床位
}

Expand Down