Traffic
Traffic realizations shared by the engineering packages.
They are cars, the adaptation of a speed or a flow towards a desired one, and the optimal velocity model.
CarElement(label, x=0.0, *, values=None, size=None, space=None)
Bases: Element
Car on a road at the position x, whose speed is the derivative x'.
The interactions that drive the car give the acceleration x'', and the speed x' starts at zero unless values
gives it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the car or the group of cars. |
required |
x
|
object
|
The initial position, one value per car or one for all. |
0.0
|
values
|
Mapping[str, object] | None
|
Further values by name, such as the starting speed |
None
|
size
|
int | None
|
The number of cars, or |
None
|
space
|
BaseSpace | None
|
The road, a continuous space of one dimension whose axis |
None
|
Examples:
>>> from skcomplex.systems.engineering.common.traffic import CarElement
>>> CarElement('cars', x=[0.0, 10.0], values={"x'": 1.0}, size=2).x
[0.0, 10.0]
Source code in src/skcomplex/systems/engineering/common/traffic/_car.py
41 42 43 44 45 46 47 48 49 50 51 | |
OptimalVelocityInteraction(label, *, target, a=1.0, V0=1.0, hc=2.0, road_length=40.0)
Bases: SpeedAdaptationInteraction
Relaxation of the speed x' of every car of a ring road.
The speed follows x'' = a (V(h) - x') with the optimal velocity V(h) = V0 (tanh(h - hc) + tanh(hc)) of the
headway h to the next car, a relaxation over the time 1 / a.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction. |
required |
target
|
Role
|
The path of the group of cars, in the order they drive. |
required |
a
|
Annotated[float, open(0, oo)]
|
The sensitivity, the inverse of the relaxation time. |
1.0
|
V0
|
Annotated[float, open(0, oo)]
|
The scale of the optimal velocity. |
1.0
|
hc
|
Annotated[float, open(0, oo)]
|
The safe headway, where the optimal velocity turns. |
2.0
|
road_length
|
Annotated[float, open(0, oo)]
|
The length of the ring road. |
40.0
|
Examples:
>>> from skcomplex.systems.engineering.common.traffic import OptimalVelocityInteraction
>>> OptimalVelocityInteraction('follow', target='cars').state
"x'"
Source code in src/skcomplex/systems/engineering/common/traffic/_optimal_velocity.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
SpeedAdaptationInteraction(label, *, target, state='x', goal=0.0, time=1.0, noise=None)
Bases: Interaction
Adaptation of a speed or a flow towards a desired one over an adaptation time.
Traffic engineering names it the speed adaptation of a driver, as in the optimal velocity and Payne-Whitham models.
The rate is (goal(s) - x) / time(s) of a value x of the target, with optional noise. With a constant goal and
time and an additive noise of amplitude sigma, the value follows the Ornstein-Uhlenbeck process
dx = (goal - x) / time dt + sigma dW, whose stationary variance is sigma**2 time / 2. The value is a state of
the target, such as the flow Q of a road, or the speed "x'" of a car, the derivative of its position. A goal, a
time, or a noise is a number or a function of the namespace of the interaction, whose target is s.target.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
label
|
str
|
The label of the interaction, unique among the components of its system. |
required |
target
|
Role
|
The path of the element or group whose value relaxes. |
required |
state
|
str
|
The name of the value of the target that relaxes, with a prime for the derivative of a value. |
'x'
|
goal
|
Setting
|
A function of the namespace that returns the goal, or a number. |
0.0
|
time
|
Setting
|
A function of the namespace that returns the relaxation time, or a positive number. |
1.0
|
noise
|
Setting | None
|
A function of the namespace that returns the amplitude of the noise, a number, or |
None
|
Raises:
| Type | Description |
|---|---|
ValidationError
|
A goal, a time, or a noise is neither callable nor a number, raised by |
Examples:
>>> from skcomplex.core.components.elements import Element
>>> from skcomplex.core.systems import System
>>> from skcomplex.systems.engineering.common.traffic import SpeedAdaptationInteraction
>>> relaxation = SpeedAdaptationInteraction('relaxation', target='stock', goal=10.0, time=0.5)
>>> system = System(elements=[Element('stock', values={'x': 0.0})], interactions=[relaxation]).prepare()
>>> round(float(system.simulate(until=5.0, dt=0.01).get_values('stock.x')[-1]), 3)
10.0
Source code in src/skcomplex/systems/engineering/common/traffic/_speed_adaptation.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | |