Skip to content

Exemplo 2 da API Micro Aimsun Next

Exemplo 2: Obtendo Informações Estatísticas

Este exemplo mostra como acessar diferentes informações estatísticas durante e ao final da simulação.

Versão C++

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

// Os procedimentos podem ser modificados pelo usuário

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("		 SISTEMA");
        snprintf(astring, 128, "		 Relatório :%d",estad.report);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Fluxo :%d ",estad.Flow);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Viagem :%f",estad.TTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Atraso :%f",estad.DTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Velocidade :%f",estad.Sa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Parada :%f 
",estad.STa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 NumParadas :%f",estad.NumStops);
        AKIPrintString(astring);
    }

    StructAkiEstadSection estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, 0);
    if (estad2.report==0){
        snprintf(astring, 128, "		 SEÇÃO");
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Relatório :%d",estad2.report);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Fluxo :%d ",estad2.Flow);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Viagem :%f",estad2.TTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Atraso :%f",estad2.DTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Velocidade :%f",estad2.Sa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Parada :%f 
",estad2.STa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 NumParadas :%f",estad2.NumStops);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 LongQueueAvg :%f ",estad2.LongQueueAvg);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 LongQueueMax :%f ",estad2.LongQueueMax);
        AKIPrintString(astring);
    }

    estad = AKIEstGetParcialStatisticsSystem(timeSta, carPosition);
    if (estad.report==0){
        snprintf(astring, 128, "		 SISTEMA CARRO
");
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Relatório :%d",estad.report);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Fluxo :%d ",estad.Flow);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Viagem :%f",estad.TTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Atraso :%f",estad.DTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Velocidade :%f",estad.Sa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Parada :%f 
",estad.STa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 NumParadas :%f",estad.NumStops);
        AKIPrintString(astring);
    }

    estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, carPosition);
    if (estad2.report==0){
        snprintf(astring, 128, "		 SEÇÃO CARRO
");
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Relatório :%d",estad2.report);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Fluxo :%d ",estad2.Flow);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Viagem :%f",estad2.TTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Atraso :%f",estad2.DTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Velocidade :%f",estad2.Sa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Parada :%f 
",estad2.STa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 NumParadas :%f",estad2.NumStops);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 LongQueueAvg :%f ",estad2.LongQueueAvg);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 LongQueueMax :%f ",estad2.LongQueueMax);
        AKIPrintString(astring);
    }
    return 0;
}

int AAPIFinish()
{
    StructAkiEstadSystem estad = AKIEstGetGlobalStatisticsSystem(0);
    if (estad.report==0){
        snprintf(astring, 128, "		 SISTEMA
");
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Relatório :%d",estad.report);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Fluxo :%d ",estad.Flow);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Viagem :%f",estad.TTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Atraso :%f",estad.DTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Velocidade :%f",estad.Sa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Parada :%f 
",estad.STa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 NumParadas :%f",estad.NumStops);
        AKIPrintString(astring);
    }

    StructAkiEstadSection estad2 = AKIEstGetGlobalStatisticsSection(1, 0);
    if (estad2.report==0){
        snprintf(astring, 128, "		 SEÇÃO
");
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Relatório :%d",estad2.report);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Fluxo :%d ",estad2.Flow);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Viagem :%f",estad2.TTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Atraso :%f",estad2.DTa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Velocidade :%f",estad2.Sa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 Tempo de Parada :%f 
",estad2.STa);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 NumParadas :%f",estad2.NumStops);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 LongQueueAvg :%f ",estad2.LongQueueAvg);
        AKIPrintString(astring);
        snprintf(astring, 128, "		 LongQueueMax :%f ",estad2.LongQueueMax);
        AKIPrintString(astring);
    }
    return 0;
}


int AAPIUnLoad()
{
    return 0;
}

