flow.controllers package

Submodules

flow.controllers.base_controller module

Contains the base acceleration controller class.

class flow.controllers.base_controller.BaseController(veh_id, car_following_params, delay=0, fail_safe=None, display_warnings=True, noise=0)[source]

Bases: object

Base class for flow-controlled acceleration behavior.

Instantiates a controller and forces the user to pass a maximum acceleration to the controller. Provides the method safe_action to ensure that controls are never made that could cause the system to crash.

Parameters

veh_id : str

ID of the vehicle this controller is used for

car_following_params : flow.core.params.SumoCarFollowingParams

The underlying sumo model for car that will be overwritten. A Flow controller will override the behavior this sumo car following model; however, if control is ceded back to sumo, the vehicle will use these params. Ensure that accel / decel parameters that are specified to in this model are as desired.

delay : int

delay in applying the action (time)

fail_safe : list of str or str

List of failsafes which can be “instantaneous”, “safe_velocity”, “feasible_accel”, or “obey_speed_limit”. The order of applying the falsafes will be based on the order in the list.

display_warnings : bool

Flag for toggling on/off printing failsafe warnings to screen.

noise : double

variance of the gaussian from which to sample a noisy acceleration

abstract get_accel(env)[source]

Return the acceleration of the controller.

get_action(env)[source]

Convert the get_accel() acceleration into an action.

If no acceleration is specified, the action returns a None as well, signifying that sumo should control the accelerations for the current time step.

This method also augments the controller with the desired level of stochastic noise, and utlizes the “instantaneous”, “safe_velocity”, “feasible_accel”, and/or “obey_speed_limit” failsafes if requested.

Parameters

env : flow.envs.Env

state of the environment at the current time step

Returns

float

the modified form of the acceleration

get_feasible_action(action)[source]

Perform the “feasible_accel” failsafe action.

Checks if the computed acceleration would put us above maximum acceleration or deceleration. If it would, output the acceleration equal to maximum acceleration or deceleration.

Parameters

action : float

requested acceleration action

Returns

float

the requested action clipped by the feasible acceleration or deceleration.

get_obey_speed_limit_action(env, action)[source]

Perform the “obey_speed_limit” failsafe action.

Checks if the computed acceleration would put us above edge speed limit. If it would, output the acceleration that would put at the speed limit velocity.

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

action : float

requested acceleration action

Returns

float

the requested action clipped by the speed limit

get_safe_action_instantaneous(env, action)[source]

Perform the “instantaneous” failsafe action.

Instantaneously stops the car if there is a change of colliding into the leading vehicle in the next step

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

action : float

requested acceleration action

Returns

float

the requested action if it does not lead to a crash; and a stopping action otherwise

get_safe_velocity_action(env, action)[source]

Perform the “safe_velocity” failsafe action.

Checks if the computed acceleration would put us above safe velocity. If it would, output the acceleration that would put at to safe velocity.

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

action : float

requested acceleration action

Returns

float

the requested action clipped by the safe velocity

safe_velocity(env)[source]

Compute a safe velocity for the vehicles.

Finds maximum velocity such that if the lead vehicle were to stop entirely, we can bring the following vehicle to rest at the point at which the headway is zero.

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

Returns

float

maximum safe velocity given a maximum deceleration, delay in performing the breaking action, and speed limit

flow.controllers.base_lane_changing_controller module

Contains the base lane change controller class.

class flow.controllers.base_lane_changing_controller.BaseLaneChangeController(veh_id, lane_change_params=None)[source]

Bases: object

Base class for lane-changing controllers.

Instantiates a controller and forces the user to pass a lane_changing duration to the controller.

Parameters

veh_id : str

ID of the vehicle this controller is used for

lane_change_params : dict

Dictionary of lane changes params that may optional contain “min_gap”, which denotes the minimize safe gap (in meters) a car is willing to lane-change into.

get_action(env)[source]

Return the action of the lane change controller.

Modifies the lane change action to ensure safety, if requested.

Parameters

env : flow.envs.Env

state of the environment at the current time step

Returns

float or int

lane change action

abstract get_lane_change_action(env)[source]

Specify the lane change action to be performed.

If discrete lane changes are being performed, the action is a direction

  • -1: lane change right

  • 0: no lane change

  • 1: lane change left

Parameters

env : flow.envs.Env

