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!