Search code examples
anylogicagent-based-modeling

How to position Canvas with agents in classical Agent-Based Modeling in AnyLogic


I'm new to AnyLogic and trying to figure out how Agent-based models should be set there. There is a famous Epidemic model, which I'm trying to reproduce. Most tutorials on classical ABM deal with old GUI settings.

For example, in version 8.5+, which is actual now, the Environment object (that was used for positioning of layouts) has been deprecated.

Now I see that new object Canvas is used to put the layout with agents on the page. But the structure of source code file is a bit unclear for me and I've failed to find relevant description how Canvas can be set for the purpose. (Besides I'm not sure that this is recommended way of doing this task.)

enter image description here

Question: I would love to learn the right way to arbitrary position the area with agents on the page. Below you may see what I get by default.

enter image description here


Solution

  • After some playing around, the 'minimalistic' functionality is as follows.

    1. One should create some population with arbitrary name Person (population name people adds automatically).

    2. The following structure of the Project is to be reproduced (arbitrary names are marked with yellow).

    enter image description here

    Comment: after adding a Canvas called mapCanvas one adds the function setCanvasCellColor with following body:

    mapCanvas.fillCircle(person.getX(), person.getY(), 3, color);

    It is clear that former two arguments stand for coordinates of a given point, then its size (i.e. 3) and color. Do not forget to add two arguments used in the body, namely, person as Person and color as Color.

    1. From Entry Action of the statechart named state call the just made function. I've put black color here just for the sake of demonstration; chartreuse constant gets used instead in the Epidemic example.

    main.setCanvasCellColor(this, black);

    1. Finally, you may run the model to get the following picture.

    enter image description here

    Note If one is reluctant to bother with Canvas, use Main - Presentation - xxx_presentation and click Draw agent with offset to this position checkbox.