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

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

问题描述

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

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 );

在 Patient 中,我创建了两个变量 XHome 和 YHome,并在启动时"字段中输入:

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();

现在似乎 SetHomeLocation 函数中的代码没有按预期工作.我在某些领域获得的代理比我预期的要少.

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.

我也相信

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.

如需完整披露,您可以通过以下链接下载完整模型.https://www.mediafire.com/file/eaq65mgpqi9qlld/TestModelKaart.zip/文件

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

需要明确的是,这篇文章包含两个问题.首先,模型显示意外行为(即在某些区域放置的代理太少)的原因可能是什么?其次,如果我想要 x >uniform(1) <= y,我如何让 AnyLogic 从均匀分布中评估一个抽奖?

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天全站免登陆