Initial cost examples
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). The time periods used to identify which costs to parse and register on the project level need not necessarily be used 1:1 to use these costs on the assignment. It is possible to apply initial costs of any time period and apply them on the assignment via another time period. This to ensure maximum flexibility.
Prerequisites:
- It is assumed you know how to set up a PLANit project, otherwise see Setting up a project
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 | 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:
- Inputs: default PLANit XML input format
- Outputs: default PLANit XML/CSV output format
- Assignment: Traditional static assignment
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 specifying a particular time period either, the entire initial cost instance is provided meaning, that all costs, both time period agnostic and time period specific (if any) are applied in a 1:1 fashion on the assignment.
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);
TraditionalStaticAssignmentConfigurator ta = (TraditionalStaticAssignmentConfigurator)
project.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
// * NEW *
ta.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 used to both identify which initial costs to use (of that period) upon parsing, as well as how to apply them in the assignment
- The initial link segment costs are registered on the traffic assignment and attributed to the same time period (choice)
By relating the initial link segment costs to a specific time period, only the indicated time period will receive the initial link segment costs.
try{
final PlanItSimpleProject simpleProject = new PlanItSimpleProject();
// * NEW *
TimePeriod theTimePeriod = simpleProject.getDemands().timePeriods.getFirst();
InitialLinkSegmentCost initialLinkSegmentCost =
simpleProject.createAndRegisterInitialLinkSegmentCost(
simpleProject.getNetwork(),"<insert the initial cost CSV file path here>", theTimePeriod);
TraditionalStaticAssignmentConfigurator taBuilder = (TraditionalStaticAssignmentConfigurator)
simpleProject.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
// * NEW *
taBuilder.registerInitialLinkSegmentCost(theTimePeriod, initialLinkSegmentCost.getTimePeriodCosts(theTimePeriod));
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
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.getFirst();
InitialLinkSegmentCost initialLinkSegmentCostTimePeriod =
simpleProject.createAndRegisterInitialLinkSegmentCost(simpleProject.getNetwork(),initialCostCSVPath2, theTimePeriod);
TraditionalStaticAssignmentConfigurator ta = (TraditionalStaticAssignmentConfigurator)
simpleProject.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
// * NEW * register with and without time period using a 1:1 mapping between parsed and applied time periods
ta.registerInitialLinkSegmentCost(initialLinkSegmentCostNoTimePeriod.getTimePeriodAgnosticCosts());
ta.registerInitialLinkSegmentCost(theTimePeriod, initialLinkSegmentCostTimePeriod.getTimePeriodCosts(theTimePeriod));
simpleProject.executeAllTrafficAssignments();
} catch (final Exception e) {
// do something
}