Something else that pybtls can do.#

In pybtls, different lanes can use different vehicle generation models.

There are four lanes of traffic:

  • Lane 1: Vehicles are generated from Grave model, and headways are in NHM condition.

  • Lane 2: Vehicles are generated from Nominal model, and headways are in Congested condition.

  • Lane 3: Vehicles are generated from Garage model, and headways are in Constant condition.

  • Lane 4: Vehicles are generated from Garage model, and headways are in Freeflow condition (Poisson arrival model).

This time we only generate the traffic without effect calculation.


Import the packages and initialize the traffic generator.

[15]:
import pybtls as pb
from pathlib import Path


traffic_gen = pb.TrafficGenerator(no_lane=4)

Set lane 1.

[16]:
# Define the flow composition
lfc_lane1 = pb.LaneFlowComposition(lane_index=1, lane_dir=1)
lfc_lane1.assign_lane_data(
    hourly_truck_flow=[100] * 24,
    hourly_car_flow=[0] * 24,
    hourly_speed_mean=[80 / 3.6 * 10] * 24,
    hourly_speed_std=[10.0] * 24,
    hourly_truck_composition=[
        [25.0, 25.0, 25.0, 25.0] for _ in range(24)
    ],  # only the Grave vehicle generator (gen by distribution) requires this info.
)

# Set the Grave vehicle generator and use the Auxerre truck features
vehicle_gen_Grave = pb.VehicleGenGrave(traffic_site="Auxerre")

# Set the headway generator
headway_gen_NHM = pb.HeadwayGenNHM()

# Config the first lane
traffic_gen.add_lane(
    vehicle_gen=vehicle_gen_Grave, headway_gen=headway_gen_NHM, lfc=lfc_lane1
)

Set lane 2.

[17]:
# Define the flow composition
lfc_lane2 = pb.LaneFlowComposition(lane_index=2, lane_dir=1)
lfc_lane2.assign_lane_data(hourly_truck_flow=[100] * 24, hourly_car_flow=[0] * 24)

# Set the Nominal vehicle generator with a custom vehicle
vehicle = pb.Vehicle(no_axles=3)
vehicle.set_axle_weights([100.0, 100.0, 100.0])  # in kN
vehicle.set_axle_spacings([3.0, 7.0, 0.0])  # in m
vehicle.set_axle_widths([2.0, 2.0, 2.0])  # in m

vehicle_gen_Nominal = pb.VehicleGenNominal(
    nominal_vehicle=vehicle, COV_list=[1.0, 1.0]
)

# Set the headway generator
headway_gen_Congested = pb.HeadwayGenCongested(
    congested_spacing=26.1, congested_speed=36.0, congested_gap_coef_var=0.05
)

# Config the second lane
traffic_gen.add_lane(
    vehicle_gen=vehicle_gen_Nominal, headway_gen=headway_gen_Congested, lfc=lfc_lane2
)

Set lane 3 and lane 4.

[18]:
# Set the flow composition
lfc_lane3 = pb.LaneFlowComposition(lane_index=3, lane_dir=2)
lfc_lane3.assign_lane_data(hourly_truck_flow=[100] * 24, hourly_car_flow=[0] * 24)

# Set the Garage vehicle generator
kernel = [[1.0, 0.08], [1.0, 0.05], [1.0, 0.02]]
vehicle_gen_Garage = pb.VehicleGenGarage(
    garage=Path(".") / "garage.txt", kernel=kernel, garage_format=4
)

# Set the headway generator
headway_gen_Constant = pb.HeadwayGenConstant(constant_speed=36.0, constant_gap=5.0)

# Config the third lane
traffic_gen.add_lane(
    vehicle_gen=vehicle_gen_Garage, headway_gen=headway_gen_Constant, lfc=lfc_lane3
)

# Set the flow composition
lfc_lane4 = pb.LaneFlowComposition(lane_index=4, lane_dir=2)
lfc_lane4.assign_lane_data(
    hourly_truck_flow=[100] * 24,
    hourly_car_flow=[0] * 24,
    hourly_speed_mean=[80 / 3.6 * 10] * 24,
    hourly_speed_std=[10.0] * 24,
)

# Use the same vehicle generator as the third lane.

# Set the headway generator
headway_gen_Freeflow = pb.HeadwayGenFreeflow()

# Config the fourth lane
traffic_gen.add_lane(
    vehicle_gen=vehicle_gen_Garage, headway_gen=headway_gen_Freeflow, lfc=lfc_lane4
)

Set the output to export the generated traffic.

[19]:
output_config = pb.OutputConfig()
output_config.set_vehicle_file_output(
    write_vehicle_file=True,
    vehicle_file_format=4,
    vehicle_file_name="generated_traffic_file.txt",
)

Do the simulation and read the output.

