.get_keys()
A Memory Output Formatter Iterator method
Description
The .get_keys() method provides the data array populated with the output properties earmarked as keys for the current result row.
You typically call this method in combination with a loop mechanism such as a while loop, see Example.
Signature
.get_keys()
Return type
Class py4j.java_collections.JavaArray
: instance
Example
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]
See also
N/A
Source code
Class MemoryOutputIteratorWrapper
in projectwrappers.py