Macro Function Components in Aimsun

Technical Note #14

March 2016
By Margarida Delgado

Imagine your cost functions have several components, such as distance, travel time or tolls. If you want to evaluate them all individually and show them as an output (in addition to the total cost) you can declare as many Macro Function Components as you need in order to produce each one of the extra Outputs when executing an Assignment.

You can create new Macro Function Components in the same folder as Cost Functions.

There are two types of Components: non-derived and derived.

Non-derived components are based on the evaluation of a part of the cost function (a subfunction), and it is detected by the Function String.


That is, the Macro Function Component editor will contain a key word that must correspond with the name of a subfunction (in all macro cost funtions: Volume Delay functions for sections, and Turning Penalty and Junction Delay for turns).

For example, to define the components ‘Distance (km)’ and ‘Time (h)’: in the Macro Function Component, set the Function String ‘distance’ and ‘time’ respectively as key words.

Now, we need to introduce the definition of these components in all macro cost functions (caution with turns, their default turning penalty is hard-coded so it contains no components) so that the component can be evaluated at all sections and turns. In the function code, the last function (in the images, ‘def vdf’ and ‘def tpf’) is the main one. Before that, we have defined the subfunctions ‘distance’ and ‘time’, which will be evaluated at the end of the assignment giving the extra columns of outputs.



Additionally, we can define Derived Components that result of the combination of other components. For example, we could define Speed as Distance/Time:



Derived Components imply no additional changes in the functions definition.
When executing an assignment, extra columns will be created, containing the values for each component.




Path assignment results also contain results for the Macro Function Components. Non-derived components are added along the path, while derived components are calculated with the non-derived path values (for example, if we define speed as derived, we don’t add the speeds through the path but calculate the total length/ total time).


And Skim and Output Matrices will also be available for each component:


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!


Cite Aimsun Next

Aimsun Next 24

Aimsun (2024). Aimsun Next 24 User’s Manual, Aimsun Next Version 24.0.0, Barcelona, Spain. Accessed on: April. 16, 2024. [Online].


Aimsun Next 24

@manual {AimsunManual,
title = {Aimsun Next 24 User’s Manual},
author = {Aimsun},
edition = {Aimsun Next 24.0.0},
address = {Barcelona, Spain},
year = {2024. [Online]},
month = {Accessed on: Month, Day, Year},
url = {},

Aimsun Next 24

T1 – Aimsun Next 24 User’s Manual
A1 – Aimsun
ET – Aimsun Next Version 24.0.0
Y1 – 2024
Y2 – Accessed on: Month, Day, Year
CY – Barcelona, Spain
PB – Aimsun
UR – [In software]. Available: