Exemplo 9 da Micro API do Aimsun Next¶
Exemplo de Controle (Alteração dos tempos de fase)¶
Este exemplo mostra como usar funções da API do Aimsun Next para alterar os tempos de um plano de controle.
Baseia-se na rede do tutorial: Editing - Finished network. A API com as configurações atuais alterará os tempos do plano de controle "Control AM" para o nó 1541. Observe que o tipo do cruzamento controlado deve ser alterado de 'Fixed' para 'External'
Versão C++¶
#include "AKIProxie.h"
#include "CIProxie.h"
#include "ANGConProxie.h"
#include "AAPI.h"
#include <stdio.h>
int nodeId = 1541;
int controlPlanId = 1630;
int phaseToChange = 2;
double newTime = 16.0;
int previousPhase = -1;
double timeLastChange = -100.0;
int AAPILoad()
{
AKIPrintString("LOAD");
return 0;
}
int AAPIInit()
{
AKIPrintString("\tInit");
ANGConnEnableVehiclesInBatch(true);
return 0;
}
int AAPISimulationReady()
{
AKIPrintString("\tAAPISimulationReady");
return 0;
}
int AAPIManage(double time, double timeSta, double timTrans, double acicle)
{
//AKIPrintString("\tManage");
return 0;
}
int AAPIPostManage(double time, double timeSta, double timTrans, double acicle)
{
//AKIPrintString("\tPostManage");
int currentPhase = ECIGetCurrentPhase(nodeId);
if (currentPhase == phaseToChange && previousPhase != phaseToChange) //Change to target phase just happened
{
int disableReport = ECIDisableEvents(nodeId);
int timeChangeReport = ECIChangeTimingPhase(nodeId, phaseToChange, newTime, timeSta);
timeLastChange = time;
}
if (time == timeLastChange + newTime)
{
int enableEventsReport = ECIEnableEventsActivatingPhase(nodeId, phaseToChange + 1, 0.0, time);
timeLastChange = -100.0;
}
previousPhase = currentPhase;
return 0;
}
int AAPIFinish()
{
AKIPrintString("\tFinish");
return 0;
}
int AAPIUnLoad()
{
AKIPrintString("UNLOAD");
return 0;
}
int AAPIPreRouteChoiceCalculation(double time, double timeSta)
{
AKIPrintString("\tPreRouteChoice Calculation");
return 0;
}
int AAPIVehicleStartParking(int idveh, int idsection, double time)
{
return 0;
}
int AAPIActionActivated(int idAction)
{
return 0;
}
int AAPIActionDeactivated(int idAction)
{
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("A Pedestrian has entered the network");
return 0;
}
int AAPIExitPedestrian(int idPedestrian, int destinationCentroid)
{
AKIPrintString("A Pedestrian has exited the network");
return 0;
}
Versão Python¶
from AAPI import *
NODE_ID = 1541
PHASE_TO_CHANGE = 2 #Index of the phase we will be changing
NEW_TIME = 16
previousPhase = None
timeLastChange = -100.0
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):
global previousPhase, timeLastChange
# AKIPrintString( "AAPIPostManage" )
currentPhase = ECIGetCurrentPhase( NODE_ID )
if currentPhase == PHASE_TO_CHANGE and previousPhase != PHASE_TO_CHANGE:
ECIDisableEvents( NODE_ID ) #Take control from Aimsun Next
timeChangeReport = ECIChangeTimingPhase( NODE_ID, PHASE_TO_CHANGE, NEW_TIME, timeSta )
timeLastChange = time
if time == timeLastChange + NEW_TIME:
ECIEnableEventsActivatingPhase(NODE_ID, PHASE_TO_CHANGE +1, 0.0, time)
timeLastChange = -100.0
previousPhase = currentPhase
return 0
def AAPIFinish():
AKIPrintString( "AAPIFinish" )
return 0
def AAPIUnLoad():
AKIPrintString( "AAPIUnLoad" )
return 0
def AAPIPreRouteChoiceCalculation(time, timeSta):
return 0
def AAPIVehicleStartParking (idveh, idsection, time):
return 0
def AAPIActionActivated(idAction):
return 0
def AAPIActionDeactivated(idAction):
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