Project examples
Here we provide you with a number of examples to set-up your PLANit 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 | Minimum Simple project | Example of setting up a PLANit “simple” project |
2 | Simple project with path | Same as Example 1, only now the user can specify its input directory |
3 | Minimum regular project | A minimum example for a PLANit project that utilises the PLANit default input format |
4 | Minimum custom project | A minimum example for a custom PLANit project that let’s you specify what input format to use |
For all examples we adopt the following defaults, and/or settings regarding other components, unless indicated otherwise:
- inputs: default PLANit XML input format
- outputs: default PLANit XML/CSV output format, with only link outputs activated, stored in input directory
- assignment: traditional static assignment
Minimum Simple Project
A PLANit simple project is a specific type of PLANit project allows the project to only contain a single traffic assignment with minimmal input configuration required. The inputs for the assignment (network, zoning, demands) are all automatically sourced from the directory where the Java instance was run from, i.e., the user.dir. If multiple networks, zonings, demands are present in this directory, it will simply parse the first one of each that it finds.
Remarks:
- assignment can only be set by type, no option to choose zoning, network, demands, since they are automatically collected and linked to the assignment
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
}
Simple project with custom input directory
Identical to the previous example, only now the user can provide the input directory explicitly. this also serves as the output directory for the results
// inputs are collected from this directory
final String projectPath = "<insert the project path here>";
try{
// create a simple PLANit project, source inputs from "projectPath"
final PlanItSimpleProject simpleProject = new PlanItSimpleProject(projectPath);
// set traditional static assignment as our type
project.createAndRegisterTrafficAssignment(TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT);
// run
project.executeAllTrafficAssignments();
} catch (final Exception e) {
// do something
}
Minimum project
This example achieves the exact same thing as the previous example. Only now, the user must explicitly link the 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 no benefits. However, if you run many different assignments, with different demand scenarios for example, then this is much more flexible and efficient. Instead of parsing the same inputs over and over, you parse the inputs once on the project level.
Next you construct the assignments by mixing and matching these components any way that you like (as long as they are compatible).
final String projectPath = "<insert the project path here>";
try {
// Create a custom PLANit project with all the default settings
final PlanItProject project = new PlanItProject(projectPath);
// *NEW*
MacroscopicNetwork network =
(MacroscopicNetwork) project.createAndRegisterInfrastructureNetwork(Network.MACROSCOPIC_NETWORK);
// *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
}
Minimum custom project
Identical to the previous example, only now the user must explicitly define:
- input format used
- output format to generate
The input format is governed by providing an InputBuilder
. The InputBuilder
expects a particular input format for the input files. In all previous examples it was internally created to be the default input format of PLANit itself, i.e., PLANitInputBuilder
. Now we must explicitly set this as the input builder. When you have access to an alternative implementation of input builder, for example because you implemented your own for your own data format, you must use the CusomPlanItProject to be able to use it.
The output format requires an OutputFormatter
to be registered on the project and the assignment. It is possible to register more than one output formatter. In that case multiple copies of the output are generated in the different formats. If none are activated, the assignment will run but will not generate any output. In this example, we activate the PLANit default output formatter
final String projectPath = "<insert the project path here>";
try {
// *NEW*
final CustomPlanItProject project = new CustomPlanItProject(new PlanItInputBuilder(projectPath));
MacroscopicNetwork network =
(MacroscopicNetwork) project.createAndRegisterInfrastructureNetwork(Network.MACROSCOPIC_NETWORK);
Zoning zoning = project.createAndRegisterZoning(network);
Demands demands = project.createAndRegisterDemands(zoning, network);
// *NEW*
OutputFormatter outputFormatter = project.createAndRegisterOutputFormatter(OutputFormatter.PLANIT_OUTPUT_FORMATTER);
TrafficAssignmentBuilder taBuilder = project.createAndRegisterTrafficAssignment(
TrafficAssignment.TRADITIONAL_STATIC_ASSIGNMENT,
demands,
zoning,
network);
// *NEW*
taBuilder.registerOutputFormatter(outputFormatter);
project.executeAllTrafficAssignments();
} catch (final Exception e) {
// do something
}