Skip to content

Exemplo da API Micro Aimsun Next 10

Exemplo de informações do Detector

Este exemplo mostra como usar as funções da API Aimsun Next para ler e imprimir no log informações dos detectores.

Esta API é baseada na rede do tutorial: Edição - Rede Finalizada.

Versão C++

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

int detectorId = 1571;

int AAPILoad()
{
    AKIPrintString("CARREGAR");
    return 0;
}

int AAPIInit()
{
    AKIPrintString("	Iniciar");
    ANGConnEnableVehiclesInBatch(true);
    return 0;
}
int AAPISimulationReady()
{
    AKIPrintString("	AAPISimulationReady");
    return 0;
}

int AAPIManage(double time, double timeSta, double timTrans, double acicle)
{
    //AKIPrintString("	Gerenciar");
    return 0;
}

int AAPIPostManage(double time, double timeSta, double timTrans, double acicle)
{
    char astring[128];
    //AKIPrintString("	Pós Gerenciar");
    int instantDetection = AKIDetGetPresenceInstantDetectionbyId(detectorId, 0, time);
    double instantOccupiedTime = AKIDetGetTimeOccupiedInstantDetectionbyId(detectorId, 0, time);
    int vehiclesDetectedCount = AKIDetGetCounterCyclebyId(detectorId, 0);
    double instantSpeed = AKIDetGetSpeedInstantDetectionbyId(detectorId, 0, time);
    double instantDensity = AKIDetGetDensityInstantDetectionbyId(detectorId, 0, time);
    int counterAggregated = AKIDetGetCounterAggregatedbyId(detectorId, 0);
    double speedAggregated = AKIDetGetSpeedAggregatedbyId(detectorId, 0);
    double occupancyAggregated = AKIDetGetTimeOccupiedAggregatedbyId(detectorId, 0);
    int presenceAggregated = AKIDetGetPresenceAggregatedbyId(detectorId, 0);
    if (instantDetection > 0.0){
        snprintf(astring, 128, "		 ------------------Detector %d MEDIDAS INSTANTÂNEAS------------------:", detectorId);
        AKIPrintString(astring);
        snprintf(astring, 128, "Detecção %d", instantDetection);
        AKIPrintString(astring);
        snprintf(astring, 128, "Tempo ocupado %g", instantOccupiedTime);
        AKIPrintString(astring);
        snprintf(astring, 128, "Veículos detectados %d", vehiclesDetectedCount);
        AKIPrintString(astring);
        snprintf(astring, 128, "Velocidade %f", instantSpeed);
        AKIPrintString(astring);
        snprintf(astring, 128, "Densidade %f", instantDensity);
        AKIPrintString(astring);
        if (counterAggregated > 0){
            snprintf(astring, 128, "Contagem Agregada %d", counterAggregated);
            AKIPrintString(astring);
            snprintf(astring, 128, "Velocidade Agregada %f", speedAggregated);
            AKIPrintString(astring);
            snprintf(astring, 128, "Ocupação Agregada %f", occupancyAggregated);
            AKIPrintString(astring);
            snprintf(astring, 128, "Presença Agregada %d", presenceAggregated);
            AKIPrintString(astring);
        }
    }
    return 0;
}

int AAPIFinish()
{
    AKIPrintString("	Finalizar");
    return 0;
}

int AAPIUnLoad()
{
    AKIPrintString("DESCARREGAR");
    return 0;
}

int AAPIPreRouteChoiceCalculation(double time, double timeSta)
{
    AKIPrintString("	Cálculo de Pré-Escolha de Rota");
    return 0;
}

int AAPIVehicleStartParking(int idveh, int idsection, double time)
{
return 0;
}

int AAPIEnterVehicle(int idveh, int idsection)
{
    return 0;
}

int AAPIExitVehicle(int idveh, int idsection)
{
    return 0;
}

int AAPIEnterVehicleSection(int idveh, int idsection, double atime)
{
    return 0;
}

