Exemplo 8 da Micro API do Aimsun Next¶
Exemplo de Controle (Prioridade de Ônibus em uma interseção)¶
Este exemplo mostra como usar a função da API do Aimsun Next para gerenciar o plano de controle de modo que os ônibus que se aproximam de um cruzamento tenham sinal verde quando chegarem ao cruzamento. Depois que o ônibus sai do cruzamento, o plano de controle é restaurado para o estado em que a chamada do ônibus foi detectada.
Versão C++¶
#include "AKIProxie.h"
#include "CIProxie.h"
#include "ANGConProxie.h"
#include "AAPI.h"
#include <stdio.h>
double previousPhaseIndex, previousPhaseTime;
// Procedures could be modified by the user
int AAPILoad()
{
return 0;
}
int AAPIInit()
{
ANGConnEnableVehiclesInBatch(true);
previousPhaseIndex = -1;
previousPhaseTime = -1;
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 busPhase = 3;
int intersection = 203;
int busCallDetector = 383;
int busExitDetector = 378;
//get bus internal position
int busVehiclePosition = AKIVehGetVehTypeInternalPosition( 9 );
int currentPhase = ECIGetCurrentPhase( intersection );
//check bus presence over busCallDetector
if( AKIDetGetCounterCyclebyId( busCallDetector, busVehiclePosition ) > 0 && currentPhase != busPhase && previousPhaseIndex == -1){
AKIPrintString( "bus detected");
#change the control to bus phase
previousPhaseIndex = currentPhase;
previousPhaseTime = time - ECIGetStartingTimePhase( intersection );
ECIChangeDirectPhase( intersection, busPhase, timeSta, time, acycle, 0 );
}
//check bus presence over busExitDetector
if( AKIDetGetCounterCyclebyId( busExitDetector, busVehiclePosition ) > 0 ){
//go back to previous phase
if( previousPhaseIndex > 0 ){
AKIPrintString( "go back to previous state");
ECIChangeDirectPhase( intersection, previousPhaseIndex, timeSta, time, acycle, previousPhaseTime);
previousPhaseIndex = -1;
previousPhaseTime = -1;
}
}
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, timeTrans, acycle):
return 0
def AAPIPostManage(time, timeSta, timeTrans, acycle):
global previousPhaseIndex
global previousPhaseTime
busPhase = 3
intersection = 203
busCallDetector = 383
busExitDetector = 378
#get bus internal position
busVehiclePosition = AKIVehGetVehTypeInternalPosition( 9 )
currentPhase = ECIGetCurrentPhase( intersection )
#check bus presence over busCallDetector
if AKIDetGetCounterCyclebyId( busCallDetector, busVehiclePosition ) > 0 and currentPhase != busPhase and previousPhaseIndex == -1:
print "bus detected"
#change the control to bus phase
previousPhaseIndex = currentPhase
previousPhaseTime = time - ECIGetStartingTimePhase( intersection )
ECIChangeDirectPhase( intersection, busPhase, timeSta, time, acycle, 0 )
#check bus presence over busExitDetector
if AKIDetGetCounterCyclebyId( busExitDetector, busVehiclePosition ) > 0:
#go back to previous phase
if previousPhaseIndex > 0:
print "go back to previous state"
ECIChangeDirectPhase( intersection, previousPhaseIndex, timeSta, time, acycle, previousPhaseTime)
previousPhaseIndex = -1
previousPhaseTime = -1
return 0
def AAPIFinish():
return 0
def AAPIUnLoad():
return 0
previousPhaseIndex = -1
previousPhaseTime = -1