ensemble.handler.symuvia package

Submodules

ensemble.handler.symuvia.configurator module

This module contains a configurator object for SymuVia. The configurator is an object that stores parameters that can be relevant to make the evolution of a simulation. The objective is to introduce flexibility when configuring the the simulator platform and the runtime execution possibilities offered by exposed functions from the c library of SymuVia

class ensemble.handler.symuvia.configurator.SymuviaConfigurator(**kwargs)[source]

Bases: ensemble.tools.connector_configurator.ConnectorConfigurator

Configurator class for containing specific simulator parameters .. rubric:: Example

To use the Simulator declare in a string the path to the simulator

>>> path = "path/to/libSymuyVia.dylib"
>>> simulator = SymuviaConfigurator(library_path = path)
Parameters
  • library_path (str) – Absolute path towards the simulator library

  • bufferSize (int) – Size of the buffer for message for data received from simulator

  • write_xml (bool) – Flag to turn on writting the XML output

  • trace_flow (bool) – Flag to determine tracing or not the flow / trajectories

  • total_steps (int) – Define the number of iterations of a simulation

  • step_launch_mode (str) – Determine to way to launch the RunStepEx. Options lite/full

Returns

Configurator object with simulation parameters

Return type

configurator (Configurator)

b_end: ctypes.c_int = c_int(0)
buffer_string: ctypes.c_char = <ctypes.c_char_Array_1000000 object>
library_path: str = 'libSymuFlow.so'
step_launch_mode: str = 'lite'
total_steps: int = 0
trace_flow: bool = False
write_xml: ctypes.c_bool = c_bool(False)

ensemble.handler.symuvia.connector module

Symuvia Connector

This module details the implementation of a Simulator object in charge of handling the connection between the traffic simulator and this interface. The connection with the traffic simulator is handled by an object called Connector which establishes a messaging protocol with the traffic simulator.

Example

To use the Simulator declare in a string the path to the simulator

>>> from ensemble.handler.symuvia import SymuviaConnector
>>> path_symuvia = "path/to/libSymuyVia.dylib"
>>> simulator = SymuviaConnector(library_path=path_symuvia)

Other parameters can also be send to the simulator in order to provide other configurations:

Example

To send make increase the buffer size to a specific size:

>>> simulator = Simulator(path, bufferSize = 1000000)

To increase change the flag that traces the flow:

>>> simulator = Simulator(path, traceFlow = True)
class ensemble.handler.symuvia.connector.SymuviaConnector(**kwargs)[source]

Bases: ensemble.handler.symuvia.configurator.SymuviaConfigurator, ensemble.metaclass.connector.AbsConnector

Simulator class for containing object to connect and command a simulation in SymuVia

Example

Call of the default simulator

>>> from ensemble.handler.symuvia import SymuViaConnector
>>> simulator = SymuViaConnector()
Returns

Symuvia simulator object with simulation parameters

Return type

Simulator

You may also pass suplementary parameters to the object by specifying keys in the call:

Example

To use the Simulator declare in a string the path to the simulator

>>> from ensemble.handler.symuvia import SymuViaConnector
>>> path_symuvia = "path/to/libSymuyVia.dylib"
>>> simulator = SymuViaConnector(library_path=path_symuvia)

This object describes is a configurator manager for the interface between the traffic simulator and the python interface. For more details on the optinal keyword parameters please refer to Configurator class.

Raises
  • EnsembleAPILoadFileError – Error raised whenever the SymuVia library is not found

  • EnsembleAPILoadFileError – Error raised whenever the provided path for an scenario cannot be loaded into the Simulator

  • EnsembleAPILoadFileError – Error raised when a vehicle cannot be created

  • EnsembleAPIDriveVehicleError – Error rased when a vehicle state cannot be imposed

  • NotImplementedError – Not implemented functionality

Returns

Simulator manager object

Return type

Simulator

property do_next: bool

Returns true if the simulation shold continue

property get_vehicle_data

Returns the query received from the simulator

Returns

Request from the simulator

Return type

dict

load_scenario(scenario: ensemble.handler.symuvia.scenario.SymuviaScenario)[source]

checks existance and load scenario into

load_simulator() None[source]

This is a method to load the shared symuvia library into python. This method is used in the internal simulationp process however it can be also called from outside like:

Example

To use the Simulator declare in a string the path to the simulator

>>> from ensemble.tools.constants import DEFAULT_LIB_OSX
>>> simulator = Simulator(DEFAULT_LIB_OSX)
>>> simulator.load_symuvia()
Raises

EnsembleAPILoadLibraryError – When the library cannot be loaded

performConnect() None[source]

Perform simulation connection

performInitialize(scenario: ensemble.handler.symuvia.scenario.SymuviaScenario) None[source]

Perform simulation initialization

performPreRoutine() None[source]

Perform simulator preroutine

performQuery() None[source]

Perform simulator Query

push_data()[source]

Push data back to the simulator

query_data() int[source]

Run simulation step by step

Returns

iteration step

Return type

int

register_simulation(scenarioPath: str) None[source]

Register simulation file within the simulator

