ts_core.execution.Rolodex module

Rolodex Overview

Rolodex handles data collection through TraCi variable subscriptions, data access, and supporting functions

Software Structure and Implementation

Light Control

ts_runner will accept an argument that specifies the file and class name to import at startup. Messing with this part of Python is tricky business.

Optimization

ts_runner looks for a file named optimizer_example to run inside the optimizer_example file an OptimizerExample class is expected to exist with a function called train which is called after every simulation tick

Output

Output from ts_runner is directed to ``<sumo_project_dir>/output/<YYYY_MM_DD_HH_MM_SS_dddddd>/’’ which contains:

  • sutripinfo.xml
  • YYYY_MM_DD_HH_MM_SS_dddddd_ts_runner.log (Not yet implemented, writes to current dir)
class DataBuffer(buffer_length, domain, attributes=None, dumpfile=None, id_update_frequency=None)[source]

Bases: object

Buffers to hold simulation data collected by subscriptions

add(attributes, tick_num)[source]

Adds the given attributes to buffer

Parameters:
  • attributes (attributes/ids/sampling frequencies to be added to the buffer, same as __init__) –
  • tick_num (the tick number of the simulation) –
Returns:

Return type:

Nothing

dump(dumpfile=None)[source]

Writes the pickle representation of the buffer to the dumpfile

Parameters:dumpfile (file handle to write data to) –
Returns:
Return type:Nothing
generate_data_structures(tick_num)[source]

Generates lookup tables for the buffer

Parameters:tick_num (the tick number of the simulation) –
Returns:
Return type:The list of ids of objects of the given domain that are discovered, if id_table is empty
remove_id(id)[source]

Removes the specified ID from the buffer

Parameters:id (the ID of the object to be removed e.g. 'car100') –
Returns:
Return type:Nothing
reset(attributes=None)[source]

Resets the buffer (esentially calls __init__ again)

Parameters:attributes (same as __init__) –
update(id, data, tick_num=None)[source]

Updates the data stored in the buffer for the given ID

Parameters:
  • id (the ID of the object in the buffer's domain e.g. 'car100') –
  • data (a dictionary containing the data to be put into the buffer e.g.) – data = {‘lane position’:123.12345123451234, …}
Returns:

Return type:

any data removed from the buffer when inserting the new data

class Rolodex(attributes=None, buffer_length=None, frame_time=None, simulation_run_time=None, dumpfile=None, id_update_frequency=None, ticks_per_second=1, auto_removal_delay=10)[source]

Bases: object

Data buffer wrapper class

Parameters:
  • - what data is needed to be collected, strings found in SumoAttributeDictionary (attributes) –

    An empty id list will gather the specified attribute data for every id available at setup time Can specify unique sampling frequencies for each attribute/context id, or choose to use a global sampling frequency for all attributes

    (context, attribute label, [id list], sampling frequency)

  • - if a global buffer length is desired for all attributes (buffer_length) –
  • - file pointer to dump buffer contents to when requested / on fatal errors (dumpfile) –
  • frame_time (the time period o collect data for) –
  • simulation_run_time (the total time that the simulaion is run for) –
  • dumpfile (the file to dump data to in case of a memory errors) –
  • id_update_frequency (how often to update the the list of objects when auto-updating is used) –
  • ticks_per_second (how many ticks per second of simulation time) –
  • auto_removal_delay (how many simulation ticks to wait before removing the data for an object that has left the simulation) –
Returns:

Return type:

Nothing

add_subscription(domain, id_table, ids=[])[source]

Adds a TraCi subscription for the given domain, IDs and attributes

Parameters:
  • domain (the label of the domain e.g. 'vehicle') –
  • id_table (a dictionary containing the IDs and the attributes to collect data for for them e.g.) – id_table = ‘car100’:[attribute_label_0,attribute_label_1, …]
  • ids (a list to specify which IDs within the id_table will be added) –
attribute_to_var_tuple(domain, list)[source]

Used to get the tuple of attributes for establishing a TraCi subscription

Parameters:
  • domain (the label of the domain e.g. 'vehicle') –
  • list (the list of attributes e.g. ['lane position', 'lane id', ..]) –
Returns:

Return type:

A tuple containing the TraCi hex codes for the given attributes

convert_hex_to_attribute(domain, data)[source]

Converts the data returned by a TraCi subscription from hex codes to attribute labels

Parameters:
  • domain (the label of the domain e.g. 'vehicle') –
  • data (the data returned by traci.{domain}.getSubscriptionResults()) –
Returns:

Return type:

A dictionary containing the attribute labels as keys and their data as values

dump_to_file(domain=None, dumpfile=None)[source]

Option to dump buffers to file

Parameters:
  • domain (can specify the domain to dump e.g. 'vehicle') –
  • dumpfile (the file handle to write the data to) –
Returns:

Return type:

Nothing

get_data(domains=[])[source]

Returns a copy of the data buffers for the given domains

Parameters:domains (['vehicle', 'lane', ..]) –
Returns:
Return type:data
list_context_domains()[source]

prints the TraCi domains

Parameters:Nothing
Returns:
Return type:Nothing
remove_subscription(domain, ids=[])[source]

removes a subscription from TraCi

Parameters:
  • domain (the label of the domain e.g. 'vehicle') –
  • ids (the list of ids to remove subscriptions for e.g. ['car100', 'car101']) –
set_update_frequency(attribute, num_simulation_ticks_between_samples, ids=[])[source]

Not implemented

setup_context_subscription(context_attributes=None)[source]

Not implemented

setup_subscription(domain, id_table)[source]

Sets up a TraCi subscription for the given IDs and attributes

Parameters:
  • domain (the label of the domain e.g. 'vehicle') –
  • id_table (a dictionary containing the IDs and the attributes to collect data for for them e.g.) – id_table = ‘car100’:[attribute_label_0,attribute_label_1, …]
Returns:

Return type:

Nothing

update(domain, id_table=[])[source]

updates the buffer for the given domain and ids/attributes

Parameters:
  • domain (the label of the domain e.g. 'vehicle') –
  • id_table (a dictionary containing the IDs and the attributes to collect data for for them e.g.) –
    id_table = {
    ‘car100’:[(attribute_label,sampling_frequency,simulation_ticks_since_last_update), …], ‘car101’:[(attribute_label,sampling_frequency,simulation_ticks_since_last_update), …]

    }

update_subscription_buffers(tick_num, domains=None)[source]

Updates the subscription buffers

Parameters:
  • tick_num (the current tick number of the simulation_run_time) –
  • domains (used to specify which domains are updates e.g. ['junction', 'vehicle', ..]) –
Returns:

Return type:

Nothing