Traffic Assignment examples

Examples on how to configure a traffic assignment

Here we provide you with a number of examples to set-up your PLANit traffic assignment instance.

Prerequisites:

Note that the required Java imports are not listed in these examples as it is expected that the user has access to an IDE (like Eclipse), where this is added to the Java file automatically upon usage.

Note that currently the only traffic assignment implementation available is traditional static assignment. Hence all examples adopt this implementation.

Example Name Description
1 Simple traffic assignment Example of setting up a simple assignment
2 regular traffic assignment Example of setting up a regular assignment
3 Smoothing component Example of setting up the smoothing component
4 Physical cost component Example of setting up the physical cost component
5 Virtual cost component Example of setting up the virtual cost component
6 Gap function Example of setting up the gap function component
6 Stop criterion Example of setting up the stop criterion component

For all examples we adopt the following defaults, and/or settings regarding other components, unless indicated otherwise:

Simple assignment

All assignments have defaults for almost all underlying components. So, you can create a very minimalistic assignment very easily as is demonstrated here. We refer the reader to the JavaDoc for the relevant defaults.

for this simple assignment we utilise a PLANitSimpleProject. This avoids the need for stating which network, demands, and zoning are to be used since their will only be one of each available.


try{
	// create a simple PLANit project, source inputs from directory java instance was run 
	final PlanItSimpleProject simpleProject = new PlanItSimpleProject();
	
	// set traditional static assignment as our type
	project.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);

	// run
  	project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}

Regular assignment

This example achieves the exact same thing as the previous example. Only now, the user must explicitly link the input components that are parsed on the project level (network, zoning, and demands) and register them with the assignment.

If you only conduct a single assignment this has little benefit. However, if you run many assignments, with different networks for example, then this is much more flexible . Instead of parsing the same inputs over and over, you parse the inputs once on the project level and reuse them for different assignments.


try {
  // Create a custom PLANit project with all the default settings
  final PlanItProject project = new PlanItProject("<insert the project path here>");
  
  // *NEW*
  PhysicalNetwork network = project.createAndRegisterPhysicalNetwork(PhysicalNetwork.MACROSCOPICNETWORK);
  
  // *NEW*
  Zoning zoning = project.createAndRegisterZoning(network);
  
  // *NEW*
  Demands demands = project.createAndRegisterDemands(zoning, network);      

  // *NEW*
  project.createAndRegisterTrafficAssignment(
      TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT,
      demands,
      zoning,
      network);

  project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}

Smoothing component

This example shows how to set a particular smoothing type on the assignment. Whenever the type is chosen, the object instance is created and returned for further configuration. See the Javadoc for details for each of the available smoothing implementations.


try {

  final PlanItSimpleProject project = new PlanItSimpleProject();
  
  TrafficAssignmentBuilder taBuilder = project.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW *
  // set MSA Smoothing as the type
  // instance is returned for follow up configuration
  MSASmoothing smoothing = (MSASmoothing) taBuilder.createAndRegisterSmoothing(Smoothing.MSA);
  // smoothing.callAMethod()  

  project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}

Physical cost component

This example shows how to set a particular Physical cost type on the assignment. Physical cost applies to all physical road infrastructure, but does not consider virtual constructs such as connector links. Whenever the type is chosen, the object instance is created and returned for further configuration. See the Javadoc for details for each of the available physical cost implementations.

Note for traditional static assignment, link performance functions can be chosen here, such as the BPR function.


try {

  final PlanItSimpleProject project = new PlanItSimpleProject();
  
  TrafficAssignmentBuilder taBuilder = project.createAndRegisterTrafficAssignment(
    TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW *
  // set BPR link performance function as the type
  BPRLinkTravelTimeCost bprCost = 
    (BPRLinkTravelTimeCost) taBuilder.createAndRegisterPhysicalCost(PhysicalCost.BPR);
  // override default alpha and beta parameters
  bprCost.setDefaultParameters(0.5, 5); 

  project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}

Virtual cost component

This example shows how to set a particular Virtual cost type on the assignment. Virtual cost applies to the non-physical road infrastructure such as connector links. Whenever the type is chosen, the object instance is created and returned for further configuration. See the Javadoc for details for each of the available virtual cost implementations.


try {

  final PlanItSimpleProject project = new PlanItSimpleProject();
  
  TrafficAssignmentBuilder taBuilder = project.createAndRegisterTrafficAssignment(
    TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW *
  // set speed based virtual cost function as the type
  SpeedConnectoidTravelTimeCost virtualCost =
    (SpeedConnectoidTravelTimeCost) taBuilder.createAndRegisterVirtualCost(VirtualCost.SPEED);
  // set default speed to 25 km/h
  virtualCost.setConnectiodSpeed(25);

  project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}

Gap function component

This example shows how to get access to the gap function component

Currently, there is only a single implementation of the gap function. It cannot be set by the user but is available by default.

try {

  final PlanItSimpleProject project = new PlanItSimpleProject();
  
  TrafficAssignmentBuilder taBuilder = project.createAndRegisterTrafficAssignment(
    TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
    
  // * NEW *
  // check type of default created gap function
  if(taBuilder.getGapFunction() instanceof LinkBasedRelativeDualityGapFunction) {
    System.out.println("Link based relative duality gap used as gap function");
  }else {
    System.out.println("unknown gap function");
  }

  project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}

Stop criterion component

This example shows how to get access and/or configure the stop criterion component

Currently, there is only a single implementation of the stop criterion. It cannot be set by the user. It is available by default via the gap function.


try {

  final PlanItSimpleProject project = new PlanItSimpleProject();
  
  TrafficAssignmentBuilder taBuilder = project.createAndRegisterTrafficAssignment(
    TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW *
  // access stop criterion via gap function and set max number of iterations to 100  
  taBuilder.getGapFunction().getStopCriterion().setMaxIterations(100);

  project.executeAllTrafficAssignments();
} catch (final Exception e) {
  // do something
}