Versão Python

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("		 SISTEMA")
        astring = "		 Relatório : " + str(estad.report)
        AKIPrintString(astring)
        astring = "		 Fluxo : " + str(estad.Flow)
        AKIPrintString(astring)
        astring = "		 Tempo de Viagem : " + str(estad.TTa)
        AKIPrintString(astring)
        astring = "		 Tempo de Atraso : " + str(estad.DTa)
        AKIPrintString(astring)
        astring = "		 Velocidade : " + str(estad.Sa)
        AKIPrintString(astring)
        astring = "		 Tempo de Parada : " + str(estad.STa)
        AKIPrintString(astring)
        astring = "		 NumParadas : " + str(estad.NumStops)
        AKIPrintString(astring)

    estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, 9)
    if (estad2.report==0):
        AKIPrintString("		 SEÇÃO")
        astring = "		 Relatório : " + str(estad2.report)
        AKIPrintString(astring)
        astring = "		 Fluxo : " + str(estad2.Flow)
        AKIPrintString(astring)
        astring = "		 Tempo de Viagem : " + str(estad2.TTa)
        AKIPrintString(astring)
        astring = "		 Tempo de Atraso : " + str(estad2.DTa)
        AKIPrintString(astring)
        astring = "		 Velocidade : " + str(estad2.Sa)
        AKIPrintString(astring)
        astring = "		 Tempo de Parada : " + str(estad2.STa)
        AKIPrintString(astring)
        astring = "		 NumParadas : " + str(estad2.NumStops)
        AKIPrintString(astring)
        astring = "		 LongQueueAvg : " + str(estad2.LongQueueAvg)
        AKIPrintString(astring)
        astring = "		 LongQueueMax : " + str(estad2.LongQueueMax)
        AKIPrintString(astring)

    estad = AKIEstGetParcialStatisticsSystem(timeSta, carPosition)
    if (estad.report==0):
        AKIPrintString("		 SISTEMA CARRO
")
        astring = "		 Relatório : " + str(estad.report)
        AKIPrintString(astring)
        astring = "		 Fluxo : " + str(estad.Flow)
        AKIPrintString(astring)
        astring = "		 Tempo de Viagem : " + str(estad.TTa)
        AKIPrintString(astring)
        astring = "		 Tempo de Atraso : " + str(estad.DTa)
        AKIPrintString(astring)
        astring = "		 Velocidade : " + str(estad.Sa)
        AKIPrintString(astring)
        astring = "		 Tempo de Parada : " + str(estad.STa)
        AKIPrintString(astring)
        astring = "		 NumParadas : " + str(estad.NumStops)
        AKIPrintString(astring)

    estad2 = AKIEstGetParcialStatisticsSection(1, timeSta, carPosition)
    if (estad2.report==0):
        AKIPrintString("		 SEÇÃO CARRO
")
        astring = "		 Relatório : " + str(estad2.report)
        AKIPrintString(astring)
        astring = "		 Fluxo : " + str(estad2.Flow)
        AKIPrintString(astring)
        astring = "		 Tempo de Viagem : " + str(estad2.TTa)
        AKIPrintString(astring)
        astring = "		 Tempo de Atraso : " + str(estad2.DTa)
        AKIPrintString(astring)
        astring = "		 Velocidade : " + str(estad2.Sa)
        AKIPrintString(astring)
        astring = "		 Tempo de Parada : " + str(estad2.STa)
        AKIPrintString(astring)
        astring = "		 NumParadas : " + str(estad2.NumStops)
        AKIPrintString(astring)
        astring = "		 LongQueueAvg : " + str(estad2.LongQueueAvg)
        AKIPrintString(astring)
        astring = "		 LongQueueMax : " + str(estad2.LongQueueMax)
        AKIPrintString(astring)

    return 0

def AAPIFinish():
    estad = AKIEstGetGlobalStatisticsSystem(0)
    if (estad.report==0):
        AKIPrintString("		 SISTEMA
")
        astring = "		 Relatório : " + str(estad.report)
        AKIPrintString(astring)
        astring = "		 Fluxo : " + str(estad.Flow)
        AKIPrintString(astring)
        astring = "		 Tempo de Viagem : " + str(estad.TTa)
        AKIPrintString(astring)
        astring = "		 Tempo de Atraso : " + str(estad.DTa)
        AKIPrintString(astring)
        astring = "		 Velocidade : " + str(estad.Sa)
        AKIPrintString(astring);
        astring = "		 Tempo de Parada : " + str(estad.STa)
        AKIPrintString(astring);
        astring = "		 NumParadas : " + str(estad.NumStops)
        AKIPrintString(astring)

    estad2 = AKIEstGetGlobalStatisticsSection(1, 0)
    if (estad2.report==0):
        AKIPrintString("		 SEÇÃO
")
        astring = "		 Relatório : " + str(estad2.report)
        AKIPrintString(astring)
        astring = "		 Fluxo : " + str(estad2.Flow)
        AKIPrintString(astring)
        astring = "		 Tempo de Viagem : " + str(estad2.TTa)
        AKIPrintString(astring)
        astring = "		 Tempo de Atraso : " + str(estad2.DTa)
        AKIPrintString(astring)
        astring = "		 Velocidade : " + str(estad2.Sa)
        AKIPrintString(astring)
        astring = "		 Tempo de Parada : " + str(estad2.STa)
        AKIPrintString(astring)
        astring = "		 NumParadas : " + str(estad2.NumStops)
        AKIPrintString(astring)
        astring = "		 LongQueueAvg : " + str(estad2.LongQueueAvg)
        AKIPrintString(astring)
        astring = "		 LongQueueMax : " + str(estad2.LongQueueMax)
        AKIPrintString(astring)

    return 0

def AAPIUnLoad():
    return 0

def AAPIEnterVehicle(idveh,idsection):
    return 0

def AAPIExitVehicle(idveh,idsection):
    return 0