The Aimsun Next Application Programming Interface (API) extension can be implemented using a Python script. This Python script is an ASCII file (with extension: “.py”), which can be edited in any text editor. This Python script is provided with the Aimsun Next software in the Aimsun_Next_installation_folder (right-click on the Aimsun Next shortcut > Select “Open File location”).
- Copy-paste the py file from Aimsun_Next_installation_folder/programming/Aimsun Next API/python/samples/Micro OR Meso/sample.py in the working directory ( it is recommended to place it in the same directory as the ANG file so that Aimsun Next can automatically recognize the relative paths if moved to a different directory.
- Copy-paste the py file from Aimsun_Next_installation_folder/programming/Aimsun Next API/python/private/Micro OR Meso/AAPI.py in the same directory where the sample.py file is stored.
- You may save the Python script file (py) with a name of your preference. Keep the sample.py file as back-up file in case you need to code another API.
- Open the renamed Python script file. In the upper part, the AAPI module is imported to allow the interpretation of the function from C++ to Python. This module works as an interface between the Python script and Aimsun Next (interpreter with Python code and libraries). The Aimsun Next Microscopic API module has seven high level functions which communicate between the API Module and the Simulation model: AAPILoad(), AAPIInit(), AAPISimulationReady(), AAPIManage(…), AAPIPostManage(…), AAPIFinish(), AAPIUnLoad(). It also has eight additional functions that are called when certain events occur: AAPIEnterVehicle(…), AAPIExitVehicle(…), AAPIEnterVehicleSection(…), AAPIExitVehicleSection(…), AAPIPreRouteChoiceCalculation(…), AAPIVehicleStartParking(…), AAPIEnterPedestrian(…), AAPIExitPedestrian(…). For more information re the Aimsun Next Mesoscopic API, visit the Aimsun Next Manual > Aimsun Next API > Architecture > Simulation Management.
- Find a complete list of functions documented in the Aimsun Next Manual to manage control plans, to apply changes in the microscopic or mesoscopic simulations. Access the Aimsun Next Manual > Aimsun Next API > Manage Control Plans/Microscopic Simulation/Mesoscopic Simulation. Also find a step-by-step instruction how to build an API as well as explore the API examples.
- Start coding –
- To test the coding status, load the API in the Aimsun Next, open a Dynamic Scenario
- Access the tab Aimsun Next APIs
- Add the py in the Aimsun Next APIs and select it.
- Press OK and then right click on the Replication > Run Animated Simulation (for microscopic simulation). Now observe the printed messages of your code in the Log window (to activate the Log window, go to Main Menu > Window > Windows > Log (o).