Initial cost examples

Examples on how to configure initial costs

Here we provide you with a number of examples to set-up initial costs in your PLANit project.

Initial costs can be provided across time periods or specific to a time period. Depending on which you use different factory and registration methods are available to you, most of which are detailed in the examples below.

Initial costs are registered on the project level and can be assigned to one or more traffic assignment instances. Therefore, the parsing of the initial costs occurs on the project level and then - in a second step - the user assigns the parsed initial costs to the relevant traffic assignment instance(s).

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.

Example Name Description
1 Basic link segment initial costs simplest example of setting up initial link segment costs
2 Link segment initial costs by time period Example of setting up initial link segment costs by time period
3 Link segment initial costs by time period (automatic) Example of setting up initial link segment costs by time period by automatically sourcing the periods from the demands
4 Hybrid initial link segment costs Example of setting up initial link segment costs with and without a time period

For all examples we utilise a PLANitProject, resulting in adopting the following defaults, unless indicated otherwise:

Minimum example

In this example, we parse initial link segments costs generated by an earlier generated CSV output file. This output file is consistent with the PLANit default output format and can be used as a source for initial costs.

  • The initial link segment costs are sourced from the Cost column in the CSV
  • The initial link segment costs are not attributed to a particular time period when parsed
  • The initial link segment costs are registered on the traffic assignment without attributing them to a particular time period either

By not relating the initial link segment costs to any specific time period, all time periods in the underlying demands will be initialised with these initial link segment costs. If you want to attribute the costs to a particular time period, see other examples where we do so.


final String initialCostCSVPath = "<insert the initial cost CSV file path here>";

try{
	 
  final PlanItSimpleProject simpleProject = new PlanItSimpleProject();
	
  // * NEW *
  final InitialLinkSegmentCost initialLinkSegmentCost = 
    project.createAndRegisterInitialLinkSegmentCost(project.getNetwork(), initialCostCSVPath);	

  TrafficAssignmentBuilder taBuilder = 
    project.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
	
  // * NEW *
  taBuilder.registerInitialLinkSegmentCost(initialLinkSegmentCost);
  
  project.executeAllTrafficAssignments();
  	
} catch (final Exception e) {
  // do something
}

Initial cost by time period

In this example, we parse initial link segments costs generated by an earlier generated CSV output file. This output file is consistent with the PLANit default output format and can be used as a source for initial costs.

  • The initial link segment costs are sourced from the Cost column in the CSV
  • The initial link segment costs are attributed to a particular time period when parsed
  • time periods are registered within the Demands instance that is populated automatically for a PLANitsimpleProject upon creation (it parses demands from input files expected to be available in the current working directory)
  • The initial link segment costs are registered on the traffic assignment and attributed to the time period

By relating the initial link segment costs to a specific time period, only the indicated time period will receive the initial link segment costs.

It is expected the time period on the project and the traffic assignment match, although technically this is not required.


try{
   
  final PlanItSimpleProject simpleProject = new PlanItSimpleProject();
  
  // * NEW *
  TimePeriod theTimePeriod = simpleProject.getDemands().timePeriods.getTimePeriodById(0);  
  InitialLinkSegmentCost initialLinkSegmentCost = 
    simpleProject.createAndRegisterInitialLinkSegmentCost(
      simpleProject.getNetwork(),"<insert the initial cost CSV file path here>", theTimePeriod);  

  TrafficAssignmentBuilder taBuilder = 
    simpleProject.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW *
  taBuilder.registerInitialLinkSegmentCost(theTimePeriod, initialLinkSegmentCost);
  
  simpleProject.executeAllTrafficAssignments();
    
} catch (final Exception e) {
  // do something
}

Initial cost by time period automatic

In this example, we parse initial link segments costs generated by an earlier generated CSV output file. This output file is consistent with the PLANit default output format and can be used as a source for initial costs.

  • The initial link segment costs are sourced from the Cost column in the CSV
  • The initial link segment costs are attributed to all time periods available in the provided Demands instance
  • Time periods are registered within the Demands instance that is populated automatically for a PLANitsimpleProject upon creation (it parses demands from input files expected to be available in the current working directory)
  • The initial link segment costs are registered on the traffic assignment and attributed to the time period

By relating the initial link segment costs to a specific time period, only the indicated time period will receive the initial link segment costs.

It is expected the time period on the project and the traffic assignment match, although technically this is not required.


try{
   
  final PlanItSimpleProject simpleProject = new PlanItSimpleProject();
  
  // * NEW * source time periods from Demands instance and register initial costs on each one
  List<InitialLinkSegmentCostPeriod> initialLinkSegmentCosts = 
    simpleProject.createAndRegisterInitialLinkSegmentCost(
      simpleProject.getNetwork(),"<insert the initial cost CSV file path here>", simpleProject.getDemands());  

  TrafficAssignmentBuilder taBuilder = 
    simpleProject.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW * register for all available time periods
  for(InitialLinkSegmentCostPeriod initialCost : initialLinkSegmentCosts) {
    taBuilder.registerInitialLinkSegmentCost(initialCost.getTimePeriod(), initialCost);
  }
  
  simpleProject.executeAllTrafficAssignments();
    
} catch (final Exception e) {
  // do something
}

Hybrid initial cost

In this example, we parse two different initial link segments costs generated by earlier generated CSV output files. Output files are consistent with the PLANit default output format and can be used as a source for initial costs.

  • The initial link segment costs are sourced from the Cost column in the CSV
  • the first initial link segment costs is not attributed to a time period
  • the second initial link segment cost is attributed to a time period
  • The initial link segment costs are registered on the traffic assignment and attributed to the time period (if any)

when a time period in the assignment is not present with any initial link segment cost, it reverts to the non-specific initial link segment costs, otherwise it will utilise the specific initial link segment costs

It is expected the time period on the project and the traffic assignment match, although technically this is not required.


final String initialCostCSVPath1 = "<insert the initial cost CSV file path1 here>";
final String initialCostCSVPath2 = "<insert the initial cost CSV file path2 here>";

try{
   
  final PlanItSimpleProject simpleProject = new PlanItSimpleProject();
  
  // * NEW * initial cost WITHOUT time period
  InitialLinkSegmentCost initialLinkSegmentCostNoTimePeriod = 
    simpleProject.createAndRegisterInitialLinkSegmentCost(simpleProject.getNetwork(),initialCostCSVPath1);
    
  // * NEW * intial cost WITH time period
  TimePeriod theTimePeriod = simpleProject.getDemands().timePeriods.getTimePeriodById(0);  
  InitialLinkSegmentCost initialLinkSegmentCostTimePeriod = 
    simpleProject.createAndRegisterInitialLinkSegmentCost(project.getNetwork(),initialCostCSVPath2, theTimePeriod);      

  TrafficAssignmentBuilder taBuilder = 
    simpleProject.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
  
  // * NEW * register with and without time period
  taBuilder.registerInitialLinkSegmentCost(initialLinkSegmentCostNoTimePeriod);
  taBuilder.registerInitialLinkSegmentCost(theTimePeriod, initialLinkSegmentCostTimePeriod);
  
  simpleProject.executeAllTrafficAssignments();
    
} catch (final Exception e) {
  // do something
}