[20]:
sim_task = pb.Simulation(Path(".") / "temp")
sim_task.add_sim(
    traffic=traffic_gen,
    no_day=30,  # 30 days traffic
    output_config=output_config,
    track_progress=True,  # optional, print the simulation days.
    tag="Case4",
)

# Run simulation
sim_task.run(no_core=1)

# Get the output
case4_output = sim_task.get_output()["Case4"]
print(case4_output.get_summary())

from IPython.display import display
display(case4_output.read_data("traffic")["generated_traffic_file"])

Starting simulation...
Day complete...

Flushing buffer of 10000 vehicles at 1/1/0 5:13:46.5162

Flushing buffer of 10000 vehicles at 1/1/0 10:26:25.8773

Flushing buffer of 10000 vehicles at 1/1/0 15:39:30

Flushing buffer of 10000 vehicles at 1/1/0 20:51:52.9777

Flushing buffer of 10000 vehicles at 2/1/0 2:3:25

Flushing buffer of 10000 vehicles at 2/1/0 7:16:6.92188

Flushing buffer of 10000 vehicles at 2/1/0 12:30:14.9937

Flushing buffer of 10000 vehicles at 2/1/0 17:43:19.2472

Flushing buffer of 10000 vehicles at 2/1/0 22:54:45

Flushing buffer of 10000 vehicles at 3/1/0 4:6:24.3359

Flushing buffer of 10000 vehicles at 3/1/0 9:18:17.0485

Flushing buffer of 10000 vehicles at 3/1/0 14:28:27.5164

Flushing buffer of 10000 vehicles at 3/1/0 19:41:25

Flushing buffer of 10000 vehicles at 4/1/0 0:55:25

Flushing buffer of 10000 vehicles at 4/1/0 6:9:12.8006

Flushing buffer of 10000 vehicles at 4/1/0 11:21:45.6165

Flushing buffer of 10000 vehicles at 4/1/0 16:34:43.5363

Flushing buffer of 10000 vehicles at 4/1/0 21:46:43.7012

Flushing buffer of 10000 vehicles at 5/1/0 3:0:5

Flushing buffer of 10000 vehicles at 5/1/0 8:13:45

Flushing buffer of 10000 vehicles at 5/1/0 13:25:0

Flushing buffer of 10000 vehicles at 5/1/0 18:37:35.733

Flushing buffer of 10000 vehicles at 5/1/0 23:50:50

Flushing buffer of 10000 vehicles at 6/1/0 5:3:31.7269

Flushing buffer of 10000 vehicles at 6/1/0 10:17:39.8773

Flushing buffer of 10000 vehicles at 6/1/0 15:30:39.9467

Flushing buffer of 10000 vehicles at 6/1/0 20:43:14.4277

Flushing buffer of 10000 vehicles at 7/1/0 1:57:1.67666

Flushing buffer of 10000 vehicles at 7/1/0 7:8:53.9963

Flushing buffer of 10000 vehicles at 7/1/0 12:21:59.3933

Flushing buffer of 10000 vehicles at 7/1/0 17:36:8.40203

Flushing buffer of 10000 vehicles at 7/1/0 22:50:34.0523

Flushing buffer of 10000 vehicles at 8/1/0 4:1:38.9174

Flushing buffer of 10000 vehicles at 8/1/0 9:14:11.5955

Flushing buffer of 10000 vehicles at 8/1/0 14:28:14.7104

Flushing buffer of 10000 vehicles at 8/1/0 19:42:16.3824

Flushing buffer of 10000 vehicles at 9/1/0 0:54:24.4012

Flushing buffer of 10000 vehicles at 9/1/0 6:7:45

Flushing buffer of 10000 vehicles at 9/1/0 11:18:11.721

Flushing buffer of 10000 vehicles at 9/1/0 16:30:18.8936

Flushing buffer of 10000 vehicles at 9/1/0 21:41:52.5814

Flushing buffer of 10000 vehicles at 10/1/0 2:52:55

Flushing buffer of 10000 vehicles at 10/1/0 8:4:19.162

Flushing buffer of 10000 vehicles at 10/1/0 13:16:15

Flushing buffer of 10000 vehicles at 10/1/0 18:28:40

Flushing buffer of 10000 vehicles at 10/1/0 23:41:18.5865
        1       2       3       4       5       6       7       8       9       10

Flushing buffer of 10000 vehicles at 11/1/0 4:54:50.5777

Flushing buffer of 10000 vehicles at 11/1/0 10:7:45

Flushing buffer of 10000 vehicles at 11/1/0 15:21:1.78421

Flushing buffer of 10000 vehicles at 11/1/0 20:34:33.974

Flushing buffer of 10000 vehicles at 12/1/0 1:46:45

Flushing buffer of 10000 vehicles at 12/1/0 7:1:1.04452

