Leg forecasts

Inspect the forecasts used for selected legs. The tracer takes a snapshot at the beginning of each retained sample and averages the forecast tables across samples.

Collect the data

Load the 3MKT demo and attach the tracer before running it:

import passengersim as pax
from passengersim.tracers.forecasts import LegForecastTracer

cfg = pax.Config.from_yaml(pax.demo_network("3MKT"))
cfg.simulation_controls.num_trials = 1
cfg.simulation_controls.num_samples = 800
cfg.simulation_controls.burn_samples = 50
cfg.simulation_controls.show_progress_bar = False
cfg.db = None
cfg.outputs.reports.clear()
cfg.outputs._write_no_files()

with pax.Simulation(cfg) as sim:
    LegForecastTracer(leg_ids=[101, 111]).attach(sim)
    summary = sim.run()
table = summary.callback_data["selected_leg_forecasts"]

To enable the same tracer in YAML:

callbacks:
  selected_leg_forecasts:
    parameters:
      leg_ids: [101, 111]

Read the results

Use the dashboard to explore the forecasts by booking class and data collection point (DCP). It shows forecast demand and its spread, expected demand within each timeframe, and sales and closure history where available.

table.xs(101, level="leg_id")["mean_to_departure"].head()
booking_class Y0 Y1 Y2 Y3 Y4 Y5
days_prior
63 13.072979 15.958167 10.995991 4.555502 29.473970 13.946011
56 12.373492 15.069346 10.320606 4.416118 23.263560 10.449293
49 11.757851 14.308372 9.788555 4.310887 20.339303 8.797925
42 11.305594 13.700526 9.335939 4.209964 16.921252 6.942897
35 10.663851 12.951295 8.778401 4.099759 13.604226 5.060979
from passengersim.tracers.forecasts import fig_leg_forecast_dashboard

fig_leg_forecast_dashboard(summary, leg_id=101)

Leg forecasts omit adjusted fares. For that view, use the path forecast tracer.