在AnyLogic中建模人口密度 [英] Modelling population density in AnyLogic

查看:373
本文介绍了在AnyLogic中建模人口密度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在AnyLogic中对人口密度进行建模.为此,我在Main插入了一个国家的图像,并使用折线绘制了区域(在这种情况下为省份,称为pl_ [areaname].然后在Main中使用函数(SetHomeLocation),我正在放置代理(患者(在这种情况下)在这些区域中(如果满足条件的话).为简便起见,下面显示了部分代码.

double x;
double y;
if(uniform(1) <=  0.0343995) /// province 1
do {
    x = uniform( image.getX(), image.getX() + image.getWidth() );
    y = uniform( image.getY(), image.getY() + image.getHeight() );
} while( ! pl_Groningen.contains( x, y ) );
else if(uniform(1) > 0.0343995 && uniform(1) <= 0.0725446) /// province 2
do {
    x = uniform( image.getX(), image.getX() + image.getWidth() );
    y = uniform( image.getY(), image.getY() + image.getHeight() );
} while( ! pl_Friesland.contains( x, y ) );
else
do {
    x = uniform( image.getX(), image.getX() + image.getWidth() );
    y = uniform( image.getY(), image.getY() + image.getHeight() );
} while( ! countrybounds.contains( x, y ) );
agent.setXY( x, y );

在患者"中,我创建了两个变量XHome和YHome,并在启动时"字段中输入了以下内容:

//setup home location (within the country bounds that are defined in Main)
main.setHomeLocation( this );
XHome = getX();
YHome = getY();

现在看来SetHomeLocation函数中的代码无法正常运行.在某些地区,我得到的代理商比预期的要少.

我也相信

if(uniform(1) > x && uniform(y) <= y)

是错误的,因为我认为该语句将评估均匀分布中的两个不同的平局,而不是一个.

要进行全面披露,请使用以下链接下载完整的模型. https://www.mediafire.com/file/eaq65mgpqi9qlld/TestModelKaart.zip/文件

为清楚起见,本文包含两个问题. 首先,该模型显示出意外行为(即在某些区域放置的座席太少)的原因可能是什么? 其次,如果我要x>均匀(1)< = y,如何让AnyLogic从均匀分布中评估一幅?

与人口密度建模有关的任何其他提示当然也很受欢迎!

解决方案

要回答至少一个问题,您必须在开头创建一个变量,并在其余函数中使用它:

double rand=uniform();
if(rand <=  0.0343995) /// province 1
//your code
else if(rand > 0.0343995 && rand <= 0.0725446) /// province 2
//your code
else //rand>0.0725446
//your code

请先检查是否可以解决您的其他问题.

I am trying to model population density in AnyLogic. To that end, I've inserted an image of a country in Main, and used polyline to draw areas (called pl_[areaname], provinces in this case. Then using a function (SetHomeLocation) in Main, I am placing agents (patients in this case) in these areas, if a condition is met. For brevity, part of the code is shown below.

double x;
double y;
if(uniform(1) <=  0.0343995) /// province 1
do {
    x = uniform( image.getX(), image.getX() + image.getWidth() );
    y = uniform( image.getY(), image.getY() + image.getHeight() );
} while( ! pl_Groningen.contains( x, y ) );
else if(uniform(1) > 0.0343995 && uniform(1) <= 0.0725446) /// province 2
do {
    x = uniform( image.getX(), image.getX() + image.getWidth() );
    y = uniform( image.getY(), image.getY() + image.getHeight() );
} while( ! pl_Friesland.contains( x, y ) );
else
do {
    x = uniform( image.getX(), image.getX() + image.getWidth() );
    y = uniform( image.getY(), image.getY() + image.getHeight() );
} while( ! countrybounds.contains( x, y ) );
agent.setXY( x, y );

In Patient, I've created two variables XHome and YHome, and in the 'on startup' field I've entered:

//setup home location (within the country bounds that are defined in Main)
main.setHomeLocation( this );
XHome = getX();
YHome = getY();

Now it seems that the code in SetHomeLocation function is not working as it supposed to be. I am getting fewer agents in some areas than I would expect.

I also believe that

if(uniform(1) > x && uniform(y) <= y)

is faulty, as I believe that statement would evaluate two different draws from the uniform distribution, instead of one.

For full disclosure, the following link lets you download the complete model. https://www.mediafire.com/file/eaq65mgpqi9qlld/TestModelKaart.zip/file

To be clear, this post contains two questions. First, what could be the cause that the model shows unexpected behavior, i.e. placing too few agents in some areas? Second, how do I let AnyLogic evaluate one draw from the uniform distribution, if I want x > uniform(1) <= y?

Any other tips that are related to modeling population density are of course very welcome!

解决方案

To answer at least one of your questions, you have to create a variable in the beginning and use it in the rest of your function:

double rand=uniform();
if(rand <=  0.0343995) /// province 1
//your code
else if(rand > 0.0343995 && rand <= 0.0725446) /// province 2
//your code
else //rand>0.0725446
//your code

Check first if this solves your other problem or not.

这篇关于在AnyLogic中建模人口密度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