Aimsun Next Micro API Example 6¶
Example of ANG Connection (Creating a new attribute)¶
This example shows how to create a new attribute "Occupied" (as integer) in the section object and then set a value depending on the value of an attribute already defined (in that case the road type).
C++ Version¶
#include "AKIProxie.h"
#include "CIProxie.h"
#include "ANGConProxie.h"
#include "AAPI.h"
#include <stdio.h>
#include <string.h>
// Procedures could be modified by the user
int AAPILoad()
{
return 0;
}
int AAPIInit()
{
//getting the attributes by name. A UNICODE conversion is required by using AKIConvertFromAsciiString method
void * roadTypeAtt = ANGConnGetAttribute(
AKIConvertFromAsciiString("GKSection::roadTypeAtt") );
void * Occupied = ANGConnGetAttribute( AKIConvertFromAsciiString("GKSection::Occupied" ));
if (Occupied == NULL){
Occupied = ANGConnCreateAttribute( AKIConvertFromAsciiString("GKSection"),
AKIConvertFromAsciiString("GKSection::Occupied"),
AKIConvertFromAsciiString("Occupied"), INTEGER_TYPE, EXTERNAL);
}
int NbSections=AKIInfNetNbSectionsANG();
for(int i=0; i<NbSections;i++)
{
bool anyNonAsciiChar;
int SecId = AKIInfNetGetSectionANGId(i);
//getting the value
int roadTypeId = ANGConnGetAttributeValueInt( roadTypeAtt, SecId );
bool nonChar;
char* roadTypeName = AKIConvertToAsciiString( ANGConnGetObjectName(roadTypeId), false, &nonChar );
if (roadTypeName == "Parking" ){
ANGConnSetAttributeValueInt( Occupied, SecId, 1 );
}else{
ANGConnSetAttributeValueInt( Occupied, SecId, 0 );
}
}
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)
{
return 0;
}
int AAPIFinish()
{
return 0;
}
int AAPIUnLoad()
{
return 0;
}
Python Version¶
from AAPI import *
from PyANGKernel import *
def AAPILoad():
return 0
def AAPIInit():
model = GKSystem.getSystem().getActiveModel()
roadTypeAtt = ANGConnGetAttribute( AKIConvertFromAsciiString("GKSection::roadTypeAtt" ))
if roadTypeAtt!= None:
Occupied = ANGConnGetAttribute( AKIConvertFromAsciiString("GKSection::Occupied" ))
if Occupied == None:
Occupied = ANGConnCreateAttribute( AKIConvertFromAsciiString("GKSection"), AKIConvertFromAsciiString("GKSection::Occupied"), AKIConvertFromAsciiString("Occupied"), INTEGER_TYPE, EXTERNAL)
NbSections = AKIInfNetNbSectionsANG()
for i in range(0, NbSections):
SecId = AKIInfNetGetSectionANGId(i)
value = ANGConnGetAttributeValueInt( roadTypeAtt, SecId )
nonChar = boolp()
roadTypeName = AKIConvertToAsciiString( ANGConnGetObjectName(roadTypeId), False, nonChar )
if roadTypeName == "Parking" :
ANGConnSetAttributeValueInt( Occupied, SecId, 1 )
else:
ANGConnSetAttributeValueInt( Occupied, SecId, 0 )
return 0
def AAPISimulationReady():
return 0
def AAPIManage(time,timeSta,timTrans,acicle):
return 0
def AAPIPostManage(time,timeSta,timTrans,acicle):
return 0
def AAPIFinish():
return 0
def AAPIUnLoad():
return 0