0

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

garej
  • 508
  • 1
  • 8
  • 24
  • 1
    this is a loooong answer with a lot of elements to explain.. I suggest for now to explore the canvas object in the help file... play with all the functions always knowing that it's not that you position the agents in the canvas, instead of that, you paint the canvas in the position where the agents are supposed to be... If you are new to AnyLogic, this is not the right place to start imo. – Felipe Nov 12 '19 at 22:49
  • @Felipe, notice also that SIR (epidemic) example model from documentation doesn't work in my installation of AnyLogic ver. 8.5.1, and errors are connected to GUI issues. – garej Nov 13 '19 at 07:10
  • Using the Canvas element is an advanced thing just designed for better performance than the more normal method of using standard discrete space (and is only relevant for discrete (grid-based) space). Unfortunately AnyLogic updated many of their example models to 'show off' its use when it's not at all necessary. See the `AnyLogic Help > Agent Based Modeling > Space in agent based models` help section. – Stuart Rossiter Nov 29 '19 at 17:42

1 Answers1

1

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.

garej
  • 508
  • 1
  • 8
  • 24