How to set different speed limits for different vehicle types in Aimsun Next

Technical Note #52

October 2020

By Tessa Hayman

Many modelers aren’t aware of this incredibly useful feature in Aimsun Next. In this technical note, Tessa Hayman reveals how to set different speed limits for different vehicle types in dynamic models.

In certain situations, the speed limit for each vehicle type is different. For instance, on a single-carriageway road in the UK, vehicles over 7.5 tonnes can only travel at 50 miles per hour but other vehicles can travel at 60 miles per hour. You can code this in Aimsun Next through the use of traffic management for microscopic and mesoscopic models, or within the delay functions for macroscopic models.

 

 

For microscopic and mesoscopic models, the speed for a road is set by the “Speed Limit” parameter. This can be reduced for a vehicle class through using a traffic management action called “Speed Reduction”, which you can also use to reduce turn speeds for larger vehicles.

 

 

 

How to add a speed reduction action to one section/turn

Step 1: Add a traffic condition by going to the Project menu > Traffic Management > New > Traffic Condition

 

 

Step 2: Double-click on the Traffic Condition to open it. Select Activation Condition: Always and Apply to Warm up.

 

 

 

 

Traffic Condition parameters
Traffic Condition parameters

 

 

 

Step 3: Add a speed reduction action by right-clicking the Traffic Condition > New > Speed Reduction

 

 

 

 

How to set different speed limits for different vehicle types in Aimsun Next

 

 

Step 4: Select the speed reduction parameters.

 

 

 

 

How to set different speed limits for different vehicle types in Aimsun Next

 

 

In the speed reduction menu, you can specify which section/turn the action is applied to, what the new speed will be and choose to apply the action only to a certain vehicle class. In the example above, the Heavy class has been chosen which includes all vehicle types with vehicles over 7.5t.

 

 

The above method is valid for one section or one turn at a time; this would be an arduous task for a model with a large number of roads where HGVs have different speed limits. However, you can also choose to apply a speed change to a grouping of sections, a grouping of turns or a road type.

 

 

 

Applying Speed reduction for all sections in a road type with a set number of lanes using a script

However, it may be the case that you want to apply a speed reduction to a subset of sections for a road type such as single-carriageway roads with a 60-mile-per-hour speed limit without having these be a separate road type.

 

 

The following script can be used to apply a speed reduction action for a given road type while also checking the number of lanes in the section. You need to specify the Traffic Condition name, new speed, vehicle class and road type and number of lanes for which the new speed would apply. The script will then iterate over all sections in the model of the specified road type and add a speed reduction action for each one.

 

 

The pseudocode for this is:
Get/Create Traffic Condition
Get vehicle class
For all sections:

If section.roadtype==roadtype and section.numberoflanes:

Create speed reduction action
Add speed reduction to Traffic Condition

 

				
					'''This script applies a speed reduction for all sections in a road type. The User must specify the road type and the new speed'''

TrafficConditionName="Speed Reduction"
RoadTypeName="SingleCarriageway60" #96kph
VehicleClassName="Heavy Class"
NewSpeed=80 #50mph
NumberofLanes=1

def createSpeedReduction(section,Speed, VehicleClassname): #Add a speed reduction action
	change = GKSystem.getSystem().newObject("GKSpeedChange", model)
	change.setSection(section)
	change.setSpeed(str(Speed)) #set the new speed
	VehicleClassType=model.getType("GKVehicleClass")
	VehicleClass=model.getCatalog().findByName(VehicleClassname,VehicleClassType)
	change.setVehicleClass(VehicleClass) #add a filter for the vehicle class 
	return change

def NewTrafficCondition():#add a new TrafficConditionName
	cmd = model.createNewCmd( model.getType( "GKTrafficCondition" ))
	model.getCommander().addCommand( cmd )
	res = cmd.createdObject()
	res.setActivationType(GKSimulationEvent.eAlways) #set it to be active throughout the modelled period
	applyToWarmUpAtt = model.getColumn("GKPolicy::applyOnWarmupAtt") #set it to be active in the warm up
	res.setDataValue(applyToWarmUpAtt, QVariant(True))
	return res

def GetVehicleClass( model, name): # get the vehicle class object
	vehicleClassType=model.getType("GKVehicleClass")
	vehicleClass = model.getCatalog().findByName(name, vehicleClassType)
	if vehicleClass == None:
		print ("No Vehicle Class Found")
		return None
	return vehicleClass

condition=model.getCatalog().findByName(TrafficConditionName, model.getType("GKTrafficCondition"))

if condition==None: #find condition or add new one
	condition=NewTrafficCondition()
	condition.setName(TrafficConditionName)

