Aimsun Next Micro API Example 3:¶
Example of Vehicle Entrance and Vehicle Tracking¶
This example shows how to implement vehicle tracking and how to introduce vehicles into the system using an external entrance distribution. It also shows how to vary vehicle speed, here by introducing a random variation, and how to force a route change.
C++ Version¶
#include "AKIProxie.h"
#include "CIProxie.h"
#include "ANGConProxie.h"
#include "AAPI.h"
#include <stdio.h>
int idVehFirst = 0;
int idVehSecond = 0;
int idVeh = 0;
int carPosition = 0;
int AAPILoad()
{
return 0;
}
int AAPIInit()
{
idVeh = ANGConnGetObjectIdByType( AKIConvertFromAsciiString( "car" ), AKIConvertFromAsciiString( "GKVehicle" ), false )
carPosition = AKIVehGetVehTypeInternalPosition( idVeh )
idVehFirst = AKIEnterVehTrafficOD(108, carPosition, 285, 288, True);
idVehSecond = AKIEnterVehTrafficOD(108, carPosition, 285, 288, True);
return 0;
}
int AAPISimulationReady()
{
return 0;
}
int AAPIManage(double time, double timeSta, double timeTrans, double acycle)
{
/* Any signal or ITS actions would go here
return 0;
}
int AAPIPostManage(double time, double timeSta, double timeTrans, double acycle)
{
spd1 = AKIVehTrackedGetInf(idVehFirst).CurrentSpeed + rand(0.5);
spd2 = AKIVehTrackedGetInf(idVehSecond).CurrentSpeed + rand(0.5);
AKIVehTrackedModifySpeed(idVehFirst, spd1 );
AKIVehTrackedModifySpeed(idVehSecond,spd2 );
if ( AKIVehTrackedGetInf(idVehSecond).idSection == 545)
{
AKIVehTrackedModifyNextSection(idVehSecond, 546);
}
return 0;
}
int AAPIFinish()
{
return 0;
}
int AAPIUnLoad()
{
return 0;
}
Python Version¶
from AAPI import *
idVehFirst = 0
idVehSecond = 0
carPosition = 0
def AAPILoad():
return 0
def AAPIInit():
global idVehFirst
global idVehSecond
global carPosition
idVeh = 8
carPosition = AKIVehGetVehTypeInternalPosition( idVeh )
idVehFirst = AKIEnterVehTrafficOD(108, carPosition, 285, 288, True)
idVehSecond = AKIEnterVehTrafficOD(108, carPosition, 285, 288, True)
return 0
def AAPISimulationReady():
return 0
def AAPIManage(time, timeSta, timTrans, SimStep):
'Any signal or ITS actions would go here
return 0
def AAPIPostManage(time, timeSta, timTrans, SimStep):
global idVehFirst
global idVehSecond
spd1 = AKIVehTrackedGetInf(idVehFirst).CurrentSpeed + rand(0.5)
spd2 = AKIVehTrackedGetInf(idVehSecond).CurrentSpeed + rand(0.5)
AKIVehTrackedModifySpeed(idVehFirst, spd1)
AKIVehTrackedModifySpeed(idVehSecond, spd2)
if AKIVehTrackedGetInf(idVehSecond).idSection == 545:
AKIVehTrackedModifyNextSection(idVehSecond, 546)
return 0
def AAPIFinish():
return 0
def AAPIUnLoad():
return 0
def AAPIEnterVehicle(idveh,idsection):
return 0
def AAPIExitVehicle(idveh,idsection):
return 0