Parameters

scenarioPath (str) – Path to scenario

request_answer()[source]

Request simulator answer and maps the data locally

property scenariofilename

Scenario filenamme

Returns

Absolute path towards the XML input for SymuVia

Return type

filname (str)

property simulation_step

Current simulation iteration

property simulationstep: float

Current simulation step

property time

Current simulation time

ensemble.handler.symuvia.scenario module

Scenario Module

This module contains descriptions that stablish a traffic scenario. A traffic scenario for SymuVia is regularly described by a simulation object that points towards properties of the simulation file in this case an XML.

class ensemble.handler.symuvia.scenario.SymuviaScenario(scn_file: Optional[str] = None, layout_file: Optional[str] = None, platoon_file: Optional[str] = None)[source]

Bases: ensemble.input.scenario.Scenario

Scenario class for Vissim

classmethod create_input(*args)[source]

Looks for indicated symuvia scenario paths and performs validation create the scenario

filename(encoding: str = 'UTF8')[source]

This method returns the value of encoding of the simulation scenario under consideration

Parameters

encoding (string, optional) – enconder UTF8, defaults to None

Returns

Full path of scenario

Return type

string

get_network_endpoints() tuple[source]

Get networks endpoint names

Returns

tuple containing endpoint names

Return type

tuple

Get network link names

Returns

tuple containing link names

Return type

tuple

get_simulation_parameters() tuple[source]

Get simulation parameters

Returns

tuple with XML dictionary containing parameters

Return type

tuple

get_simulation_steps(simid: int = 0) range[source]

Get simulation steps for an simulation. specify the simulation id via an integer value

Parameters

simid (int, optional) – simulation id , defaults to 0

Returns

Return type

range

get_vehicletype_information() tuple[source]

Get the vehicle parameters

Returns

tuple of dictionaries containing vehicle parameters

Return type

tuple

load_xml_tree() None[source]

Load XML file_name

ensemble.handler.symuvia.stream module

SymuVia Stream

This module is able to receive the stream of data comming from the SymuVia platform and define a parser for a specific vehicle data suitable to perform platooning activities.

class ensemble.handler.symuvia.stream.SimulatorRequest(**kwargs)[source]

Bases: ensemble.metaclass.stream.DataQuery

create_vehicle_registry()[source]

Creates a vehicle registry for all vehicles in simulation

property current_nbveh: int

Provides current number of vehicles

property current_time: float

Provides current time step

property data_query

Direct parsing from the string buffer

Returns

Simulator data parsed from XML

Return type

simdata (OrderedDict)

get_vehicle_data() tuple[source]

Extracts vehicles information from simulators response

Returns

list of dictionaries containing vehicle data with correct formatting

Return type

t_veh_data (list)

is_vehicle_driven(vehid: int) bool[source]

Returns true if the vehicle state is exposed to a driven state

Parameters

vehid (str) – vehicle id

Returns

True if veh is driven

Return type

driven (bool)

property query

String response from the simulator

update_vehicle_registry()[source]

Updates vehicle registry in case it exists

ensemble.handler.symuvia.xmlparser module

Symuvia XML Parser

A parser for trajectories from symuvia.

class ensemble.handler.symuvia.xmlparser.XMLTrajectory(xml: bytes)[source]

Bases: object

Model object for a trajectory, it can be created from a xml and contains trajectories for a set of vehicles.

property abs: tuple

abs cached values for all vehicles in network

Returns

cached abs values

Return type

tuple

property acc

acceleration cached values for all vehicles in network

Returns

cached acc values

Return type

tuple

aliases = {'abscissa': 'abs', 'acceleration': 'acc', 'distance': 'dst', 'elevation': 'z', 'lane': 'voie', 'link': 'tron', 'ordinate': 'ord', 'speed': 'vit', 'vehid': 'id', 'vehtype': 'type'}
property driven

alias for etat_pilotage

property dst

distance cached values for all vehicles in network

Returns

cached dst values

Return type

tuple

property etat_pilotage

etat_pilotage cached values for all vehicles in network

Returns

cached etat_pilotage values

Return type

tuple

property id

Vehicle id cached values for all vehicles in network

Returns

cached id values

Return type

tuple

property inst

val simulation time instant for current trajectory

Returns

simulation time

Return type

float

property nbveh

nbveh simulation time instant for current trajectory

Returns

number of vehicles

Return type

int

property ord

ordinate cached values for all vehicles in network

Returns

cached ord values

Return type

tuple

property todict

Converts to dictionary any of the data in the

property traj

Trajectory cached values for all vehicles in network

Returns

cached traj values

Return type

tuple

property tron

link cached values for all vehicles in network

Returns

cached tron values

Return type

tuple

property type

Vehicle type cached values for all vehicles in network

Returns

cached type values

Return type

tuple

property vit

speed cached values for all vehicles in network

Returns

cached vit values

Return type

tuple

property voie

lane cached values for all vehicles in network

Returns

cached voie values

Return type

tuple

property z

elevation cached values for all vehicles in network

Returns

cached z values

Return type

tuple

Module contents