ensemble.logic package

Submodules

ensemble.logic.frozen_set module

Frozen Set

This is a class describing a sorted frozen set. This is a collection implementation for a set of ordered elements that establish specific protocols for iteration, information access, element identification.

class ensemble.logic.frozen_set.SortedFrozenSet(items=None, key='vehid')[source]

Bases: collections.abc.Sequence, collections.abc.Set

This is a collection that provides a set of properties to create a sorted frozen set.

In particular this is

Parameters
  • Items (Iterable) – Inherits from the Sequence collection object.

  • Key (str) – Key to organize the vehicle platoon

count(value) integer -- return number of occurrences of value[source]
difference(iterable)[source]
index(value[, start[, stop]]) integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

intersection(iterable)[source]
issubset(iterable)[source]
issuperset(iterable)[source]
symmetric_difference(iterable)[source]
union(iterable)[source]

ensemble.logic.platoon_set module

Platoon Set

This is a class describing a frozen set. This is a collection implementation for a set of ordered elements that establish specific protocols for iteration, information access, element identification.

class ensemble.logic.platoon_set.PlatoonSet(items=None, key='x', id: int = - 1)[source]

Bases: ensemble.logic.frozen_set.SortedFrozenSet

This is a collection that provides a set of properties to create a platoon frozen set.

In particular

Parameters
  • Sequence (Sequence) – Inherits from the Sequence collection object.

  • Set (Set) – Inherits from the Set collection object.

count(value) integer -- return number of occurrences of value[source]
difference(iterable)[source]
increase_pid()[source]

Increases platoon id

index(value[, start[, stop]]) integer -- return first index of value.[source]

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

intersection(iterable)[source]
issubset(iterable)[source]
issuperset(iterable)[source]
joinable()[source]

Exams last vehicle in the Platoon

pid = count(0)
classmethod set_pid(value)[source]

Set counter for the platoons

symmetric_difference(iterable)[source]
union(iterable)[source]
update_pid()[source]

Exams and updates the Platoon Index Position

ensemble.logic.platoon_states module

This module defines the basic states required to determine the status of a vehicle in a platoon formation

The states are defined as:

  • StandAlone: Vehicle not in a platoon formation

  • Joining: Vehicle willing to join a platoon or willing to create a platoon

  • Platooning: Vehicle inside a platoon formation

  • Split: Vehicle is willing to split from current platoon.

