Examples

See your project in action!

Here we provide you with a number of representative examples.

Traditional Static Assignment

All examples in this section are configured to be using the traditional static assignment approach

Example Name Description
1 Minimum Minimum example with all default settings
2 Components Explicit setting of default components and some small configuration changes to their options
3 Output Configuration Changing output configuration by adding and removing columns from results and activating different types of results
4 Initial Cost Apply initial costs
5 Memory Output Utilise memory output formatter to get access to results without persisting them to disk

Minimum

An assignment where

from planit import *

# create PLANit instance collecting input from current dir "."
plan_it = PLANit()

# choose traditional static assignment
plan_it.set(TrafficAssignment.TRADITIONAL_STATIC)         

# run!
plan_it.run()

Components

An assignment where we explicitly set the (default) components and change a number of settings

  • Custom input directory to read project inputs from
  • Default stop criterion maximum of 100 iterations with an epsilon of 0.000001,
  • Default MSA smoothing,
  • Default FIXED cost for the connectors, and
  • Default BPR function for the cost of physical links, overwrite default alpha and beta
  • Default Output formatter
    • Results for links, paths, and ods are activated, and
    • Results will be stored in the same directory as where the inputs were read from.
    • explicit naming of result files to refer to this testcase
from planit import *

# input files can be found here
project_path = "path_to_input_dir">

# create PLANit instance pointing to input directory
plan_it = PLANit(project_path)

# explicitly set default components for assignment: 
# e.g., BPR function, fixed cost for connectors, MSA smoothing explicitly
plan_it.set(TrafficAssignment.TRADITIONAL_STATIC)         
plan_it.assignment.set(PhysicalCost.BPR)
plan_it.assignment.set(VirtualCost.FIXED)
plan_it.assignment.set(Smoothing.MSA)

#overwrite default alpha and beta
alpha = 4.5
beta = 0.9
plan_it.assignment.physical_cost.set_default_parameters(alpha,beta)

# only persist results of the final iteration to reduce the number of files generated
plan_it.assignment.output_configuration.set_persist_only_final_Iteration(True)
# cap the number of iterations to 100
plan_it.assignment.gap_function.stop_criterion.set_max_iterations(100)
plan_it.assignment.gap_function.stop_criterion.set_epsilon(0.000001)

# activate OD and PATH output results, besides the default link outputs
plan_it.assignment.activate_output(OutputType.OD)
plan_it.assignment.activate_output(OutputType.PATH)

# include the description of this run in the result file names       
plan_it.output.set_xml_name_root("Example_2")                
plan_it.output.set_csv_name_root("Example_2")     
# persist results to the same directory as where the input file(s) where found
plan_it.output.set_output_directory(project_path)

# run!
plan_it.run()

Output configuration

  • Changing some output properties on the link results
  • Activate od and path results
from planit import *

plan_it = PLANit()
plan_it.set(TrafficAssignment.TRADITIONAL_STATIC)

# activate and configure PATH outputs
plan_it.assignment.activate_output(OutputType.PATH)
#	use node XML ids as the way to uniquely identify the path in the output, e.g. "[1,5,7,2,3]"
plan_it.assignment.path_configuration.set_path_id_type(PathIdType.NODE_XML_ID)

# activate and configure OD outputs
plan_it.assignment.activate_output(OutputType.OD)         

# configure LINK outputs (active by default)
# 	add Volume Capacity Ratio property to link results 
plan_it.assignment.link_configuration.add(OutputProperty.VC_RATIO)
# 	remove computed speed property from link results 
plan_it.assignment.link_configuration.remove(OutputProperty.COMPUTED_SPEED)

# run!
plan_it.run()

Initial Cost

Default assignment with initial costs. Initial costs are applied in a hierarchy where the most specific initial costs available are utilised.

Currently initial costs are only supported in combination with the default link (segment) output files, where it parses the link costs from the CSV files in order to extract its initial cost.

from planit import *

path_to_initial_costs_period_1 = "specify_path"
path_to_initial_costs_generic = "specify_path"

plan_it = PLANit()
plan_it.set(TrafficAssignment.TRADITIONAL_STATIC)

# specify location of initial costs for time period "1" (XML id)
planit_instance.initial_costs.set(path_to_initial_costs_period_1, "1")

# specify initial costs for all other periods
planit_instance.initial_costs.set(path_to_initial_costs_generic)


# run!
plan_it.run()

Memory output

Default assignment with memory output formatter only. Use an iterator to loop through the results of the assignment

from planit import *

plan_it = PLANit()
plan_it.set(TrafficAssignment.TRADITIONAL_STATIC)

# remove default formatter - activate memory output
plan_it.deactivate(OutputFormatter.PLANIT_IO)
plan_it.activate(OutputFormatter.MEMORY)

# run!
plan_it.run()

#collect iteration index of last recorded iteration
i = plan_it.memory.get_last_iteration()

# find position of flow result column which is a value (output) of the result row
flow_pos = plan_it.memory.get_position_of_output_value_property(OutputType.LINK, OutputProperty.FLOW)

# find position of link (XML) id which is a key of the result row	
id_pos = plan_it.memory.get_position_of_output_key_property(OutputType.LINK, OutputProperty.LINK_SEGMENT_XML_ID)

# collect iterator for mode "1", time period "2", last iteration i
link_iter = plan_it.memory.iterator("1", "2", i, OutputType.LINK)

# print results by looping over entries
while link_iter.has_next():
	link_iter.next()
	print "id: ", link_iter.get_keys()[id_pos], " flow: ", link_iter.get_values()[flow_pos] 

Last modified January 1, 0001