sections=model.getCatalog().getObjectsByType(model.getType("GKSection")) 
for section in sections: #for all sections in road type, if the section has x lanes, make a new speed change in the given Traffic Condition
	section=sections[section]
	nooflanes=section.getNbFullLanes() #get the number of full lanes for this section 
	if section.getRoadType().getName()==RoadTypeName and nooflanes==NumberofLanes:
		speedreductionaction=createSpeedReduction(section,NewSpeed,VehicleClassName)
		speedreductionaction.setName("Speed reduction for section %s" %(section.getId()))
		condition.addChange(speedreductionaction)
		print ("new change")

print ("done")
				
			

Applying the Traffic Condition

Lastly, you need to apply the Traffic Condition to the Scenario, whether it has been added via a script or manually; open the scenario object and go to the Strategies and Conditions tab. Tick the new Traffic Condition.

 

 

 

Activating Traffic Condition in the Scenario
Activating Traffic Condition in the Scenario

More technical notes

Python: from function to attribute

August 2016: Most users are familiar with creating their own attributes within objects within an Aimsun model. Grant MacKinnon explains how you can also add a column to an object where a value is returned based on some Python Code, allowing you to calculate a value on the fly.

  • Got a question? Get in touch.

    We are here to help!

SHARE

Cite Aimsun Next

 

Aimsun Next 23

Aimsun (2023). Aimsun Next 23 User's Manual, Aimsun Next Version 23.0.0, Barcelona, Spain. Accessed on: July. 19, 2023. [Online].
Available: https://docs.aimsun.com/next/23.0.0/

 


 

Aimsun Next 20.0.5

Aimsun (2021). Aimsun Next 20.0.5 User's Manual, Aimsun Next Version 20.0.3, Barcelona, Spain. Accessed on: May. 1, 2021. [In software].
Available: qthelp://aimsun.com.aimsun.20.0/doc/UsersManual/Intro.html
 

Aimsun Next 23

@manual {​​​​​​​​AimsunManual,

title = {​​​​​​​​Aimsun Next 23 User's Manual}​​​​​,
author = {​​​​​​​​Aimsun}​​​​​​​​,
edition =  {​​​​​​​​​​​​​​​Aimsun Next 23.0.0}​​​​​​​​​​​​​​​,
address = {​​​​​​​​​​​​​​​Barcelona, Spain}​​​​​​​​​​​​​​​,
year  = {​​​​​​​​​​​​​​​2023. [Online]}​​​​​​​​​​​​​​​,
month = {​​​​​​​​​​​​​​​Accessed on: Month, Day, Year}​​​​​​​​​​​​​​​,
url = {​​​​​​​​​​​​​​​https://docs.aimsun.com/next/23.0.0/}​​​​​​​​​​​​​​​,
}​​​​​​​​​​​​​​​


Aimsun Next 20.0.5

@manual {​​​​​​​​AimsunManual,

title = {​​​​​​​​Aimsun Next 20.0.5 User's Manual}​​​​​​​​,
author = {​​​​​​​​Aimsun}​​​​​​​​,
edition =  {​​​​​​​​​​​​​​​Aimsun Next 20.0.5}​​​​​​​​​​​​​​​,
address = {​​​​​​​​​​​​​​​Barcelona, Spain}​​​​​​​​​​​​​​​,
year  = {​​​​​​​​​​​​​​​2021. [In software]}​​​​​​​​​​​​​​​,
month = {​​​​​​​​​​​​​​​Accessed on: Month, Day, Year}​​​​​​​​​​​​​​​,
url = {​​​​​​​​​​​​​​​qthelp://aimsun.com.aimsun.20.0/doc/UsersManual/Intro.html}​​​​​​​​​​​​​​​,
}​​​​​​​​​​​​​​​

Aimsun Next 23

TY  - COMP
T1  - Aimsun Next 23 User's Manual
A1  - Aimsun
ET - Aimsun Next Version 23.0.0
Y1  - 2023
Y2 - Accessed on: Month, Day, Year
CY  - Barcelona, Spain
PB  - Aimsun
UR  - [In software]. Available: https://docs.aimsun.com/next/23.0.0/


Aimsun Next 20.0.5

TY  - COMP
T1  - Aimsun Next 20.0.5 User's Manual
A1  - Aimsun
ET - Aimsun Next Version 20.0.5
Y1  - 2021
Y2 - Accessed on: Month, Day, Year
CY  - Barcelona, Spain
PB  - Aimsun
UR  - [In software]. Available: qthelp://aimsun.com.aimsun.20.0/doc/UsersManual/Intro.html