.get_keys()
A Memory Output Formatter Iterator method
You can use an iterator to access the results for a given mode, time, iteration, and output type on the memory output formatter.
The iterator “iterates” over the results by providing you access to result entries one-by-one starting with the first and continuing until the last. Each result entry exposed by the iterator is a raw array where array entry reflects a single value for exactly one of the activated output properties.
To know which array entry belongs to what output property, you must first collect its position, i.e., index, assigned to the output property, see .get_position_of_output_value_property(+)
and .get_position_of_output_key_property(+)
on the memory output formatter. Which of the two methods to use depends on whether or not the output property is regarded a key or a value.
Once you have established which property value is found at what array index, and you constructed an instance of this class via the .iterator(+)
on the memory output formatter, you are ready to loop over the results.
Remember each entry contain a single raw array - representing a result row - which can now be decoded using the position information you collected earlier.
While this may sound cumbersome, it is in fact an extremely flexible approach, that you will get used to very quickly. See the example section of this page for an illustrative example.
No defaults (yet)
Memory output formatter iterator exposes the following methods
Name | Description |
---|---|
has_next() |
Verify if there is another row of results |
next() |
Move iterator to the next row of results |
get_keys() |
Collect the current result row’s keys as a raw data array |
get_values |
Collect the current result row’s values as a raw data array |
No exposed properties (yet)
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()
modeXmlId = "1"
timePeriodXmlId = "2"
# 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 and print results by looping over entries
link_segment_iterator = plan_it.project.memory.iterator(modeXmlId, timePeriodXmlId, i, OutputType.LINK)
while link_segment_iterator.has_next():
link_segment_iterator.next()
print "id: ", link_segment_iterator.get_keys()[id_pos], " flow: ", link_segment_iterator.get_values()[flow_pos]
N/A
Class MemoryOutputIteratorWrapper
in projectwrappers.py
A Memory Output Formatter Iterator method
A Memory Output Formatter Iterator method
A Memory Output Formatter Iterator method
A Memory Output Formatter Iterator method