嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 2 元微信扫码支付:2 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
疫情传播中存在各种随机性;简易模拟程序中,我们采用均匀分布的随机数来模拟这种随机性
void Population::spreading()
{
srand(time(NULL));
vector<int> sick(0);
for(int i=0;i<people;i )
{
if(pops[i].get_status()>0)
{
for(int trans=0;trans<6;trans )
{
float bad_luck = (float)rand()/(float)RAND_MAX;
if(bad_luck < prob)
{
int random = rand()%people;
while(i==random)
{
random = rand()%people;
}
sick.push_back(random);
}
}
}
}
for(int k=0;k<sick.size();k )
{
if(pops[sick[k]].get_status()==0)
{
pops[sick[k]].infect(5);
}
}
};
void Population::innoculation(float per)
{
srand(time(NULL));
int count =0;
int per_innoculated = ceil(people*per);
while(count < per_innoculated)
{
int random = floor(people*(float)rand()/(float)RAND_MAX);
pops[random] = -2;
count =1;
}
};