Step3: 整合GIS数据

现在,我们在之前简单的传播模型基础上,结合交通仿真的知识,载入GIS数据并使代理人在不同建筑之间沿着路网移动,完成一个城市环境的病毒传播模拟。

载入GIS数据并初始化

global {
    //载入GIS数据
    file roads_shapefile <- file("../includes/road.shp");
    file buildings_shapefile <- file("../includes/building.shp");
    //将全局代理形状设置为包括所有道路的矩形
    geometry shape <- envelope(roads_shapefile); 
    ...
    init{
    //从GIS数据创建建筑和道路
    create road from: roads_shapefile;
    create building from: buildings_shapefile;
    //代理人的初始位置设置为随机建筑的任意位置
    create people number:nb_people {
            speed <- agent_speed;
        location <- any_location_in(one_of(building));
    }
    }
}

接下来,创建道路和建筑族。

然后在实验设置中设置显示建筑与道路族。

编写人群的移动行为

我们将人群的移动简化为人群在接近9点、12点、18点时为移动高峰期,其他时间呆在建筑里。这里我们引入两个变量: staying_counter staying_coeff

  • staying_counter当代理人达到建筑时开始计数,随着时间递增,开始移动时恢复为0。

  • staying_coeff 接近9点、12点、18点时数值最小,在三个时间段之间递增。

  • staying_counter/staying_coeff: 代理人开始移动的概率,随着代理人在建筑中的停留时间递增,并在9点、12点、18点时概率最大。

首先在全局定义中,定义staying_coeff 以及路网road_network,并在创建道路后初始化路网。

然后在人群族中,为代理人编写staymove行为。

6.3.1 整合GIS数据

本节完整代码如下:

Last updated

Was this helpful?