Skip to content

Aimsun Next Micro API Example 4

Example of Incident Generation

This example shows how to implement incident generation. It generates two incidents, then it removes the first one.

C++ Version

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

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

int AAPIInit()
{   
    AKIGenerateIncident(329, 1, 150.0f, 1.0f, AKIGetIniSimTime()+5.0f, 300.0f, 200.0f, true, true, 200.0f, 200.0f, 50.0f);
    AKIGenerateIncident(329, 2, 150.0f, 1.0f, AKIGetIniSimTime()+5.0f, 300.0f, 200.0f, true, true, 200.0f, 200.0f, 50.0f);
    return 0;
}

int AAPISimulationReady()
{
    return 0;
}

int AAPIManage(double time, double timeSta, double timeTrans, double acycle)
{

    if (time >= 400){
        AKIRemoveIncident(329, 1, 150);
        AKIRemoveIncident(329, 2, 150);
}

    return 0;
}

int AAPIPostManage(double time, double timeSta, double timeTrans, double acycle)
{ 
    return 0;
}

int AAPIFinish()
{
    AKIResetAllIncidents();
    return 0;
}

int AAPIUnLoad()
{
    return 0;
}

Python Version

from AAPI import *

def AAPILoad():
    return 0

def AAPIInit():
    AKIGenerateIncident(329, 1, 150, 1, AKIGetIniSimTime() + 5, 300, 200, True, True, 200, 200, 50);
    AKIGenerateIncident(329, 2, 150, 1, AKIGetIniSimTime() + 5, 300, 200, True, True, 200, 200, 50);
    return 0

def  AAPISimulationReady():
    return 0

def AAPIManage(time, timeSta, timTrans, SimStep):
    if (time >= 400):
        AKIRemoveIncident(329, 1, 150)
        AKIRemoveIncident(329, 2, 150)
    return 0
def AAPIPostManage(time, timeSta, timTrans, SimStep):
    return 0

def AAPIFinish():
    AKIResetAllIncidents()
    return 0

def AAPIUnLoad():
    return 0

def AAPIEnterVehicle(idveh,idsection):
    return 0

def AAPIExitVehicle(idveh,idsection):
    return 0