Pular para o conteúdo

Exemplo 7 da Micro API do Aimsun Next:

Exemplo de uma conexão ANG (atualizando um atributo de veículo de simulação ANG)

Este exemplo mostra como criar um novo atributo "VehStatus" (como um inteiro) no objeto ANG Simulation Vehicle e, em seguida, definir um valor dependendo da seção onde o veículo está localizado (na seção 241 o atributo é definido como 1, enquanto na seção 250 é definido como 2).

Versão C++

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

void * vehStatusAtt;

// Procedures could be modified by the user
int AAPILoad()
{   
    return 0;
}

int AAPIInit()
{   
    ANGConnEnableVehiclesInBatch(true);
//getting the attributes by name. A UNICODE conversion is required by using AKIConvertFromAsciiString method
    vehStatusAtt = ANGConnCreateAttribute( AKIConvertFromAsciiString("GKSimVehicle"),
                    AKIConvertFromAsciiString("GKSimVehicle::VehStatusInt"),
                    AKIConvertFromAsciiString("Vehicle Status"), INTEGER_TYPE, EXTERNAL);
    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)
{ 
    int         nbvehs, i, idVehANG;
    InfVeh      infveh;

    nbvehs = AKIVehStateGetNbVehiclesSection(241, true);
    for (i=0; i< nbvehs; i++) {
        infveh = AKIVehStateGetVehicleInfSection(241,i);
        if (infveh.report>=0) {
            idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh);
            if ( idVehANG > 0 ) {
                ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 1);
            }
        }
    }
    nbvehs = AKIVehStateGetNbVehiclesSection(250, true);
    for (i=0; i< nbvehs; i++) {
        infveh = AKIVehStateGetVehicleInfSection(250,i);
        if (infveh.report>=0) {
            idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh);
            if ( idVehANG > 0 ) {
                ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 2);
            }
        }
    }
    return 0;
}

int AAPIFinish()
{
    return 0;
}

int AAPIUnLoad()
{
    return 0;
}

Versão Python

from AAPI import *

def AAPILoad():
    return 0

def AAPIInit():
    ANGConnEnableVehiclesInBatch(True);
    # getting the attributes by name. A UNICODE conversion is required by using AKIConvertFromAsciiString method
    global vehStatusAtt
    vehStatusAtt = ANGConnCreateAttribute( AKIConvertFromAsciiString("GKSimVehicle"),
                    AKIConvertFromAsciiString("GKSimVehicle::VehStatusInt"),
                    AKIConvertFromAsciiString("Vehicle Status"), 1, 2)
    return 0

def AAPISimulationReady():
    return 0

def AAPIManage(time, timeSta, timeTrans, acycle):
    return 0

def AAPIPostManage(time, timeSta, timeTrans, acycle):
    nbvehs = AKIVehStateGetNbVehiclesSection(241, True)
    for i in range(0, nbvehs):
        infveh = AKIVehStateGetVehicleInfSection(241,i)
        if infveh.report >= 0 :
            idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh)
            if idVehANG > 0:
                ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 1)
    nbvehs = AKIVehStateGetNbVehiclesSection(250, True)
    for i in range(0, nbvehs):  
        infveh = AKIVehStateGetVehicleInfSection(250,i)
        if infveh.report >= 0:
            idVehANG = ANGConnVehGetGKSimVehicleId(infveh.idVeh)
            if idVehANG > 0:
                ANGConnSetAttributeValueInt(vehStatusAtt, idVehANG, 2)
    return 0

def AAPIFinish():
    return 0

def AAPIUnLoad():
    return 0