Aimsun Next Micro API Example 2¶
Example 2: Obtaining Statistical information¶
This example shows how to access different statistical information during and at the end of the simulation.
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 idVeh, carPosition;
int AAPILoad()
{
return 0;
}
int AAPIInit()
{
idVeh = ANGConnGetObjectIdByType( AKIConvertFromAsciiString( "car" ), AKIConvertFromAsciiString( "GKVehicle" ), false )
carPosition = AKIVehGetVehTypeInternalPosition( idVeh )
return 0;
}
int AAPISimulationReady()
{
return 0;
}
int AAPIManage(double time, double timeSta, double timeTrans, double acycle)
{
return 0;
}
int AAPIPostManage(double time, double timeSta, double timeTrans, double acycle)
{
StructAkiEstadSystem estad = AKIEstGetParcialStatisticsSystem(timeSta, 0);
if (estad.report==0){
AKIPrintString("\t\t SYSTEM");
snprintf(astring, 128, "\t\t Report :%d",estad.report);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Flow :%d ",estad.Flow);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Travel Time :%f",estad.TTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Delay Time :%f",estad.DTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Speed :%f",estad.Sa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Stop Time :%f \n",estad.STa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t NumStops :%f",estad.NumStops);
AKIPrintString(astring);
}
StructAkiEstadSection estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, 0);
if (estad2.report==0){
snprintf(astring, 128, "\t\t SECTION");
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Report :%d",estad2.report);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Flow :%d ",estad2.Flow);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Travel Time :%f",estad2.TTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Delay Time :%f",estad2.DTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Speed :%f",estad2.Sa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Stop Time :%f \n",estad2.STa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t NumStops :%f",estad2.NumStops);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t LongQueueAvg :%f ",estad2.LongQueueAvg);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t LongQueueMax :%f ",estad2.LongQueueMax);
AKIPrintString(astring);
}
estad = AKIEstGetParcialStatisticsSystem(timeSta, carPosition);
if (estad.report==0){
snprintf(astring, 128, "\t\t SYSTEM CAR\n");
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Report :%d",estad.report);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Flow :%d ",estad.Flow);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Travel Time :%f",estad.TTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Delay Time :%f",estad.DTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Speed :%f",estad.Sa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Stop Time :%f \n",estad.STa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t NumStops :%f",estad.NumStops);
AKIPrintString(astring);
}
estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, carPosition);
if (estad2.report==0){
snprintf(astring, 128, "\t\t SECTION CAR\n");
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Report :%d",estad2.report);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Flow :%d ",estad2.Flow);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Travel Time :%f",estad2.TTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Delay Time :%f",estad2.DTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Speed :%f",estad2.Sa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Stop Time :%f \n",estad2.STa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t NumStops :%f",estad2.NumStops);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t LongQueueAvg :%f ",estad2.LongQueueAvg);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t LongQueueMax :%f ",estad2.LongQueueMax);
AKIPrintString(astring);
}
return 0;
}
int AAPIFinish()
{
StructAkiEstadSystem estad = AKIEstGetGlobalStatisticsSystem(0);
if (estad.report==0){
snprintf(astring, 128, "\t\t SYSTEM\n");
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Report :%d",estad.report);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Flow :%d ",estad.Flow);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Travel Time :%f",estad.TTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Delay Time :%f",estad.DTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Speed :%f",estad.Sa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Stop Time :%f \n",estad.STa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t NumStops :%f",estad.NumStops);
AKIPrintString(astring);
}
StructAkiEstadSection estad2 = AKIEstGetGlobalStatisticsSection(1, 0);
if (estad2.report==0){
snprintf(astring, 128, "\t\t SECTION\n");
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Report :%d",estad2.report);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Flow :%d ",estad2.Flow);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Travel Time :%f",estad2.TTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Delay Time :%f",estad2.DTa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Speed :%f",estad2.Sa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t Stop Time :%f \n",estad2.STa);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t NumStops :%f",estad2.NumStops);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t LongQueueAvg :%f ",estad2.LongQueueAvg);
AKIPrintString(astring);
snprintf(astring, 128, "\t\t LongQueueMax :%f ",estad2.LongQueueMax);
AKIPrintString(astring);
}
return 0;
}
int AAPIUnLoad()
{
return 0;
}
Python Version¶
from AAPI import *
carPosition = 0
def AAPILoad():
return 0
def AAPIInit():
idVeh = ANGConnGetObjectIdByType( AKIConvertFromAsciiString( "car" ), AKIConvertFromAsciiString( "GKVehicle" ), False )
carPosition = AKIVehGetVehTypeInternalPosition( idVeh )
return 0
def AAPISimulationReady():
return 0
def AAPIManage(time, timeSta, timTrans, SimStep):
return 0
def AAPIPostManage(time, timeSta, timTrans, SimStep):
estad = AKIEstGetParcialStatisticsSystem(timeSta, 0)
if (estad.report==0):
AKIPrintString("\t\t SYSTEM")
astring = "\t\t Report : " + str(estad.report)
AKIPrintString(astring)
astring = "\t\t Flow : " + str(estad.Flow)
AKIPrintString(astring)
astring = "\t\t Travel Time : " + str(estad.TTa)
AKIPrintString(astring)
astring = "\t\t Delay Time : " + str(estad.DTa)
AKIPrintString(astring)
astring = "\t\t Speed : " + str(estad.Sa)
AKIPrintString(astring)
astring = "\t\t Stop Time : " + str(estad.STa)
AKIPrintString(astring)
astring = "\t\t NumStops : " + str(estad.NumStops)
AKIPrintString(astring)
estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, 9)
if (estad2.report==0):
AKIPrintString("\t\t SECTION")
astring = "\t\t Report : " + str(estad2.report)
AKIPrintString(astring)
astring = "\t\t Flow : " + str(estad2.Flow)
AKIPrintString(astring)
astring = "\t\t Travel Time : " + str(estad2.TTa)
AKIPrintString(astring)
astring = "\t\t Delay Time : " + str(estad2.DTa)
AKIPrintString(astring)
astring = "\t\t Speed : " + str(estad2.Sa)
AKIPrintString(astring)
astring = "\t\t Stop Time : " + str(estad2.STa)
AKIPrintString(astring)
astring = "\t\t NumStops : " + str(estad2.NumStops)
AKIPrintString(astring)
astring = "\t\t LongQueueAvg : " + str(estad2.LongQueueAvg)
AKIPrintString(astring)
astring = "\t\t LongQueueMax : " + str(estad2.LongQueueMax)
AKIPrintString(astring)
estad = AKIEstGetParcialStatisticsSystem(timeSta, carPosition)
if (estad.report==0):
AKIPrintString("\t\t SYSTEM CAR\n")
astring = "\t\t Report : " + str(estad.report)
AKIPrintString(astring)
astring = "\t\t Flow : " + str(estad.Flow)
AKIPrintString(astring)
astring = "\t\t Travel Time : " + str(estad.TTa)
AKIPrintString(astring)
astring = "\t\t Delay Time : " + str(estad.DTa)
AKIPrintString(astring)
astring = "\t\t Speed : " + str(estad.Sa)
AKIPrintString(astring)
astring = "\t\t Stop Time : " + str(estad.STa)
AKIPrintString(astring)
astring = "\t\t NumStops : " + str(estad.NumStops)
AKIPrintString(astring)
estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, carPosition)
if (estad2.report==0):
AKIPrintString("\t\t SECTION CAR\n")
astring = "\t\t Report : " + str(estad2.report)
AKIPrintString(astring)
astring = "\t\t Flow : " + str(estad2.Flow)
AKIPrintString(astring)
astring = "\t\t Travel Time : " + str(estad2.TTa)
AKIPrintString(astring)
astring = "\t\t Delay Time : " + str(estad2.DTa)
AKIPrintString(astring)
astring = "\t\t Speed : " + str(estad2.Sa)
AKIPrintString(astring)
astring = "\t\t Stop Time : " + str(estad2.STa)
AKIPrintString(astring)
astring = "\t\t NumStops : " + str(estad2.NumStops)
AKIPrintString(astring)
astring = "\t\t LongQueueAvg : " + str(estad2.LongQueueAvg)
AKIPrintString(astring)
astring = "\t\t LongQueueMax : " + str(estad2.LongQueueMax)
AKIPrintString(astring)
return 0
def AAPIFinish():
estad = AKIEstGetGlobalStatisticsSystem(0)
if (estad.report==0):
AKIPrintString("\t\t SYSTEM\n")
astring = "\t\t Report : " + str(estad.report)
AKIPrintString(astring)
astring = "\t\t Flow : " + str(estad.Flow)
AKIPrintString(astring)
astring = "\t\t Travel Time : " + str(estad.TTa)
AKIPrintString(astring)
astring = "\t\t Delay Time : " + str(estad.DTa)
AKIPrintString(astring)
astring = "\t\t Speed : " + str(estad.Sa)
AKIPrintString(astring);
astring = "\t\t Stop Time : " + str(estad.STa)
AKIPrintString(astring);
astring = "\t\t NumStops : " + str(estad.NumStops)
AKIPrintString(astring)
estad2 = AKIEstGetGlobalStatisticsSection(1, 0)
if (estad2.report==0):
AKIPrintString("\t\t SECTION\n")
astring = "\t\t Report : " + str(estad2.report)
AKIPrintString(astring)
astring = "\t\t Flow : " + str(estad2.Flow)
AKIPrintString(astring)
astring = "\t\t Travel Time : " + str(estad2.TTa)
AKIPrintString(astring)
astring = "\t\t Delay Time : " + str(estad2.DTa)
AKIPrintString(astring)
astring = "\t\t Speed : " + str(estad2.Sa)
AKIPrintString(astring)
astring = "\t\t Stop Time : " + str(estad2.STa)
AKIPrintString(astring)
astring = "\t\t NumStops : " + str(estad2.NumStops)
AKIPrintString(astring)
astring = "\t\t LongQueueAvg : " + str(estad2.LongQueueAvg)
AKIPrintString(astring)
astring = "\t\t LongQueueMax : " + str(estad2.LongQueueMax)
AKIPrintString(astring)
return 0
def AAPIUnLoad():
return 0
def AAPIEnterVehicle(idveh,idsection):
return 0
def AAPIExitVehicle(idveh,idsection):
return 0