Skip to content

transitlos.flex.core

ctypes wrapper of flexcore.c (compiled on first import, recompiled when the C file changes). No numba: the installed NumPy is too new for it.

Config(tau_band=0.3, gamma=2.0, delta=0.05, dom_tau_h=0.1, dom_tau_v=0.05, h_max=1000000000.0, v_min=0.0, s_min=0.0, p_min=0.0, P=10, K=15, Kc=24, Kcand=48, max_walk_m=1500.0, cell_radius_m=66.0) dataclass

Cap / floor hyperparameters (all in one place; saved with the results).

array()

The configuration as one float64 vector for the C core.

Returns:

Type Description
ndarray

The vector.

Profiles(mode, h, v)

Station profile arrays in the layout the C code reads: [S, P] int8 mode (-1 empty), float32 headway and speed, plus summaries.

valid_mask()

True for the filled profile slots.

Returns:

Type Description

Boolean array [S, P].

args()

The profile arrays as C arguments, in the order the C core expects.

Returns:

Type Description

Tuple of ctypes arguments.

sp_array(p=DEFAULT)

The scoring as one float64 vector for the C core (layout documented at the top of the scoring section of flexcore.c).

Parameters:

Name Type Description Default
p ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description
ndarray

float64 vector.

select_items(mode, h, v, d, q, cap, axes, cfg=Config())

The cap on generic items (tests): indexes chosen, in selection order.

Parameters:

Name Type Description Default
mode

Mode per item (0 bus, 1 tram, 2 rail).

required
h

Headway (min).

required
v

Speed (km/h).

required
d

Walking distance (m).

required
q

Quality (score) per item.

required
cap int

Items to keep.

required
axes int

Number of axes used for diversity.

required
cfg Config

Caps and floors.

Config()

Returns:

Type Description
ndarray

Indices of the chosen items.

select_profiles(off, mode, h, v, cfg=Config(), params=DEFAULT)

Profiles of many stations. off[ns+1] delimits the candidates (mode 0/1/2, headway min, speed km/h) of each station. Returns (idx[ns, P] into the candidate arrays or -1, count[ns], dropped[ns]).

Parameters:

Name Type Description Default
off

[stations + 1] offsets into the candidate arrays.

required
mode

Candidate mode.

required
h

Candidate headway (min).

required
v

Candidate speed (km/h).

required
cfg Config

Caps and floors.

Config()
params ScoreParams

Scoring parameters.

DEFAULT

Returns (lab_station[n,Kc], lab_dist[n,Kc], lab_n[n], lab_cap[n] (labels refused at that node because it was full), stats[stored, dropped_by_dominance, node_cap_hits]).

Parameters:

Name Type Description Default
indptr

CSR row offsets of the street graph.

required
adj

CSR neighbours.

required
w

CSR edge lengths (m).

required
src_node

Source node per snapped station end.

required
src_off

Walking distance from the station to that node (m).

required
src_station

Station index per source.

required
prof Profiles

Station profiles.

required
cfg Config

Caps and floors.

Config()

process_cells(rec_off, ru, rv, ra, rb, rl, lab, prof, cfg=Config(), params=DEFAULT)

Stations per cell. lab = multilabel_search()[:4]. Returns (station[nc,K], dist_m[nc,K] uint16 (65535 empty), flag[nc], cropped[nc]). flag: bit0 the cap was needed, bit1 the candidate list limit was hit, bit2 the search refused labels at a node touching the cell. cropped = stations GENUINELY cut (non-dominated, above the floors, but over the cap or the list limit); stations dropped by floors or dominance are not counted.

Parameters:

Name Type Description Default
rec_off

Offsets of each cell's edge records.

required
ru

Edge start node per record.

required
rv

Edge end node per record.

required
ra

Entry position along the edge (m).

required
rb

Exit position along the edge (m).

required
rl

Edge length (m).

required
lab

multilabel_search()[:4].

required
prof Profiles

Station profiles.

required
cfg Config

Caps and floors.

Config()
params ScoreParams

Scoring parameters.

DEFAULT

ptlos_array(dist, mode, h, v, params=DEFAULT)

Level-of-service value (stop score x walk decay) of each (distance, mode, headway, speed), computed by the C core.

Parameters:

Name Type Description Default
dist

Walking distance (m).

required
mode

Mode (0 bus, 1 tram, 2 rail).

required
h

Headway (min).

required
v

Speed (km/h).

required
params ScoreParams

Scoring parameters.

DEFAULT

Returns:

Type Description
ndarray

float64 array.

recompute_cells(cell_station, cell_dist, prof, params=DEFAULT)

The fast recomputation: (los[nc] float32 on 0-100, slot[nc] int8 winning station slot, profile[nc] int8 winning profile) under params.

Parameters:

Name Type Description Default
cell_station

[cells, K] station per slot.

required
cell_dist

[cells, K] walking distance (m).

required
prof Profiles

Station profiles.

required
params ScoreParams

Scoring parameters.

DEFAULT

recompute_stops(prof, params=DEFAULT)

Stop score of every (station, profile) slot, shape [S, P] float32 (0 for empty slots).

Parameters:

Name Type Description Default
prof Profiles

Station profiles.

required
params ScoreParams

Scoring parameters.

DEFAULT

recompute_cells_fast(cell_station, cell_dist, prof, params=DEFAULT, ss=None)

Like recompute_cells, but the stop scores are computed once (or passed in ss, shape [S, P]) and each cell only does the walk decay.

Parameters:

Name Type Description Default
cell_station

[cells, K] station per slot.

required
cell_dist

[cells, K] walking distance (m).

required
prof Profiles

Station profiles.

required
params ScoreParams

Scoring parameters.

DEFAULT
ss ndarray | None

Optional precomputed stop scores [S, P].

None

Returns:

Type Description

(los, slot, profile) as :func:recompute_cells.