Using AI to help build AnyLogic Simulation Models
- Selaelo Kgoale
- Oct 22
- 6 min read
This is a special blog post by our junior engineer, Selaelo Kgoale. Selaelo is still a junior in the simulation modeling world, and he is presenting some of the lessons he has learned on his new journey in a series of blog posts. Subscribe to the blog if you want to follow along and learn some new tips and tricks.
This post was made possible by the support of our Patrons. To become a member, click here.
In this blog post, we'll demonstrate how one can effectively leverage AI in the simulation development workflow to increase productivity significantly. When I first started learning how to build models in AnyLogic, I quickly realised that there’s a lot to keep track of, including Java code, model structure, debugging, documentation… the list goes on. The tasks related to these aspects of development can range from being too repetitive/mundane to being daunting at times. One cannot help but wonder if there's a way around this.
According to my mentor, Jaco-Ben Vosloo, the answer lies in integrating AI into one's workflow. See his demonstration video on AI usage in model building here. It should be noted that this blog post serves as a companion to the video, extensively covering parts not detailed in the video. The blog post aims to cover the key areas:
Leveraging chatbots for general guidance and writing functions
IDE integration: AI in VS Code to write and review code
AI-powered code review and task assignment in GitHub
Now, let's put this in motion.
Leveraging Chatbots For General Concept Guidance And Code Generation Assistance
General-purpose chatbots like ChatGPT, Grok, and Perplexity can be valuable resources for simulation modelers, particularly during the early stages of planning or when working with unfamiliar structures. They can be leveraged in two main ways: providing guidance on general concepts for structuring models and assisting with code generation.
General Concept Guidance
Chatbots are capable of offering high-level recommendations in response to modeling prompts, particularly useful for novice modelers. For example, we can use the following prompt on perplexity:
"Please provide me with instructions on how I can set up an inventory management system in my AnyLogic model so that I can track how inventory is built up for the different kinds of products and then order new products based on target stock levels. Please provide as many details as possible. Give specific considerations to the AnyLogic function and features.”

Responses generally include definitions of agents, suggestions for variables, and relationships among objects. Although the results require interpretation and implementation within the AnyLogic platform, they can serve as effective starting points.

You can use the prompt to review the response in detail
Code Generation Assistance
AI chatbots can generate Java code snippets from plain-text descriptions or pseudocode. These outputs are beneficial when defining utility functions, loops, or decision logic. While further translation into AnyLogic-specific elements, such as Function Objects, is necessary, chatbots significantly speed up development by offering structural foundations and syntax support. For example, we can use the following prompt on Grok:
"I need a function for my AnyLogic model that will cycle through all the Docks in the collection loadDocks and find at least one that has enough space available to carry the order I want to place. If multiple docks are present, return the one with the largest dock.spaceAvailable()"

Copilot generates relevant Java code that users can review, modify, and seamlessly incorporate into AnyLogic-specific function objects. This process minimises manual coding effort and helps maintain consistency, particularly for frequently used code segments. To demonstrate, the output from our prompt is standard code

This code cannot be directly translated to the AnyLogic drag-and-drop & coding environment. The code must be implemented in an object's properties section, in our case, the 'findDock' function object.

We can either manually translate the code or ask Grok for a step-by-step guide to streamline and reduce potential human error. When choosing the latter, get the following output from the prompt:

The output provides the exact step, simplifying one's work. Feel free to preview these responses by replicating the prompts.
IDE Integration: AI In VS Code To Write And Review Code
For those comfortable with Git workflows and versioned modeling, opening your project in Visual Studio Code (VS Code) unlocks a whole new level of interactivity.
To leverage the functionality, one must perform the following steps:
Save your AnyLogic model in ALPX format
Open it in VS Code to expose the whole file structure
Use tools like GitHub Copilot for inline suggestions
It should be noted that for ease of use between the two platofrms, code generation instructions can be written as inline comments as follows:

From here, we save the model in ALPX format by checking the "Use multi-part ALP format".

Then we proceed to open the model in VS Code

Once the model is opened, we can navigate to the comment line and press Enter at the end of the line. This will trigger a generation of the suggestive line. We press Enter on the generated line to generate the subsequent line and so forth till we have the entire suggested code. In this demonstration, the code is a for loop.

Save the changes in VS Code and reload or re-open the AnyLogic model to preview the code

AI-powered code review and task assignment in GitHub
Code review
AI can also be integrated into the quality assurance process through pull request reviews in GitHub. This also requires a GitHub Co-Pilot subscription.
In this work, we have some work done in our AnyLogic Model committed on a branch, a commit that we push to the origin:

Then, we create a pull request and assign Co-Pilot as a reviewer:

Co-pilot will review the code and make recommendations accordingly. It'll provide a pull request overview detailing changes.

Here we can observe an example of recommended changes and commit them to the branch:

Task assignment
AI can also be assigned issues/tasks similar to how one would assign to a human developer. The time taken to perform a task is proportional to the complexity of said task. To demonstrate this we assign an issue to Co-Pilot as follows:
Write a detailed description of the task

Select Co-pilot as an assignee

Co-pilot then creates a work-in-progress pull request for the task. In this section, we can track the progress of the tasks via the checklist Co-pilot generates.

Upon viewing the session, we observe the following:

One can view the status and the time spent on the session(Duration). Co-pilot essentially creates a separate branch accordingly and completes task(s) simultaneously, detailing the current and following steps..
After a couple of minutes, the task will be ready for review we can review the pull request when the work is done and we can see what changes Co-Pilot made.

Some other tasks assignment ideas for Co-Pilot
a) Add descrptions to all variables and parameters

The image added to the description is a sample model element, and the line "The location of the description can be found in the Description> tag in the XML of various parts." is compulsory to help the AI identify where to place generated descriptions.
It should be noted that, similar to a human developer, Co-Pilot sends an email upon commencing and completing a task. The following sample is an email for the commencement of the log task:

b) Full review if coding best practices and model architecture
We can also ask Co-Pilot to review our entire model

Conclusion:
The adoption of AI in model development is inevitable and represents the next step in improving the process. The main area that stands to benefit from this development is repetitive tasks, such as model formulation, abstract code formulation, and code review. It should be noted that AI recommendations should not be implemented without a thorough review from the developer.
Keep modeling
Selaelo Kgoale
Want to see the tips shared in this blog post live in action? Watch the demonstration video by Jaco-Ben Vosloo:
Selaelo Kgoale is a simulation enthusiast and junior engineer at The AnyLogic Modeler. To contact him, use LinkedIn.
What next?
If you liked this post, you could read more posts by following the links above. Why not subscribe to our blog or follow us on any of the social media accounts for future updates? The links are in the Menu bar at the top, or the footer at the bottom. You can also join the mobile app here!
If you really want to make a difference in supporting us please consider joining our Patreon community here
If you want to contact us for some advice, maybe a potential partnership or project or just to say "Hi!", feel free to get in touch here, and we will get back to you soon!





