Memory Output Formatter

An in-memory output formatter
Description

In-memory results of the PLANit run. All results are collected in a multi-dimensional matrix, where you can access data by providing information to pinpoint its location in the result. You must always provide the following meta-information before accessing any result data:

  • Mode (XML) id
  • Time period (XML) id
  • Iteration index
  • OutputType. type

The mode and time period ids refer to the ids provided in the input files, rather then the auto-generated ids used by PLANit internally.

Further, you must be able to pinpoint the location of the output properties, e.g. flow, cost, in the result array that are exposed via an iterator. So, you first collect the position of each output property, then construct the appropriate iterator. Once this is done, you can loop over each result row and collect the relevant data.

This class exposes the necessary methods to both identify the position of output properties, and also allows you to construct the appropriate iterator.

Defaults

No defaults (yet)

Methods

Memory output formatter exposes the following methods

Name Description
get_position_of_output_value_property(+) Collect the index of an activated output property (e.g. flow) for an active output type (e.g. link). Property is not a(n) (partial) id for the row
get_position_of_output_key_property(+) Collect the index of an activated output property (e.g. link segment id) representing a key for an active output type (e.g. link). Property is a(n) (partial) id for the row
get_last_iteration() Collect the index of the last iteration conducted by the PLANit run
iterator(+) Construct an iterator to loop over the results for a given time period, mode, and iteration

Properties

No exposed properties (yet)

Example 1

from planit import *

#prep
plan_it = Planit()
plan_it.project.set(TrafficAssignment.TRADITIONAL_STATIC)
plan_it.project.assignment.set(PhysicalCost.BPR)
plan_it.project.assignment.set(VirtualCost.FIXED)
plan_it.project.assignment.set(Smoothing.MSA)

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

# run simulation
plan_it.project.run()

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

# find position of flow result
flow_pos = plan_it.project.memory.get_position_of_output_value_property(OutputType.LINK, OutputProperty.FLOW)

# find position of key; we use link segment (XML) id	
id_pos = plan_it.project.memory.get_position_of_output_key_property(OutputType.LINK, OutputProperty.LINK_SEGMENT_XML_ID)

# collect iterator for mode "1", time period "2", iteration i, and print results by looping over entries
modeXmlId = "1"
timePeriodXmlId = "2"
the_iterator = plan_it.project.memory.iterator(modeXmlId, timePeriodXmlId, i, OutputType.LINK)
while the_iterator.has_next():
	the_iterator.next()
	print "id: ", the_iterator.get_keys()[id_pos], " flow: ", the_iterator.get_values()[flow_pos] 

See also

iterator for the implementation of the memory output formatter iterator planit.project.activate(+) to see how to activate an output formatter
planit.project.deactivate(+) to see how to de-activate an output formatter
planit.project.memory on how to access the memory output formatter

Source code

Class MemoryOutputFormatterWrapper in projectwrappers.py


.get_last_iteration()

Memory Output Formatter method

.get_position_of_output_key_property(+)

Memory Output Formatter method

.get_position_of_output_value_property(+)

Memory Output Formatter method

.iterator(+)

Memory Output Formatter method

Memory Output Formatter Iterator

An iterator for in-memory output formatter results

Last modified January 1, 0001