state of the environment at the current time step

Returns

float or int

requested lane change action

flow.controllers.base_routing_controller module

Contains the base routing controller class.

class flow.controllers.base_routing_controller.BaseRouter(veh_id, router_params)[source]

Bases: object

Base class for routing controllers.

These controllers are used to dynamically change the routes of vehicles after initialization.

Parameters

veh_id : str

ID of the vehicle this controller is used for

router_params : dict

Dictionary of router params

abstract choose_route(env)[source]

Return the routing method implemented by the controller.

Parameters

env : flow.envs.Env

see flow/envs/base.py

Returns

list or None

The sequence of edges the vehicle should adopt. If a None value is returned, the vehicle performs no routing action in the current time step.

flow.controllers.car_following_models module

Contains several custom car-following control models.

These controllers can be used to modify the acceleration behavior of vehicles in Flow to match various prominent car-following models that can be calibrated.

Each controller includes the function get_accel(self, env) -> acc which, using the current state of the world and existing parameters, uses the control model to return a vehicle acceleration.

class flow.controllers.car_following_models.BCMController(veh_id, car_following_params, k_d=1, k_v=1, k_c=1, d_des=1, v_des=8, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Bilateral car-following model controller.

This model looks ahead and behind when computing its acceleration.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

k_d : float

gain on distances to lead/following cars (default: 1)

k_v : float

gain on vehicle velocity differences (default: 1)

k_c : float

gain on difference from desired velocity to current (default: 1)

d_des : float

desired headway (default: 1)

v_des : float

desired velocity (default: 8)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

From the paper: There would also be additional control rules that take into account minimum safe separation, relative speeds, speed limits, weather and lighting conditions, traffic density and traffic advisories

class flow.controllers.car_following_models.BandoFTLController(veh_id, car_following_params, alpha=0.5, beta=20, h_st=2, h_go=10, v_max=32, want_max_accel=False, time_delay=0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Bando follow-the-leader controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

alpha : float

gain on desired velocity to current velocity difference (default: 0.6)

beta : float

gain on lead car velocity and self velocity difference (default: 0.9)

h_st : float

headway for stopping (default: 5)

h_go : float

headway for full speed (default: 35)

v_max : float

max velocity (default: 30)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

accel_func(v, v_l, s)[source]

Compute the acceleration function.

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.CFMController(veh_id, car_following_params, k_d=1, k_v=1, k_c=1, d_des=1, v_des=8, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

CFM controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : SumoCarFollowingParams

see parent class

k_d : float

headway gain (default: 1)

k_v : float

gain on difference between lead velocity and current (default: 1)

k_c : float

gain on difference from desired velocity to current (default: 1)

d_des : float

desired headway (default: 1)

v_des : float

desired velocity (default: 8)

time_delay : float, optional

time delay (default: 0.0)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.GippsController(veh_id, car_following_params=None, v0=30, acc=1.5, b=- 1, b_l=- 1, s0=2, tau=1, delay=0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Gipps’ Model controller.

For more information on this controller, see: Traffic Flow Dynamics written by M.Treiber and A.Kesting By courtesy of Springer publisher, http://www.springer.com

http://www.traffic-flow-dynamics.org/res/SampleChapter11.pdf

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.param.SumoCarFollowingParams

see parent class

v0 : float

desirable velocity, in m/s (default: 30)

acc : float

max acceleration, in m/s2 (default: 1.5)

b : float

comfortable deceleration, in m/s2 (default: -1)

b_l : float

comfortable deceleration for leading vehicle , in m/s2 (default: -1)

s0 : float

linear jam distance for saftey, in m (default: 2)

tau : float

reaction time in s (default: 1)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.IDMController(veh_id, v0=30, T=1, a=1, b=1.5, delta=4, s0=2, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True, car_following_params=None)[source]

Bases: flow.controllers.base_controller.BaseController

Intelligent Driver Model (IDM) controller.

For more information on this controller, see: Treiber, Martin, Ansgar Hennecke, and Dirk Helbing. “Congested traffic states in empirical observations and microscopic simulations.” Physical review E 62.2 (2000): 1805.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.param.SumoCarFollowingParams

see parent class

v0 : float

desirable velocity, in m/s (default: 30)

T : float

safe time headway, in s (default: 1)

a : float

max acceleration, in m/s2 (default: 1)

b : float

comfortable deceleration, in m/s2 (default: 1.5)

delta : float

acceleration exponent (default: 4)

s0 : float

linear jam distance, in m (default: 2)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.LACController(veh_id, car_following_params, k_1=0.3, k_2=0.4, h=1, tau=0.1, a=0, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Linear Adaptive Cruise Control.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

k_1 : float

design parameter (default: 0.8)

k_2 : float

design parameter (default: 0.9)

h : float

desired time gap (default: 1.0)

tau : float

lag time between control input u and real acceleration a (default:0.1)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.LinearOVM(veh_id, car_following_params, v_max=30, adaptation=0.65, h_st=5, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Linear OVM controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

v_max : float

max velocity (default: 30)

adaptation : float

adaptation constant (default: 0.65)

h_st : float

headway for stopping (default: 5)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.OVMController(veh_id, car_following_params, alpha=1, beta=1, h_st=2, h_go=15, v_max=30, time_delay=0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Optimal Vehicle Model controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

alpha : float

gain on desired velocity to current velocity difference (default: 0.6)

beta : float

gain on lead car velocity and self velocity difference (default: 0.9)

h_st : float

headway for stopping (default: 5)

h_go : float

headway for full speed (default: 35)

v_max : float

max velocity (default: 30)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.car_following_models.SimCarFollowingController(veh_id, car_following_params, delay=0, fail_safe=None, display_warnings=True, noise=0)[source]

Bases: flow.controllers.base_controller.BaseController

Controller whose actions are purely defined by the simulator.

Note that methods for implementing noise and failsafes through BaseController, are not available here. However, similar methods are available through sumo when initializing the parameters of the vehicle.

Usage: See BaseController for usage example.

get_accel(env)[source]

See parent class.

flow.controllers.lane_change_controllers module

Contains a list of custom lane change controllers.

class flow.controllers.lane_change_controllers.SimLaneChangeController(veh_id, lane_change_params=None)[source]

Bases: flow.controllers.base_lane_changing_controller.BaseLaneChangeController

A controller used to enforce sumo lane-change dynamics on a vehicle.

Usage: See base class for usage example.

get_lane_change_action(env)[source]

See parent class.

class flow.controllers.lane_change_controllers.StaticLaneChanger(veh_id, lane_change_params=None)[source]

Bases: flow.controllers.base_lane_changing_controller.BaseLaneChangeController

A lane-changing model used to keep a vehicle in the same lane.

Usage: See base class for usage example.

get_lane_change_action(env)[source]

See parent class.

flow.controllers.rlcontroller module

Contains the RLController class.

class flow.controllers.rlcontroller.RLController(veh_id, car_following_params)[source]

Bases: flow.controllers.base_controller.BaseController

RL Controller.

Vehicles with this class specified will be stored in the list of the RL IDs in the Vehicles class.

Usage: See base class for usage example.

Examples

A set of vehicles can be instantiated as RL vehicles as follows:

>>> from flow.core.params import VehicleParams
>>> vehicles = VehicleParams()
>>> vehicles.add(acceleration_controller=(RLController, {}))

In order to collect the list of all RL vehicles in the next, run:

>>> from flow.envs import Env
>>> env = Env(...)
>>> rl_ids = env.k.vehicle.get_rl_ids()
Attributes

veh_id : str

Vehicle ID for SUMO identification

get_accel(env)[source]

Pass, as this is never called; required to override abstractmethod.

flow.controllers.routing_controllers module

Contains a list of custom routing controllers.

class flow.controllers.routing_controllers.BayBridgeRouter(veh_id, router_params)[source]

Bases: flow.controllers.routing_controllers.ContinuousRouter

Assists in choosing routes in select cases for the Bay Bridge network.

Extension to the Continuous Router.

choose_route(env)[source]

See parent class.

class flow.controllers.routing_controllers.ContinuousRouter(veh_id, router_params)[source]

Bases: flow.controllers.base_routing_controller.BaseRouter

A router used to continuously re-route of the vehicle in a closed ring.

This class is useful if vehicles are expected to continuously follow the same route, and repeat said route once it reaches its end.

choose_route(env)[source]

See parent class.

Adopt one of the current edge’s routes if about to leave the network.

class flow.controllers.routing_controllers.GridRouter(veh_id, router_params)[source]

Bases: flow.controllers.base_routing_controller.BaseRouter

A router used to re-route a vehicle in a traffic light grid environment.

choose_route(env)[source]

See parent class.

class flow.controllers.routing_controllers.I210Router(veh_id, router_params)[source]

Bases: flow.controllers.routing_controllers.ContinuousRouter

Assists in choosing routes in select cases for the I-210 sub-network.

Extension to the Continuous Router.

choose_route(env)[source]

See parent class.

class flow.controllers.routing_controllers.MinicityRouter(veh_id, router_params)[source]

Bases: flow.controllers.base_routing_controller.BaseRouter

A router used to continuously re-route vehicles in minicity network.

This class allows the vehicle to pick a random route at junctions.

choose_route(env)[source]

See parent class.

flow.controllers.velocity_controllers module

Contains a list of custom velocity controllers.

class flow.controllers.velocity_controllers.FollowerStopper(veh_id, car_following_params, v_des=15, danger_edges=None)[source]

Bases: flow.controllers.base_controller.BaseController

Inspired by Dan Work’s… work.

Dissipation of stop-and-go waves via control of autonomous vehicles: Field experiments https://arxiv.org/abs/1705.01693

Parameters

veh_id : str

unique vehicle identifier

v_des : float, optional

desired speed of the vehicles (m/s)

find_intersection_dist(env)[source]

Find distance to intersection.

Parameters

env : flow.envs.Env

see flow/envs/base.py

Returns

float

distance from the vehicle’s current position to the position of the node it is heading toward.

get_accel(env)[source]

See parent class.

class flow.controllers.velocity_controllers.NonLocalFollowerStopper(veh_id, car_following_params, v_des=15, danger_edges=None)[source]

Bases: flow.controllers.velocity_controllers.FollowerStopper

Follower stopper that uses the average system speed to compute its acceleration.

get_accel(env)[source]

See parent class.

class flow.controllers.velocity_controllers.PISaturation(veh_id, car_following_params)[source]

Bases: flow.controllers.base_controller.BaseController

Inspired by Dan Work’s… work.

Dissipation of stop-and-go waves via control of autonomous vehicles: Field experiments https://arxiv.org/abs/1705.01693

Parameters

veh_id : str

unique vehicle identifier

car_following_params : flow.core.params.SumoCarFollowingParams

object defining sumo-specific car-following parameters

get_accel(env)[source]

See parent class.

Module contents

Contains a list of custom controllers.

These controllers can be used to modify the dynamics behavior of human-driven vehicles in the network.

In addition, the RLController class can be used to add vehicles whose actions are specified by a learning (RL) agent.

class flow.controllers.BCMController(veh_id, car_following_params, k_d=1, k_v=1, k_c=1, d_des=1, v_des=8, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Bilateral car-following model controller.

This model looks ahead and behind when computing its acceleration.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

k_d : float

gain on distances to lead/following cars (default: 1)

k_v : float

gain on vehicle velocity differences (default: 1)

k_c : float

gain on difference from desired velocity to current (default: 1)

d_des : float

desired headway (default: 1)

v_des : float

desired velocity (default: 8)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

From the paper: There would also be additional control rules that take into account minimum safe separation, relative speeds, speed limits, weather and lighting conditions, traffic density and traffic advisories

class flow.controllers.BandoFTLController(veh_id, car_following_params, alpha=0.5, beta=20, h_st=2, h_go=10, v_max=32, want_max_accel=False, time_delay=0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Bando follow-the-leader controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

alpha : float

gain on desired velocity to current velocity difference (default: 0.6)

beta : float

gain on lead car velocity and self velocity difference (default: 0.9)

h_st : float

headway for stopping (default: 5)

h_go : float

headway for full speed (default: 35)

v_max : float

max velocity (default: 30)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

accel_func(v, v_l, s)[source]

Compute the acceleration function.

get_accel(env)[source]

See parent class.

class flow.controllers.BaseController(veh_id, car_following_params, delay=0, fail_safe=None, display_warnings=True, noise=0)[source]

Bases: object

Base class for flow-controlled acceleration behavior.

Instantiates a controller and forces the user to pass a maximum acceleration to the controller. Provides the method safe_action to ensure that controls are never made that could cause the system to crash.

Parameters

veh_id : str

ID of the vehicle this controller is used for

car_following_params : flow.core.params.SumoCarFollowingParams

The underlying sumo model for car that will be overwritten. A Flow controller will override the behavior this sumo car following model; however, if control is ceded back to sumo, the vehicle will use these params. Ensure that accel / decel parameters that are specified to in this model are as desired.

delay : int

delay in applying the action (time)

fail_safe : list of str or str

List of failsafes which can be “instantaneous”, “safe_velocity”, “feasible_accel”, or “obey_speed_limit”. The order of applying the falsafes will be based on the order in the list.

display_warnings : bool

Flag for toggling on/off printing failsafe warnings to screen.

noise : double

variance of the gaussian from which to sample a noisy acceleration

abstract get_accel(env)[source]

Return the acceleration of the controller.

get_action(env)[source]

Convert the get_accel() acceleration into an action.

If no acceleration is specified, the action returns a None as well, signifying that sumo should control the accelerations for the current time step.

This method also augments the controller with the desired level of stochastic noise, and utlizes the “instantaneous”, “safe_velocity”, “feasible_accel”, and/or “obey_speed_limit” failsafes if requested.

Parameters

env : flow.envs.Env

state of the environment at the current time step

Returns

float

the modified form of the acceleration

get_feasible_action(action)[source]

Perform the “feasible_accel” failsafe action.

Checks if the computed acceleration would put us above maximum acceleration or deceleration. If it would, output the acceleration equal to maximum acceleration or deceleration.

Parameters

action : float

requested acceleration action

Returns

float

the requested action clipped by the feasible acceleration or deceleration.

get_obey_speed_limit_action(env, action)[source]

Perform the “obey_speed_limit” failsafe action.

Checks if the computed acceleration would put us above edge speed limit. If it would, output the acceleration that would put at the speed limit velocity.

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

action : float

requested acceleration action

Returns

float

the requested action clipped by the speed limit

get_safe_action_instantaneous(env, action)[source]

Perform the “instantaneous” failsafe action.

Instantaneously stops the car if there is a change of colliding into the leading vehicle in the next step

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

action : float

requested acceleration action

Returns

float

the requested action if it does not lead to a crash; and a stopping action otherwise

get_safe_velocity_action(env, action)[source]

Perform the “safe_velocity” failsafe action.

Checks if the computed acceleration would put us above safe velocity. If it would, output the acceleration that would put at to safe velocity.

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

action : float

requested acceleration action

Returns

float

the requested action clipped by the safe velocity

safe_velocity(env)[source]

Compute a safe velocity for the vehicles.

Finds maximum velocity such that if the lead vehicle were to stop entirely, we can bring the following vehicle to rest at the point at which the headway is zero.

Parameters

env : flow.envs.Env

current environment, which contains information of the state of the network at the current time step

Returns

float

maximum safe velocity given a maximum deceleration, delay in performing the breaking action, and speed limit

class flow.controllers.BaseLaneChangeController(veh_id, lane_change_params=None)[source]

Bases: object

Base class for lane-changing controllers.

Instantiates a controller and forces the user to pass a lane_changing duration to the controller.

Parameters

veh_id : str

ID of the vehicle this controller is used for

lane_change_params : dict

Dictionary of lane changes params that may optional contain “min_gap”, which denotes the minimize safe gap (in meters) a car is willing to lane-change into.

get_action(env)[source]

Return the action of the lane change controller.

Modifies the lane change action to ensure safety, if requested.

Parameters

env : flow.envs.Env

state of the environment at the current time step

Returns

float or int

lane change action

abstract get_lane_change_action(env)[source]

Specify the lane change action to be performed.

If discrete lane changes are being performed, the action is a direction

  • -1: lane change right

  • 0: no lane change

  • 1: lane change left

Parameters

env : flow.envs.Env

state of the environment at the current time step

Returns

float or int

requested lane change action

class flow.controllers.BaseRouter(veh_id, router_params)[source]

Bases: object

Base class for routing controllers.

These controllers are used to dynamically change the routes of vehicles after initialization.

Parameters

veh_id : str

ID of the vehicle this controller is used for

router_params : dict

Dictionary of router params

abstract choose_route(env)[source]

Return the routing method implemented by the controller.

Parameters

env : flow.envs.Env

see flow/envs/base.py

Returns

list or None

The sequence of edges the vehicle should adopt. If a None value is returned, the vehicle performs no routing action in the current time step.

class flow.controllers.BayBridgeRouter(veh_id, router_params)[source]

Bases: flow.controllers.routing_controllers.ContinuousRouter

Assists in choosing routes in select cases for the Bay Bridge network.

Extension to the Continuous Router.

choose_route(env)[source]

See parent class.

class flow.controllers.CFMController(veh_id, car_following_params, k_d=1, k_v=1, k_c=1, d_des=1, v_des=8, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

CFM controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : SumoCarFollowingParams

see parent class

k_d : float

headway gain (default: 1)

k_v : float

gain on difference between lead velocity and current (default: 1)

k_c : float

gain on difference from desired velocity to current (default: 1)

d_des : float

desired headway (default: 1)

v_des : float

desired velocity (default: 8)

time_delay : float, optional

time delay (default: 0.0)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.ContinuousRouter(veh_id, router_params)[source]

Bases: flow.controllers.base_routing_controller.BaseRouter

A router used to continuously re-route of the vehicle in a closed ring.

This class is useful if vehicles are expected to continuously follow the same route, and repeat said route once it reaches its end.

choose_route(env)[source]

See parent class.

Adopt one of the current edge’s routes if about to leave the network.

class flow.controllers.FollowerStopper(veh_id, car_following_params, v_des=15, danger_edges=None)[source]

Bases: flow.controllers.base_controller.BaseController

Inspired by Dan Work’s… work.

Dissipation of stop-and-go waves via control of autonomous vehicles: Field experiments https://arxiv.org/abs/1705.01693

Parameters

veh_id : str

unique vehicle identifier

v_des : float, optional

desired speed of the vehicles (m/s)

find_intersection_dist(env)[source]

Find distance to intersection.

Parameters

env : flow.envs.Env

see flow/envs/base.py

Returns

float

distance from the vehicle’s current position to the position of the node it is heading toward.

get_accel(env)[source]

See parent class.

class flow.controllers.GippsController(veh_id, car_following_params=None, v0=30, acc=1.5, b=- 1, b_l=- 1, s0=2, tau=1, delay=0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Gipps’ Model controller.

For more information on this controller, see: Traffic Flow Dynamics written by M.Treiber and A.Kesting By courtesy of Springer publisher, http://www.springer.com

http://www.traffic-flow-dynamics.org/res/SampleChapter11.pdf

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.param.SumoCarFollowingParams

see parent class

v0 : float

desirable velocity, in m/s (default: 30)

acc : float

max acceleration, in m/s2 (default: 1.5)

b : float

comfortable deceleration, in m/s2 (default: -1)

b_l : float

comfortable deceleration for leading vehicle , in m/s2 (default: -1)

s0 : float

linear jam distance for saftey, in m (default: 2)

tau : float

reaction time in s (default: 1)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.GridRouter(veh_id, router_params)[source]

Bases: flow.controllers.base_routing_controller.BaseRouter

A router used to re-route a vehicle in a traffic light grid environment.

choose_route(env)[source]

See parent class.

class flow.controllers.I210Router(veh_id, router_params)[source]

Bases: flow.controllers.routing_controllers.ContinuousRouter

Assists in choosing routes in select cases for the I-210 sub-network.

Extension to the Continuous Router.

choose_route(env)[source]

See parent class.

class flow.controllers.IDMController(veh_id, v0=30, T=1, a=1, b=1.5, delta=4, s0=2, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True, car_following_params=None)[source]

Bases: flow.controllers.base_controller.BaseController

Intelligent Driver Model (IDM) controller.

For more information on this controller, see: Treiber, Martin, Ansgar Hennecke, and Dirk Helbing. “Congested traffic states in empirical observations and microscopic simulations.” Physical review E 62.2 (2000): 1805.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.param.SumoCarFollowingParams

see parent class

v0 : float

desirable velocity, in m/s (default: 30)

T : float

safe time headway, in s (default: 1)

a : float

max acceleration, in m/s2 (default: 1)

b : float

comfortable deceleration, in m/s2 (default: 1.5)

delta : float

acceleration exponent (default: 4)

s0 : float

linear jam distance, in m (default: 2)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.LACController(veh_id, car_following_params, k_1=0.3, k_2=0.4, h=1, tau=0.1, a=0, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Linear Adaptive Cruise Control.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

k_1 : float

design parameter (default: 0.8)

k_2 : float

design parameter (default: 0.9)

h : float

desired time gap (default: 1.0)

tau : float

lag time between control input u and real acceleration a (default:0.1)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.LinearOVM(veh_id, car_following_params, v_max=30, adaptation=0.65, h_st=5, time_delay=0.0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Linear OVM controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

v_max : float

max velocity (default: 30)

adaptation : float

adaptation constant (default: 0.65)

h_st : float

headway for stopping (default: 5)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.NonLocalFollowerStopper(veh_id, car_following_params, v_des=15, danger_edges=None)[source]

Bases: flow.controllers.velocity_controllers.FollowerStopper

Follower stopper that uses the average system speed to compute its acceleration.

get_accel(env)[source]

See parent class.

class flow.controllers.OVMController(veh_id, car_following_params, alpha=1, beta=1, h_st=2, h_go=15, v_max=30, time_delay=0, noise=0, fail_safe=None, display_warnings=True)[source]

Bases: flow.controllers.base_controller.BaseController

Optimal Vehicle Model controller.

Attributes

veh_id : str

Vehicle ID for SUMO identification

car_following_params : flow.core.params.SumoCarFollowingParams

see parent class

alpha : float

gain on desired velocity to current velocity difference (default: 0.6)

beta : float

gain on lead car velocity and self velocity difference (default: 0.9)

h_st : float

headway for stopping (default: 5)

h_go : float

headway for full speed (default: 35)

v_max : float

max velocity (default: 30)

time_delay : float

time delay (default: 0.5)

noise : float

std dev of normal perturbation to the acceleration (default: 0)

fail_safe : str

type of flow-imposed failsafe the vehicle should posses, defaults to no failsafe (None)

get_accel(env)[source]

See parent class.

class flow.controllers.PISaturation(veh_id, car_following_params)[source]

Bases: flow.controllers.base_controller.BaseController

Inspired by Dan Work’s… work.

Dissipation of stop-and-go waves via control of autonomous vehicles: Field experiments https://arxiv.org/abs/1705.01693

Parameters

veh_id : str

unique vehicle identifier

car_following_params : flow.core.params.SumoCarFollowingParams

object defining sumo-specific car-following parameters

get_accel(env)[source]

See parent class.

class flow.controllers.RLController(veh_id, car_following_params)[source]

Bases: flow.controllers.base_controller.BaseController

RL Controller.

Vehicles with this class specified will be stored in the list of the RL IDs in the Vehicles class.

Usage: See base class for usage example.

Examples

A set of vehicles can be instantiated as RL vehicles as follows:

>>> from flow.core.params import VehicleParams
>>> vehicles = VehicleParams()
>>> vehicles.add(acceleration_controller=(RLController, {}))

In order to collect the list of all RL vehicles in the next, run:

>>> from flow.envs import Env
>>> env = Env(...)
>>> rl_ids = env.k.vehicle.get_rl_ids()
Attributes

veh_id : str

Vehicle ID for SUMO identification

get_accel(env)[source]

Pass, as this is never called; required to override abstractmethod.

class flow.controllers.SimCarFollowingController(veh_id, car_following_params, delay=0, fail_safe=None, display_warnings=True, noise=0)[source]

Bases: flow.controllers.base_controller.BaseController

Controller whose actions are purely defined by the simulator.

Note that methods for implementing noise and failsafes through BaseController, are not available here. However, similar methods are available through sumo when initializing the parameters of the vehicle.

Usage: See BaseController for usage example.

get_accel(env)[source]

See parent class.

class flow.controllers.SimLaneChangeController(veh_id, lane_change_params=None)[source]

Bases: flow.controllers.base_lane_changing_controller.BaseLaneChangeController

A controller used to enforce sumo lane-change dynamics on a vehicle.

Usage: See base class for usage example.

get_lane_change_action(env)[source]

See parent class.

class flow.controllers.StaticLaneChanger(veh_id, lane_change_params=None)[source]

Bases: flow.controllers.base_lane_changing_controller.BaseLaneChangeController

A lane-changing model used to keep a vehicle in the same lane.

Usage: See base class for usage example.

get_lane_change_action(env)[source]

See parent class.