Aimsun Next API Frequently asked questions¶
Getting Started¶
The Aimsun Next API is a set of methods that allow programmers to read and modify information used during an Aimsun Next Microscopic simulation concerning vehicles, demand, control, detection data, etc.
The Aimsun Next API is provided in C++ and in Python. The user must decide which language to use.
The files to build an Aimsun Next API in C++ are located in the Aimsun Next installation folder (programming/Aimsun Next API/cpp). This folder also contains a Visual Studio project that contains all the files needed to build a C++ AAPI. The only files that should be modified are AAPI.cxx and AAPI.h
The Micro/Meso files to build an Aimsun Next API in Python are located in the Aimsun Next installation folder (programming/Aimsun Next API/python/samples). The only file that that should be modified is sample.py
Does Aimsun Next API require a special license?¶
Yes. The Aimsun Next API license is required. This is available for Pro Micro, Advanced, and Expert editions.
FAQ for C++ Aimsun Next APIs¶
Which Visual Studio version I should use?**¶
With the Windows version there is a Visual Studio 2019 project in C ready to compile and build the DLL. The Visual Studio 2019 project has two configurations available: the Debugger configuration that builds the AAPI_D.dll by default and the Release configurations that builds the AAPI_R.dll by default.
In order to build an AAPI in 64 bits, select menu Build / Configuration Manager from Visual Studio 2019 (x64). Then, select x64 in the Active solution platform dropdown box.
How to debug an API extension¶
Start the debugger and attach it to Aimsun Next (Tools/Attach... menu). Place the breakpoints where required and start the simulation. Note that it might not know that the DLL is there until the simulation is started for the first time. If the functions AAPIInit or AAPILoad are to be debugged, the breakpoints placed in these methods might not be reached unless the debugger is restarted using (Ctrl+Shift+F5), after which it will be possible to debug AAPILoad and AAPIInit.
How to use strings¶
There are two methods in AAPI that allow ascii to unicode conversions:
-
const unsigned short AKIConvertFromAsciiString(const char ascii): This method convert into unicode any ascii string.
-
const char AKIConvertToAsciiString(const unsigned short string, bool deleteUshortString, bool *anyNonAsciiChar): This method converts into ascii any unicode string. Note that the unicode string can contain non-convertible characters, in that case, anyNonAsciiChar will be set to true.
00 const unsigned short* name = AKIConvertFromAsciiString("GKSection::nblanesAtt"); 01 bool anyNonAsciiChar; 02 const char* ascii = AKIConvertToAsciiString( name, false, &anyNonAsciiChar ); 03 AKIPrintString( ascii ); 04 AKIPrintAsUNICODEString( name );
-
Line 00: Ascii to Unicode conversion
- Line 02: Unicode to Ascii conversion
- Line 03, 04: print in both modes. In this case, it prints exactly the same string
FAQ for Python Aimsun Next API¶
The message "File myScript.py not found or Wrong Syntax" implies myScript.py is not a valid extension.
The message "Python Error (): No module named new" arises when python has not been installed in the computer. It can be downloaded from www.python.org.
How to use in/out parameters¶
Basic types pointers are provided. The available types are: boolp, intp, floatp, and doublep.
00 min_x = doublep()
01 min_y = doublep()
02 max_x = doublep()
03 max_y = doublep()
04 AKIInfNetGetWorldCoordinates( min_x, min_y, max_x, max_y )
05 print "min(%f, %f) max(%f, %f)"%(min_x.value(), min_y.value(), max_x.value(), max_y.value() )
- Line 00, 03: double pointers declaration.
- Line 04: Method call that initializes the minimum and maximum world coordinates.
- Line 05: Printing pointer variables content.
Functions with int * representing an int array as input parameters are supported by intArray class. A small example follows:
nextSections = intArray( 3 )
nextSections [0] = 182
nextSections [1] = 183
nextSections [2] = 184
AKIActionAddNextSubPathODAction(182, 3, nextSections, 286, 285, 0, 110, 100, 100)
Python Error¶
(<type 'exceptions.AttributeError'>): 'module' object has no attribute 'AAPIExitPedestrian'**
This error arises when some of the thirteen high level functions are not defined in the file with the API code (in this case the AAPIExitPedestrian function). The functions that should be included are: AAPILoad(), AAPIInit(), AAPISimulationReady(), AAPIManage(…), AAPIPostManage(…), AAPIFinish(), AAPIUnLoad(), AAPIPreRouteChoiceCalculation(...), AAPIVehicleStartParking(...), AAPIEnterVehicle(...), AAPIExitVehicle(...), AAPIEnterPedestrian(...), AAPIExitPedestrian(...), AAPIEnterVehicleSection(...), and AAPIExitVehicleSection(...).