LegDynamicProgram

class passengersim.rm.dynamic_prog.LegDynamicProgram(*, carrier: str = '', cfg: Config | None = None, store_bid_prices: 'daily' | 'dcp' = 'daily', reoptimize: 'once' | 'dcp' = 'dcp', arrivals_per_time_slice: float = 0.5, min_time_slices_per_dcp: int = 1, use_current_bp: bool = False, minimum_sample: int = 10, normalization_method: int[0, 1, 2, 3, 4] = 0, cabins: str | list[str] | None = None, capacity_sharing: bool | None = False, capacity_sharing_start_dcp_index: int | None = 0, capacity_sharing_start_lf: float | None = 0.0, snapshot_filters: LegSnapshotFilter | list[LegSnapshotFilter] | None = None, error_log: pathlib.Path | None = None)[source]

Bases: UnbucketedDynamicProgram

Methods

__init__(*[, carrier, cfg, ...])

apply_snapshot_filters(sim, days_prior, ...)

Apply this action's snapshot filters, if any, and return the resulting instruction.

configure([fixed])

Create an RmActionFactory for this action with the given configuration.

get_dcp_index(days_prior[, allow_between])

init(sim)

Initialize the action for the given simulation.

run(sim, days_prior)

Execute the action for the given simulation.

should_run(sim, days_prior)

Determine if the action should run on the given days_prior.

solve_carrier_lp_for_leg_fare_displacements(eng)

Attributes

frequency

The frequency with which to run this action.

produces

requires

udp

error_log

If problems are encountered, write about them in a log file at this location.

store_bid_prices

The store_bid_prices parameter determines how bid prices are used.

reoptimize

The reoptimize parameter determines how often the UDP is re-run.

arrivals_per_time_slice

The number of arrivals in each time slice.

min_time_slices_per_dcp

The minimum number of time slices in each DCP.

use_current_bp

Experimental.

normalization_method

Normalization is used when the adjusted fares don't sum to the fare value 0 = No normalization 1 = Normalize when SUM(adj_fares) > Fare 2 = Normalize when SUM(adj_fares) < Fare 3 = Normalize when SUM(adj_fares) != Fare 4 = Multiply by bid price ratios (based on Juhasz 2023)

cabins

Optional list of cabin codes to optimize.

capacity_sharing

Capacity sharing flag between cabins.

capacity_sharing_start_lf

We can optionally turn on capacity sharing when the coach cabin reaches a specified load factor.

dcps

Set of days prior to departure on which to run this action.

carrier

The carrier upon which to apply this action.

minimum_sample

The minimum sample number before this action will run.

apply_snapshot_filters(sim: Simulation, days_prior: int, *args, **kwargs) SnapshotInstruction | None

Apply this action’s snapshot filters, if any, and return the resulting instruction.

If there are no snapshot filters, or if none of the filters trigger, then this returns None.

classmethod configure(fixed: dict[str, Any] | None = None, **kwargs) RmActionFactory

Create an RmActionFactory for this action with the given configuration.

Each keyword argument name should correspond to a parameter in the RmAction subclass’s __init__ method. The value of each keyword argument will be the keyword argument used in the RmSys that uses this factory.

Fixed values can be provided via the fixed parameter, which is a dictionary of parameter names to fixed values. These values will always be passed to the RmAction constructor, and cannot be overridden via the RmSys.

frequency : Literal['dcp', 'daily', 'daily_pre_dep', 'non_dcp', 'begin_sample', 'end_sample', 'weekly'] = 'daily_pre_dep'

The frequency with which to run this action.

This can be one of the following values: - “dcp”: run only on the specified DCPs. - “daily”: run every day. - “daily_pre_dep”: run every day prior to departure (i.e., days_prior > 0).” - “non_dcp”: run on days that are not in the specified DCPs. - “begin_sample”: run only on the first DCP (i.e., the maximum days_prior). - “end_sample”: run only on the day of departure (i.e., days_prior == 0). - “weekly”: run every 7 days (i.e. when days_prior is a multiple of 7).

The run method of RM actions is actually called every day (as it is implemented as a daily callback), but the first thing the run method should do is check whether it should actually execute on that day, using the should_run method, which uses this frequency setting to determine whether to proceed.

get_dcp_index(days_prior: int, allow_between: bool = False) int
init(sim: Simulation)

Initialize the action for the given simulation.

This is a hook called once at the beginning of the simulation, after the entire network and all core data structures have been set up but before any simulation samples have been run. It can be used to perform any necessary setup before the first call to run. By default, this does nothing, but subclasses can override it if needed.

produces : set[str] = {}
requires : set[str] = {'path_forecast'}
run(sim: Simulation, days_prior: int)

Execute the action for the given simulation.

Subclasses must implement this method.

should_run(sim: Simulation, days_prior: int) bool

Determine if the action should run on the given days_prior.

snapshot_filter_type

alias of LegSnapshotFilter

solve_carrier_lp_for_leg_fare_displacements(eng: SimulationEngine, cabin_code='', days_prior: int = -1)
property udp
error_log

If problems are encountered, write about them in a log file at this location.

If not provided, no error log is written.

store_bid_prices : Literal['daily', 'dcp']

The store_bid_prices parameter determines how bid prices are used.

If store_bid_prices is set to daily, then the bid prices are stored for each day prior to departure by dividing each DCP into its component days, and then the bid prices are stored for each day, so they can vary for the same level of remaining capacity over the days in the DCP. If set to dcp, then the bid prices are stored only for each DCP, and are the same for each day within the DCP.

Note that if store_bid_prices is set to daily, then there must be a call to the udpupdate RM step in the DAILY section of the RM configuration, which updates the bid price algorithm about which day’s bid prices to be using in offer generation.

reoptimize : Literal['once', 'dcp']

The reoptimize parameter determines how often the UDP is re-run.

If reoptimize is set to once, then the UDP is run once for each sample, based only the forecast sales by DCP over the entire booking curve. If set to dcp, then the UDP is re-run for each DCP, and information on prior sales in this sample is used to adjust the displacement costs.

arrivals_per_time_slice : float

The number of arrivals in each time slice.

The number of DP simulation time slices in each time period is scaled so the total arrivals over all path-classes in one time slice is approximately equal to this value. It should not be set to a value greater than 1.0, as this will cause the DP to be under-populated.

min_time_slices_per_dcp : int

The minimum number of time slices in each DCP.

This minimum overrides the arrivals_per_time_slice parameter, and ensures that each DCP has at least this many time slices.

use_current_bp : bool

Experimental.

Turning this on will assume that bid prices have been set by a prior step and just copy them as the displacement values.

normalization_method

Normalization is used when the adjusted fares don’t sum to the fare value 0 = No normalization 1 = Normalize when SUM(adj_fares) > Fare 2 = Normalize when SUM(adj_fares) < Fare 3 = Normalize when SUM(adj_fares) != Fare 4 = Multiply by bid price ratios (based on Juhasz 2023)

cabins

Optional list of cabin codes to optimize. If not provided, this step will optimize on the leg as a whole.

capacity_sharing

Capacity sharing flag between cabins.

When set to True, will use method 3 from Peter Belobaba’s presentation. Higher cabin(s) will get max of combined cabins or itself alone. Lower cabin(s) will get min of combined cabins or itself alone.

capacity_sharing_start_lf

We can optionally turn on capacity sharing when the coach cabin reaches a specified load factor. Based on a suggestion by Darius (PROS)

dcps : set[int]

Set of days prior to departure on which to run this action.

carrier

The carrier upon which to apply this action.

minimum_sample

The minimum sample number before this action will run.