Aimsun Next Macroscopic Modeling Scripts¶
The Aimsun Next Macro Plug-in offers services to run a traffic assignment (single or multi user), to adjust an OD matrix using detection data, and to calculate the traversal matrix for an arbitrary area of the network.
To use the Macrosimulator features, first import their Python modules:
from PyMacroKernelPlugin import *
from PyMacroAdjustmentPlugin import *
from PyMacroToolPlugin import *
from PyMacroPTPlugin import *
from PyPTAdjustmentPlugin import *
The macroscopic features are available in the Aimsun Next Expert Edition, Aimsun Next Advanced Edition and Aimsun Next Pro TDM Edition.
Macro Assignment¶
To run an existing experiment:
- Get the macro experiment (in this example, using its identifier).
- Execute the action that runs the experiment.
as shown in the example below:
experiment = model.getCatalog().find( 720 )
selection = []
GKSystem.getSystem().executeAction( "execute", experiment, selection, "static assignment")
The GKSystem.getSystem().executeAction() method runs the execute action on the experiment (id 720) and the objects in selection list(here, that list is empty) The action task unique identifier is set to "static assignment".
The experiment.getStatsManager().createTrafficState() method is then be used to create traffic states using the experiment results:
experiment.getStatsManager().createTrafficState()
Retrieving assignment results from database¶
To retrieve assignment results from database, call the retrieve action:
experiment = model.getCatalog().find( 720 )
selection = []
GKSystem.getSystem().executeAction( "retrieve", experiment, selection, "static assignment retrieve")
Retrieving paths from an APA file¶
To retrieve paths from an APA file, call the retrievePaths action:
experiment = model.getCatalog().find( 720 )
selection = []
GKSystem.getSystem().executeAction( "retrieve_paths", experiment, selection, "")
Example: Matrix Adjustment¶
To perform a demand adjustment:
- Get the experiment.
- Configure the adjustment parameters.
- Execute the adjustment.
- Save the adjusted matrices.
as shown in the example below using experiment 720 and a detector grouping ID 762:
experiment = model.getCatalog().find( 720 )
scenario = experiment.getScenario()
parameters = scenario.getParams()
experiment.setOuterIterations( 10 )
experiment.setGradientDescentIterations( 10 )
parameters.setDetectorGrouping( 762 )
GKSystem.getSystem().executeAction( "execute_adj", experiment, [], "" )
experiment.getOutput().publishMatrices( model )
Example: Static OD departure adjustment¶
To perform a static OD departure adjustment:
- Get the static OD departure adjustment experiment.
- Call the "execute" kernel action.
as shown in the example below using experiment 720
depAdtExperiment = model.getCatalog().find( 1001 )
GKSystem.getSystem().executeAction( "execute", depAdtExperiment, [], "" )
Example: Macro Transit Assignment¶
To run a static Transit Assignment:
- Get the Transit Assignment Experiment (in this example, using its identifier).
- Call the "execute" kernel action.
macroPtExperiment = model.getCatalog().find( 1001 )
GKSystem.getSystem().executeAction( "execute", macroPtExperiment, [], "" )
To retrieve the data of a static Transit Assignment:
- Get the Transit Assignment Experiment (in this example, using its identifier).
- Call the "retrieve" kernel action or "retrieve_and_show" if the retrieved results should be displayed in the UI.
macroPtExperiment = model.getCatalog().find( 1001 )
GKSystem.getSystem().executeAction( "retrieve", macroPtExperiment, [], "" )
To retrieve the paths of a static Transit assignment:
- Get the Transit Assignment Experiment (in this example, using its identifier).
- Call the "retrieve_paths" kernel action.
macroPtExperiment = model.getCatalog().find( 1001 )
GKSystem.getSystem().executeAction( "retrieve_paths", macroPtExperiment, [], "" )
Example: Macro Transit Adjustment¶
To run a static Transit OD Adjustment:
- Get the Transit OD Adjustment Experiment (in this example, using its identifier).
- Call the "execute" kernel action.
macroPtAdjExperiment = model.getCatalog().find( 1001 )
GKSystem.getSystem().executeAction( "execute", macroPtAdjExperiment, [], "" )
To access the Adjustment results and publish the adjusted demand and matrices
- Get the Transit OD Adjustment Experiment (in this example, using its identifier).
- Access its result.
- From the result, either create the adjusted demand (and its matrices) or access to the user classes and create the matrices per user.
macroPtAdjExperiment = model.getCatalog().find( 1001 )
macroPTAdjustmentResults = macroPtAdjExperiment.getResult()
macroPTAdjustmentResults.publishAdjustedDemand( model )
`````
Example: Static traversal calculation¶
To perform a static traversal calculation:
- Get the experiment.
- Get the subnetwork from which the traversal will be created.
- Configure the traversal calculation parameters.
- Execute the traversal calculation.
as shown in the example below:
from PyMacroToolPlugin import *
experiment = model.getCatalog().find( 720 )
subNet = model.getCatalog().find( 675 )
plugin = GKSystem.getSystem().getPlugin( "MacroToolsPlugin" )
parameters = MacroTraversalPars( problemNet, experiment, MacroTraversalPars.eOriginal )
plugin.traversal( parameters, "" )