int AAPIExitVehicleSection(int idveh, int idsection, double time)
{
    return 0;
}

int AAPIEnterPedestrian(int idPedestrian, int originCentroid)
{
    AKIPrintString("Um Pedestre entrou na rede");
    return 0;
}

int AAPIExitPedestrian(int idPedestrian, int destinationCentroid)
{
    AKIPrintString("Um Pedestre saiu da rede");
    return 0;
}

Versão Python

from AAPI import *

DETECTOR_IDS = [1571]

def AAPILoad():
    AKIPrintString( "AAPILoad" )
    return 0

def AAPIInit():
    AKIPrintString( "AAPIInit" )
    return 0
def AAPISimulationReady():
    AKIPrintString( "AAPISimulationReady" )
    return 0
def AAPIManage(time, timeSta, timeTrans, acycle):
    # AKIPrintString( "AAPIManage" )
    return 0

def AAPIPostManage(time, timeSta, timeTrans, acycle):
    for detectorId in DETECTOR_IDS:
        instantDetection = AKIDetGetPresenceInstantDetectionbyId( detectorId, 0, time)
        instantOccupiedTime = AKIDetGetTimeOccupiedInstantDetectionbyId( detectorId, 0, time )
        vehiclesDetectedCount = AKIDetGetCounterCyclebyId(detectorId, 0)
        instantSpeed = AKIDetGetSpeedInstantDetectionbyId( detectorId, 0, time)
        instantDensity =AKIDetGetDensityInstantDetectionbyId( detectorId, 0, time)
        counterAggregated = AKIDetGetCounterAggregatedbyId( detectorId, 0)
        speedAggregated = AKIDetGetSpeedAggregatedbyId( detectorId, 0)
        occupancyAggregated = AKIDetGetTimeOccupiedAggregatedbyId( detectorId, 0)
        presenceAggregated = AKIDetGetPresenceAggregatedbyId(detectorId, 0 )
        if instantDetection >0:
            AKIPrintString( "------------------ Detector " + str(detectorId) + " MEDIDAS INSTANTÂNEAS ------------------" )
            AKIPrintString( "detecção %s"%instantDetection )
            AKIPrintString( "Tempo Ocupado (Porcentagem) %s"%instantOccupiedTime )
            AKIPrintString( "%s Veículos no último ciclo"%vehiclesDetectedCount )
            AKIPrintString( "Velocidade: " + str(instantSpeed) )
            AKIPrintString( "Densidade: " + str(instantDensity) )
            if counterAggregated > 0: #Estatísticas agregadas estão disponíveis apenas após o primeiro intervalo de estatísticas
                AKIPrintString( "------------------ Detector " + str(detectorId) + " MEDIDAS AGREGADAS ------------------" )
                AKIPrintString( "Contagem: " + str( counterAggregated ) )
                AKIPrintString( "Velocidade: " + str( speedAggregated ) )
                AKIPrintString( "Ocupação: " + str( occupancyAggregated ) )
                AKIPrintString( "Presença: " + str( presenceAggregated ) )

    return 0

def AAPIFinish():
    AKIPrintString( "AAPIFinish" )
    return 0

def AAPIUnLoad():
    AKIPrintString( "AAPIUnLoad" )
    return 0

def AAPIPreRouteChoiceCalculation(time, timeSta):
    AKIPrintString( "AAPIPreRouteChoiceCalculation" )
    return 0

def AAPIEnterVehicle(idveh, idsection):
    return 0

def AAPIExitVehicle(idveh, idsection):
    return 0

def AAPIEnterPedestrian(idPedestrian, originCentroid):
    return 0

def AAPIExitPedestrian(idPedestrian, destinationCentroid):
    return 0

def AAPIEnterVehicleSection(idveh, idsection, atime):
    return 0

def AAPIExitVehicleSection(idveh, idsection, atime):
    return 0

def AAPIVehicleStartParking (idveh, idsection, time):
    return 0