Flushing buffer of 10000 vehicles at 12/1/0 12:12:31.5879

Flushing buffer of 10000 vehicles at 12/1/0 17:25:56.4856

Flushing buffer of 10000 vehicles at 12/1/0 22:37:40

Flushing buffer of 10000 vehicles at 13/1/0 3:50:51.903

Flushing buffer of 10000 vehicles at 13/1/0 9:3:20

Flushing buffer of 10000 vehicles at 13/1/0 14:13:55

Flushing buffer of 10000 vehicles at 13/1/0 19:25:51.6264

Flushing buffer of 10000 vehicles at 14/1/0 0:37:55

Flushing buffer of 10000 vehicles at 14/1/0 5:51:19.9311

Flushing buffer of 10000 vehicles at 14/1/0 11:2:22.8353

Flushing buffer of 10000 vehicles at 14/1/0 16:13:35

Flushing buffer of 10000 vehicles at 14/1/0 21:27:50

Flushing buffer of 10000 vehicles at 15/1/0 2:41:0

Flushing buffer of 10000 vehicles at 15/1/0 7:53:55

Flushing buffer of 10000 vehicles at 15/1/0 13:6:16.0051

Flushing buffer of 10000 vehicles at 15/1/0 18:18:15

Flushing buffer of 10000 vehicles at 15/1/0 23:29:1.94771

Flushing buffer of 10000 vehicles at 16/1/0 4:42:38.2128

Flushing buffer of 10000 vehicles at 16/1/0 9:56:38.8348

Flushing buffer of 10000 vehicles at 16/1/0 15:8:19.443

Flushing buffer of 10000 vehicles at 16/1/0 20:21:30

Flushing buffer of 10000 vehicles at 17/1/0 1:33:49.4805

Flushing buffer of 10000 vehicles at 17/1/0 6:47:35

Flushing buffer of 10000 vehicles at 17/1/0 12:1:10

Flushing buffer of 10000 vehicles at 17/1/0 17:13:14.8282

Flushing buffer of 10000 vehicles at 17/1/0 22:25:50

Flushing buffer of 10000 vehicles at 18/1/0 3:38:55

Flushing buffer of 10000 vehicles at 18/1/0 8:51:9.81434

Flushing buffer of 10000 vehicles at 18/1/0 14:3:20

Flushing buffer of 10000 vehicles at 18/1/0 19:15:40

Flushing buffer of 10000 vehicles at 19/1/0 0:29:30

Flushing buffer of 10000 vehicles at 19/1/0 5:44:0

Flushing buffer of 10000 vehicles at 19/1/0 10:56:20.6654

Flushing buffer of 10000 vehicles at 19/1/0 16:8:10.8742

Flushing buffer of 10000 vehicles at 19/1/0 21:21:15

Flushing buffer of 10000 vehicles at 20/1/0 2:34:5

Flushing buffer of 10000 vehicles at 20/1/0 7:46:44.1838

Flushing buffer of 10000 vehicles at 20/1/0 12:59:24.1479

Flushing buffer of 10000 vehicles at 20/1/0 18:12:35

Flushing buffer of 10000 vehicles at 20/1/0 23:25:15
        11      12      13      14      15      16      17      18      19      20

Flushing buffer of 10000 vehicles at 21/1/0 4:37:25

Flushing buffer of 10000 vehicles at 21/1/0 9:50:41.0028

Flushing buffer of 10000 vehicles at 21/1/0 15:3:27.5088

Flushing buffer of 10000 vehicles at 21/1/0 20:15:54.3635

Flushing buffer of 10000 vehicles at 22/1/0 1:27:45

Flushing buffer of 10000 vehicles at 22/1/0 6:41:8.67708

Flushing buffer of 10000 vehicles at 22/1/0 11:53:30.945

Flushing buffer of 10000 vehicles at 22/1/0 17:7:40

Flushing buffer of 10000 vehicles at 22/1/0 22:20:24.6738

Flushing buffer of 10000 vehicles at 23/1/0 3:33:7.95659

Flushing buffer of 10000 vehicles at 23/1/0 8:47:38.0502

Flushing buffer of 10000 vehicles at 23/1/0 13:58:15

Flushing buffer of 10000 vehicles at 23/1/0 19:9:48.6066

Flushing buffer of 10000 vehicles at 24/1/0 0:21:36.2047

Flushing buffer of 10000 vehicles at 24/1/0 5:32:45

Flushing buffer of 10000 vehicles at 24/1/0 10:46:40

Flushing buffer of 10000 vehicles at 24/1/0 15:58:35

Flushing buffer of 10000 vehicles at 24/1/0 21:10:26.0284

Flushing buffer of 10000 vehicles at 25/1/0 2:22:5.18284

Flushing buffer of 10000 vehicles at 25/1/0 7:35:12.2919

