Skip to content

Exemplo da API Micro Aimsun Next 1

Exemplo 1: Obtendo Informações sobre Veículos

Este exemplo permite obter as informações de cada veículo dentro do sistema para cada passo de 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 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);
            snprintf(astring, 128, "Veículo %d , Seção %d , Faixa %d, PosiçãoAtual %f, VelocidadeAtual %f
",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);
            snprintf(astring, 128, "Veículo %d , Nó %d , De %d, Para %d, PosiçãoAtual %f, VelocidadeAtual %f
", 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;
}

Versão Python

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 = "Veículo " + str(infVeh.idVeh) + ", Seção " + str(infVeh.idSection) + " , Faixa " + str(infVeh.numberLane) + ", PosiçãoAtual " + str(infVeh.CurrentPos) + ", VelocidadeAtual " + 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 = "Veículo " + str(infVeh.idVeh) + ", Nó " + str(infVeh.idJunction) + " , De " +  str(infVeh.idSectionFrom) + ", Para " + str(infVeh.idSectionTo) + ", PosiçãoAtual " + str(infVeh.CurrentPos) + ", VelocidadeAtual " + 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