Skip to content

Aimsun Next Micro API Example 1

Example 1: Obtaining Information about Vehicles

This example allows the information of every vehicle inside the system to be obtained for each simulation step.

C++ Version

#include "AKIProxie.h"
#include "CIProxie.h"
#include "ANGConProxie.h"
#include "AAPI.h"
#include <stdio.h>

// Procedures could be modified by the user

char astring[128];

int AAPILoad()
{   
    return 0;
}

int AAPIInit()
{
    return 0;
}

int AAPISimulationReady()
{
    return 0;
}
int AAPIManage(double time, double timeSta, double timeTrans, double acycle)
{

    InfVeh infVeh;
    int nba = AKIInfNetNbSectionsANG();
    for(int i=0; i<nba;i++){
        int id = AKIInfNetGetSectionANGId(i);
        int nb = AKIVehStateGetNbVehiclesSection(id,true);
        for (int j=0; j<nb;j++){
            infVeh = AKIVehStateGetVehicleInfSection(id,j);
            sprintf(astring,"Vehicle %d , Section %d , Lane %d, CurrentPos %f, CurrentSpeed %f\n",infVeh.idVeh, infVeh.idSection, infVeh.numberLane, infVeh.CurrentPos, infVeh.CurrentSpeed);
            AKIPrintString(astring);
        }
    }
    int nbj = AKIInfNetNbJunctions();
    for( int i=0; i<nbj;i++){
        int id = AKIInfNetGetJunctionId(i);
        int nb = AKIVehStateGetNbVehiclesJunction(id);
        for ( int j=0; j<nb;j++){
            infVeh = AKIVehStateGetVehicleInfJunction(id,j);
            sprintf(astring,"Vehicle %d , Node %d , From %d, To %d, CurrentPos %f,CurrentSpeed %f\n", infVeh.idVeh, infVeh.idJunction, infVeh.idSectionFrom, infVeh.idSectionTo, infVeh.CurrentPos, infVeh.CurrentSpeed);
            AKIPrintString(astring);
        }
    }
    return 0;
}

int AAPIPostManage(double time, double timeSta, double timeTrans, double acycle)
{
    return 0;
}

int AAPIFinish()
{
    return 0;
}

int AAPIUnLoad()
{
    return 0;
}

Python Version

from AAPI import *

def AAPILoad():
    return 0

def AAPIInit():
    return 0

def AAPISimulationReady():
    return 0

def AAPIManage(time, timeSta, timTrans, SimStep):

    nba = AKIInfNetNbSectionsANG()
    for i in range(nba):
        id = AKIInfNetGetSectionANGId(i)
        nb = AKIVehStateGetNbVehiclesSection(id,True)
        for j in range(nb):
            infVeh = AKIVehStateGetVehicleInfSection(id,j)
            astring = "Vehicle " + str(infVeh.idVeh) + ", Section " + str(infVeh.idSection) + " , Lane " + str(infVeh.numberLane) + ", CurrentPos " + str(infVeh.CurrentPos) + ", CurrentSpeed " + str(infVeh.CurrentSpeed)
            AKIPrintString(astring)

    nbj = AKIInfNetNbJunctions()
    for i in range(nbj):
        id = AKIInfNetGetJunctionId(i)
        nb = AKIVehStateGetNbVehiclesJunction(id)
        for j in range(nb):
            infVeh = AKIVehStateGetVehicleInfJunction(id,j)
            astring = "Vehicle " + str(infVeh.idVeh) + ", Node " + str(infVeh.idJunction) + " , From " +  str(infVeh.idSectionFrom) + ", To " + str(infVeh.idSectionTo) + ", CurrentPos " + str(infVeh.CurrentPos) + ", CurrentSpeed " + str(infVeh.CurrentSpeed)
            AKIPrintString(astring)

    return 0

def AAPIPostManage(time, timeSta, timTrans, SimStep):
    return 0

def AAPIFinish():
    return 0

def AAPIUnLoad():
    return 0

def AAPIEnterVehicle(idveh,idsection):
    return 0

def AAPIExitVehicle(idveh,idsection):
    return 0