Flushing buffer of 10000 vehicles at 25/1/0 12:46:46.8678

Flushing buffer of 10000 vehicles at 25/1/0 17:57:45

Flushing buffer of 10000 vehicles at 25/1/0 23:11:53.0591

Flushing buffer of 10000 vehicles at 1/2/0 4:23:42.6171

Flushing buffer of 10000 vehicles at 1/2/0 9:33:26.5909

Flushing buffer of 10000 vehicles at 1/2/0 14:47:32.559

Flushing buffer of 10000 vehicles at 1/2/0 20:0:21.1986

Flushing buffer of 10000 vehicles at 2/2/0 1:13:23.4269

Flushing buffer of 10000 vehicles at 2/2/0 6:26:48.9601

Flushing buffer of 10000 vehicles at 2/2/0 11:40:31.1604

Flushing buffer of 10000 vehicles at 2/2/0 16:52:55

Flushing buffer of 10000 vehicles at 2/2/0 22:6:25

Flushing buffer of 10000 vehicles at 3/2/0 3:18:50.4962

Flushing buffer of 10000 vehicles at 3/2/0 8:32:10

Flushing buffer of 10000 vehicles at 3/2/0 13:44:21.3665

Flushing buffer of 10000 vehicles at 3/2/0 18:58:50.9719

Flushing buffer of 10000 vehicles at 4/2/0 0:12:53.8052

Flushing buffer of 10000 vehicles at 4/2/0 5:25:33.4362

Flushing buffer of 10000 vehicles at 4/2/0 10:37:17.9982

Flushing buffer of 10000 vehicles at 4/2/0 15:51:9.87466

Flushing buffer of 10000 vehicles at 4/2/0 21:4:45

Flushing buffer of 10000 vehicles at 5/2/0 2:16:25

Flushing buffer of 10000 vehicles at 5/2/0 7:28:56.5618

Flushing buffer of 10000 vehicles at 5/2/0 12:40:55

Flushing buffer of 10000 vehicles at 5/2/0 17:54:38.4569

Flushing buffer of 10000 vehicles at 5/2/0 23:7:28.5305
        21      22      23      24      25      26      27      28      29      30

Flushing buffer of 1676 vehicles at 6/2/0 0:0:3.36281
['traffic']
Head Year Month Day Hour Min Sec NoAxles NoAxleGroups GVW Velocity Length Lane Dir Trns AxleWeights AxleSpacings AxleWidths
0 1001 1 1 0 0 0 3.689 3 0 371.25945 10.0 10.902 2 1 1.8 [110.61756000000001, 185.69349000000003, 74.93... [3.994, 6.908, 0.0] [1.98, 1.98, 1.98]
1 47799 1 1 0 0 0 5.000 2 2 15.48018 10.0 2.875 2 2 1.8 [7.9461, 7.534080000000001] [2.875, 0.0] [1.98, 1.98]
2 1001 1 1 0 0 0 7.367 3 0 330.67548 10.0 10.228 2 1 1.8 [76.47876000000001, 135.17199000000002, 119.02... [2.715, 7.513, 0.0] [1.98, 1.98, 1.98]
3 42741 1 1 0 0 0 10.000 2 2 15.06816 10.0 2.897 2 2 1.8 [8.328690000000002, 6.739470000000001] [2.897, 0.0] [1.98, 1.98]
4 1001 1 1 0 0 0 11.100 3 0 338.75892 10.0 12.807 2 1 1.8 [51.01200000000001, 110.97072000000001, 176.77... [2.71, 10.097, 0.0] [1.98, 1.98, 1.98]
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
1381671 42332 5 2 0 23 59 55.000 2 2 12.67452 10.0 2.744 2 2 1.8 [6.729660000000001, 5.93505] [2.744, 0.0] [1.98, 1.98]
1381672 1001 5 2 0 23 59 55.680 3 0 221.61771 10.0 11.796 2 1 1.8 [55.142010000000006, 64.25550000000001, 102.2202] [3.887, 7.91, 0.0] [1.98, 1.98, 1.98]
1381673 1001 5 2 0 23 59 59.413 3 0 333.21627 10.0 13.354 2 1 1.8 [175.33413000000002, 122.13450000000002, 35.74... [5.304, 8.05, 0.0] [1.98, 1.98, 1.98]
1381674 47792 6 2 0 0 0 0.000 3 2 122.55633 10.0 5.241 2 2 1.8 [56.407500000000006, 36.31662, 29.84202] [3.924, 1.317, 0.0] [1.98, 1.98, 1.98]
1381675 1001 6 2 0 0 0 3.363 3 0 400.07142 10.0 11.735 2 1 1.8 [158.70618000000002, 111.60837000000001, 129.7... [3.967, 7.768, 0.0] [1.98, 1.98, 1.98]

1381676 rows × 18 columns