Welcome to the very first guest post on Simulation101. Justin Rawlings from Australia is going to share three massively useful insights for improving the user interface of your AnyLogic models over the next few weeks. They are especially useful for more complex models and I promise that even advanced AnyLogic users will find nuggets here that you haven’t thought about before. I know I have.

This week, Justin starts on how to build your own “Level up” button for models with agent hierarchies. Enjoy...

HOW TO BUILD YOUR OWN "LEVEL UP" BUTTON

As the size of your model grows, more thought must be given to how you navigate through it. This becomes an even more important issue when the 'Main' presentation of your simulation does not fit on a single maximized window.

Thankfully we are not bound to the default behaviour of AnyLogic - in fact the almost unlimited potential to create custom behaviour is its best feature in my opinion.  I've made use of the strategies listed below and found them of great help, hopefully you do too.

For demonstration purposes I've made a sample model with a single population of 'Person' agent type. This very simple agent just maintains a link to other Person agent it regards as 'friends'. This grows and shrinks over the course of the model.

You can find the demo model here (along with future demos):
https://bitbucket.org/jmjrawlings/anylogic_examples

Why do I care?

Consider you are panning around the large model area, and see something interesting. A natural desire is to 'jump in' to that agent, then 'jump out' again to where you were before. However using the default 'Level Up' button to do that in our demo model results in the following:

our model canvas - I want to check out a Person in the rose area

our model canvas - I want to check out a Person in the rose area

Jumping into a Person here...

Jumping into a Person here...

now inside the Person

now inside the Person

and 'Level Up' to get back to the Main canvas

and 'Level Up' to get back to the Main canvas

That's a long way away from where I was beforehand - how annoying! The default action of the 'Level Up' button is to take you to the origin (x=0, y=0) of 'owner' or 'parent' agent.

How do I fix it?

We can work around this by dynamically creating a ViewArea object for each Person in our model. Note that instead of dragging the 'View Area' from the palette, we instead drag a 'Variable' of type ViewArea.

A View area variable

A View area variable

As a result each Person has its own private ViewArea viewUpper = null; We now have to instantiate it when the agent is initialised. This is achieved with the following code:

// Find the owner of this agent
Agent owner = getOwner();
// A title we will give to the view area
String title = String.format("view%s",this);
// Instantiate a view area (centered on our current location)
viewUpper = new ViewArea( owner, title, getX(), getY(), ViewArea.Alignment.CENTER, ViewArea.Scaling.SPECIFIED_ZOOM,
 1.0, 1.0, 1.0);

Even though the variable lives inside the Person, the ViewArea itself will take you to the upper level agent when we navigate to it - perfect. All we need now is a Button (or anything clickable) to use as our own 'Level Up' button:

Button to go a level up

Button to go a level up

For even more control - whenever the user 'jumps into' this agent, typically handled with the following:

_origin_va.navigateTo()

By adding just a few more lines, we can ensure that when our 'Level Up' button is clicked, the user will maintain the same zoom level as when they went in. Very handy.

// Record the zoom level at the time of inspecting
double zoom = getPresentation().getPanel().getZoom();
// Store this as the zoom level of the viewArea (to maintain orientation)
viewUpper.setZoom(zoom);
// Enter this agents presentation
_origin_VA.navigateTo();

You can take this idea a lot further by dynamically changing the width, alignment, zoom level of a ViewArea at runtime - do experiment with this!

Comment

English
German