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

采用动态的流动意向平均值 #63

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions src/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ public class Constants {
* <p>
* -0.99 人群流动最慢速率,甚至完全控制疫情传播
* 0.99为人群流动最快速率, 可导致全城感染
* 流动意向平均值随感染(包括死亡和潜伏和隔离)人数占比的函数,可以使用双曲正切函数拟合得到,函数解析式为
* 使用f(x)将感染比例值域从[0, 1]转化为[-1 , 1], f(x) = -2 * (感染人数+死亡人数+隔离人数+潜伏人数)/城市总人数 -1,
* 简写为f(x) = -2x + 1
* 意向流动平均值g(x) = tanh(2 * f(x)) 简写为 y = tanh(3x)
* g(x)函数的定义域为[0, 1], 值域为(-1,1)
*/
public static float u = 0.99f;
public static int CITY_PERSON_SIZE = 5000;//城市总人口数量
Expand Down
4 changes: 3 additions & 1 deletion src/MyPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,10 @@ public void paint(Graphics g) {
g.drawString("急需病床:" + (needBeds > 0 ? needBeds : 0), captionStartOffsetX, captionStartOffsetY + 6 * captionSize);
g.setColor(new Color(0xccbbcc));
g.drawString("病死人数:" + PersonPool.getInstance().getPeopleSize(Person.State.DEATH), captionStartOffsetX, captionStartOffsetY + 7 * captionSize);
g.setColor(new Color(0xffffff));
g.setColor(new Color(0xdd00cc));
g.drawString("世界时间(天):" + (int) (worldTime / 10.0), captionStartOffsetX, captionStartOffsetY + 8 * captionSize);
g.setColor(new Color(0xffffff));
g.drawString("意向流动率:" + String.format("%.2f", Constants.u), captionStartOffsetX, captionStartOffsetY + 9 * captionSize);

}

Expand Down
7 changes: 7 additions & 0 deletions src/Person.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ public Person(City city, int x, int y) {
* @return
*/
public boolean wantMove() {
// 计算感染人数占比
double nfectedRate = (double) (PersonPool.getInstance().getPeopleSize(State.SHADOW)
+ PersonPool.getInstance().getPeopleSize(State.CONFIRMED)
+ PersonPool.getInstance().getPeopleSize(State.DEATH)
+ PersonPool.getInstance().getPeopleSize(Person.State.FREEZE)) / Constants.CITY_PERSON_SIZE;
// 使用由双曲正切函数缩两倍变化而来的函数,拟合流动意向平均值随感染率的变换
Constants.u = (float) Math.tanh(2 * ((-2 * nfectedRate) + 1));
return MathUtil.stdGaussian(sig, Constants.u) > 0;
}

Expand Down