class ensemble.logic.platoon_states.Cutin[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the vehicle in a platoon functionality

Note

Transition: Cutin to Splitting

next_state(vehicle)[source]

Determines the switching condition for the state:

Note

Transition: Platooning to Splitting

Parameters

truck (vehicle) – Platoon vehicle containing information of the ego vehicle.

class ensemble.logic.platoon_states.Joining[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the vehicle in joining a platoon.

Note

Transition: Joining to StandAlone Transition: Joining to Platooning

next_state(vgc: ensemble.metaclass.coordinator.AbsSingleGapCoord)[source]

Determines the switching condition for the state:

Note

Transition: Joining to StandAlone Transition: Joining to Platooning

Parameters

truck (vehicle) – Platoon vehicle containing information of the ego vehicle.

class ensemble.logic.platoon_states.Platooning[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the vehicle in a platoon functionality

Note

Transition: Platooning to Splitting

next_state(vehicle)[source]

Determines the switching condition for the state:

Note

Transition: Platooning to Splitting

Parameters

truck (vehicle) – Platoon vehicle containing information of the ego vehicle.

class ensemble.logic.platoon_states.Splitting[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the vehicle splitting from platoon

Note

Transition: Splitting to StandAlone Transition: Splitting to Platooning

next_state(vehicle)[source]

Determines the switching condition for the state:

Note

Transition: Splitting to StandAlone Transition: Splitting to Platooning

Parameters

truck (vehicle) – Platoon vehicle containing information of the ego vehicle.

class ensemble.logic.platoon_states.StandAlone[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the vehicle in stand alone mode.

Note

Transition: StandAlone to Joining

next_state(vgc: ensemble.metaclass.coordinator.AbsSingleGapCoord)[source]

Determines the switching condition for the state:

Note

Transition: StandAlone to Joining

Parameters

truck (fgc) – Platoon vehicle containing information of the ego vehicle.

ensemble.logic.publisher module

Publisher

This module dedicates a generic object to generate a publisher pattern implementation responsible of specific methods.

class ensemble.logic.publisher.Publisher(channels=('default',))[source]

Bases: ensemble.metaclass.subject.AbsSubject

This generic class model implements a general publisher pattern to broadcast information towards different subscribers. Subscribers are intented to be objects such as vehicles or other objects that should be aware of the publisher.

In particular this creates a subject that can notify to a specific channel where subscribers are registered.

Example

Create a DataQuery for 2 type of channels, automated and regular and perform a subscription

>>> channels = ('auto','regular')
>>> p = Publisher(channels)
>>> s = Subscriber(p,'auto')  # Registers a s into p
attach(observer, channel: str, callback=None)[source]

Attach a new observer to a specific channel,, one can specify a method of the class to be called.

Parameters
  • channel (str) – channel name

  • observer (observer) – observer object

  • callback (callable) – method to be executed when publisher notifies.

property channels
detach(observer, channel: str)[source]

Detach observer from the subject

Parameters
  • channel (str) – channel name

  • observer (observer) – observer object

  • callback (callable) – method to be executed when publisher notifies.

dispatch(channel: str = 'default', callback: str = 'update')[source]

Dispatches a message to a specific channel

Parameters

channel (str) – channel name

foo()[source]

Demo function

get_subscribers(channel)[source]

Retreive subscribers in a particular channel

ensemble.logic.runtime_machine module

Runtime Device

This module describes classes and objects to perform a runtime of a single scenario

class ensemble.logic.runtime_machine.RuntimeDevice(configurator)[source]

Bases: object

This class defines the runtime device describing a series of cyclic states required to be run:

__enter__() None[source]

Implementation of the state machine

next_state(event: str)[source]

Action to consider on event:

  • compliance

  • connect

  • initialize

  • preroutine

  • query

  • control

  • push

  • postroutine

  • terminate

Parameters

event (str) – State to go to

ensemble.logic.runtime_states module

Runtime States

This module defines the basic states required to execute and launch a simulation.

The states are defined as:

  • Compliance: This state is defined to check availability of files and candidates.

  • Connect: This state is defined to process

  • Initialize: This state perform initialization tasks. In example, loading the file scenarios into the simulator. Declaring initial conditions for the platoon, etc.

  • Preroutine: Tasks to be done before the querying information from the simulator

  • Query: Tasks of parsing data and querying information from the simulator

  • Control: Perform decision tasks for the platoon

  • Push: Push updated information to the simulator for platoon vehicles

  • Postroutine: Performs tasks after the information has been pushed.

class ensemble.logic.runtime_states.Compliance[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares an status to check file compliance .

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

Returns next state

Parameters

event (str) – Event keyword for next state “connect”

Returns

Connect object in case of switch

Return type

Connect

perform_check(configurator)[source]

This function triggers the check validation for the files raises errors in case files are not found

Parameters

configurator (Configurator) – Configuration descriptor

class ensemble.logic.runtime_states.Connect[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the creation of a connection with the simulator

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.Control[source]

Bases: ensemble.metaclass.state.AbsState

The state which computes the control decision

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.Initialize[source]

Bases: ensemble.metaclass.state.AbsState

The state which initializes values for the scenario simulation

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.PostRoutine[source]

Bases: ensemble.metaclass.state.AbsState

The state which logs information or compute step indicators

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.PreRoutine[source]

Bases: ensemble.metaclass.state.AbsState

The state which performs task previous to the interaction with the simulator

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.Push[source]

Bases: ensemble.metaclass.state.AbsState

The state which pushes data back to the simulator

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.Query[source]

Bases: ensemble.metaclass.state.AbsState

The state which retrieves information from the simulator

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

class ensemble.logic.runtime_states.Terminate[source]

Bases: ensemble.metaclass.state.AbsState

The state which declares the end of a simulation

next_state(event: str, configurator) ensemble.metaclass.state.AbsState[source]

State to switch on event

ensemble.logic.statemachine module

class ensemble.logic.statemachine.StateMachine(initialState)[source]

Bases: object

runAll(inputs)[source]

ensemble.logic.subscriber module

Subscriber

This module dedicates a generic object to generate an observer pattern implementation responsible of subscribing to a publisher

class ensemble.logic.subscriber.Subscriber(publisher, channel='default', callback=None)[source]

Bases: ensemble.metaclass.observer.AbsObserver

This general dataquery model implements a general publisher pattern to broadcast information towards different subscribers. Subscribers are intented to be objects such as vehicles, front/rear gap coordinators.

This creates an subject that can notify to a specific channel where subscribers are registered or

Example

Create a DataQuery for 2 type of channels, automated and regular vehicles:

>>> channels = ('auto','regular')
>>> query = DataQuery(channels)
update()[source]

Local update method to retrieve subject data

Module contents