openmobisim.fleet#
A fleet day without a run: shared-mobility services, a table of trips, one simulated day.
service_bike_docked and service_taxi describe a service: its docks, or its vehicles and
chargers, its options and its name. fleet_day runs every service’s day together on the
fleet engine, from a table of trips that use them and, optionally, the road times of an
earlier run (road_times_read), and returns what became of each trip and of each dock.
A frozen day, an approximation: the travellers’ choices and the traffic are held fixed.
Each trip’s service is given; a shared-bike trip takes the dock nearest its origin on foot and
returns at the dock nearest its destination on foot, whatever the docks hold; a taxi drives on
the given road times and adds no traffic, and a request no taxi can pick up within the fleet’s
cancel limit is cancelled and ends there. What a full run adds — travellers choosing among modes
and docks — is not here; a run’s own service day is played the same way, once the run has
stopped. The result
says so (FleetDay.fidelity).
An operator (policy=, see openmobisim.operator) may steer the services during the
day: move bikes between docks, set docks’ target levels, relocate or charge taxis. Its
decisions, accepted or refused with the reason, are in FleetDay.decisions().
Attributes#
Classes#
What one fleet day did ( |
|
A fleet day to step through ( |
|
|
|
One shared-mobility service: its kind, name, parts and options (see the makers). |
Functions#
|
Run every service's day together on the fleet engine, from a table of trips. |
|
A fleet day to step through: |
|
The road times of an earlier run, from its |
|
A docked bike-sharing service: bikes counted per dock. |
|
An electric taxi fleet: vehicles tracked one by one, with a battery. |
Module Contents#
- class openmobisim.fleet.FleetDay#
What one fleet day did (
fleet_day).- decisions()#
Every decision the policy took, in the order taken, accepted or refused.
Columns:
step(the policy step’s index, 0 at the window’s start),t_s(its second),service,kind(move,target,relocate,charge), the parameters by id (from_dock,to_dock,n,dock,level,vehicle,node,charger,to_soc;Noneor NaN where a kind has none),accepted,reason(why it was refused,Noneif accepted),executed_s(the second it started),finished_s(the van’s or vehicle’s arrival, the charge’s end; NaN if refused or not finished by the window’s end),moved(a move’s bikes in the van),metres(the drive’s),from_target(a move the solver made for the step’s targets).- Return type:
openmobisim.table.Columns
- trip_results()#
What became of each trip given, in the order given.
Columns:
trip_id,service,outcome(completed;cancelled: no taxi within the cancel limit, or no bike at any dock tried;unfinished: still waiting or riding when the window ended;not_requested: asking after the window;not_planned: no leg could be planned),requested_s,pickup_s(a taxi at the pickup; the bike taken),dropoff_s(a taxi’s drop-off at the destination; the bike returned),arrived_s(at the destination, a shared bike’s walk on included; after a bike trip that found no bike, on foot from the last dock tried; NaN after a cancelled taxi request),waiting_s(a taxi’s, from the request to the pickup, the dispatch delay included; NaN if never picked up; 0 for a bike),dock_from,dock_to,vehicle_id,extra_walk_s,redirections,overflow.- Return type:
openmobisim.table.Columns
- counts: dict[str, float]#
- decision_rows: openmobisim.table.Columns#
- dock_bins: dict[str, openmobisim.table.Columns]#
- fidelity: str#
- frozen: dict[str, Any] | None = None#
- plan: dict[str, int]#
- policy: dict[str, Any] | None#
- seconds: dict[str, float]#
- services: list[str]#
- trips: openmobisim.table.Columns#
- class openmobisim.fleet.FleetEnvironment(inner, network=None, *, frozen=None)#
A fleet day to step through (
fleet_environment).- Parameters:
inner (Any)
network (Any)
frozen (dict[str, Any] | None)
- fork()#
A copy of the day at its clock, to simulate ahead without touching this one.
- Return type:
- reset(seed=0)#
Start the day with
seed:(view, info)at the window’s start.- Parameters:
seed (int)
- Return type:
tuple[Any, dict[str, Any]]
- step(decisions=None)#
Apply
decisionsat the clock and run one step.Returns
(view, reward, terminated, truncated, info).- Parameters:
decisions (collections.abc.Sequence[Any] | None)
- Return type:
tuple[Any, float, bool, bool, dict]
- frozen = None#
- property t: float#
The clock, in seconds from midnight.
- Return type:
float
- class openmobisim.fleet.FleetVectorEnvironment(inner, network=None, *, frozen=None)#
nfleet days stepped together, in parallel (fleet_environment(..., n=...)).One call steps every day; the engines run in parallel on the machine’s cores. Seed
kgives the same day here as in a single environment.observationandactionencode one day’s view or decisions, as forFleetEnvironment.- Parameters:
inner (Any)
network (Any)
frozen (dict[str, Any] | None)
- reset(seeds)#
Start each day with its seed (one per day):
(views, infos).- Parameters:
seeds (collections.abc.Sequence[int])
- Return type:
tuple[list[Any], list[dict[str, Any]]]
- step(decisions)#
Apply one list of decisions per day and run each one step.
Returns
(views, rewards, terminated, truncated, infos): lists of one per day,rewardsan array.- Raises:
ValueError – Unless there is one list per day.
- Parameters:
decisions (collections.abc.Sequence[collections.abc.Sequence[Any] | None])
- Return type:
tuple[list[Any], numpy.ndarray, list[bool], list[bool], list[dict[str, Any]]]
- frozen = None#
- property t: list[float]#
Each day’s clock, in seconds from midnight.
- Return type:
list[float]
- class openmobisim.fleet.Service#
One shared-mobility service: its kind, name, parts and options (see the makers).
- chargers: Any = None#
- docks: Any = None#
- kind: str#
- name: str#
- options: collections.abc.Mapping[str, float]#
- vehicles: Any = None#
- openmobisim.fleet.fleet_day(network, services, trips=None, *, frozen=None, window=None, road_times=None, seed=None, policy=None, policy_options=None, zone_grid_m=ZONE_GRID_M)#
Run every service’s day together on the fleet engine, from a table of trips.
Or from a run’s frozen day (
frozen, a folderRun.freezewrote): the legs of the run’s service day as the run played them (its last loading’s service trips: the docks the travellers chose, the second each asks for a bike or a taxi, its ride and walk), on the road times its taxis drove on, over its window. With no policy, the day replays the run’s service day: every leg’s outcome, seconds, docks and vehicle, and the docks’ bins, bikes and taxis, are the run’s own. The services must be the run’s (the same names, docks, bikes and options) and the network too: either differing is refused, saying what differs. Each trip of the result is a leg: itstrip_idthe trip’s index in the run (Run.trip_results()’strip);FleetDay.frozenholds the day’ssetup.json.- Parameters:
network (Any) – The road network (its walk and bike layers are made from it).
services (collections.abc.Sequence[Service]) – The services (
service_bike_docked,service_taxi), names unique.trips (str | collections.abc.Iterable[collections.abc.Mapping[str, Any]] | None) – One row per trip:
origin_lon, origin_lat, destination_lon, destination_lat,departure(seconds from midnight, or"HH:MM"), and optionallytrip_id,service(a service’s name; required with more than one service) andweight(the people it stands for, 1 by default). A CSV/TSV path or text, or rows as dicts.Nonewithfrozen.frozen (str | pathlib.Path | None) – A folder
Run.freezewrote, in place oftripsandroad_times.window (tuple[object, object] | None) – The day’s start and end (seconds or
"HH:MM"); a trip asking before it opens asks at its start, one after it ends is never asked.None: 07:30 to 09:30, or a frozen day’s own (another window is refused withfrozen).road_times (RoadTimes | None) – An earlier run’s road times (
road_times_read);None: free flow.seed (int | None) – The day’s seed (a policy’s draws);
None: 0, or a frozen day’s (the run’s master seed).policy (Any) – An operator steering the services (
openmobisim.operator): a policy object (step(view)), a built-in one (policy_threshold(...)), a name (built-in or registered withpolicy_register), orNone: no operator.policy_options (collections.abc.Mapping[str, float] | None) – A named policy’s options (
{"low": 0.1}for"threshold").zone_grid_m (float) – The side of the square zones a view groups places by, in metres (
ZONE_GRID_M, 1 000: an assumption, uncalibrated).
- Raises:
ValueError – For a service, trip, option or policy that is not valid, road times of another network, or a decision naming an id that does not exist; with
frozen, for another network, other services, another window, or trips or road times given too.FileNotFoundError – For a
frozenfolder withoutsetup.json.Exception – A Python policy’s own exception, which stops the day.
- Return type:
- openmobisim.fleet.fleet_environment(network, services, trips=None, *, frozen=None, window=None, road_times=None, step_s=900.0, reward_weights=None, legs_keep=1.0, departure_jitter_s=0.0, n=1, zone_grid_m=ZONE_GRID_M)#
A fleet day to step through:
reset(seed), thenstep(decisions)until the day ends.The day is
fleet_day’s (the same services, trips, window and road times; a frozen day: the travellers’ choices and the traffic are held fixed), with no policy of its own: the caller decides at each step.reset(seed)returns(view, info)at the window’s start;step(decisions)applies the decisions (as a policy returns them:operator.Move,Target,Relocate,Charge), runsstep_sseconds and returns(view, reward, terminated, truncated, info); at the window’s endinfo["outcome"]holds the day’s tables.fork()copies the day at its clock, to simulate ahead without touching it. A view cannot be read after the next step.The reward of a step is minus
w_cancelled× the people whose request was cancelled (a taxi request no taxi could pick up within the cancel limit, which ends there; a traveller who found no bike at any dock tried),w_wait× the minutes they waited,w_walk× the extra minutes they walked (between docks: shared bikes only), andw_km× the kilometres the policy’s decisions drove (vans moving bikes, taxis relocating or driving to charge), each counted once, when its leg ends (REWARD_WEIGHTS, uncalibrated).info["refused"]holds, per decision given at the step, why the engine refused it (None: accepted).With
nabove 1 the result is aFleetVectorEnvironment:ndays stepped together, in parallel,reset(seeds)taking one seed per day andstepone list of decisions per day. Seedkgives the same day there as here.observation(view, spec)andaction(vector, spec)turn views and decisions into arrays of fixed shapes, for learning methods (specis described withobservation).With
frozen(a folderRun.freezewrote), the day is a run’s last loading: its legs as the run played them and its road times, in place of trips;frozenon the environment holds itssetup.json.legs_keepanddeparture_jitter_svary it by seed as they vary a day of trips; with neither, every seed replays the run’s day.- Parameters:
network (Any) – The road network.
services (collections.abc.Sequence[Service]) – The services (
service_bike_docked,service_taxi).trips (str | collections.abc.Iterable[collections.abc.Mapping[str, Any]] | None) – The trips, as for
fleet_day;Nonewithfrozen.frozen (str | pathlib.Path | None) – A run’s frozen day, as for
fleet_day.window (tuple[object, object] | None) – The day’s start and end;
None: 07:30 to 09:30, or a frozen day’s own.road_times (RoadTimes | None) – An earlier run’s road times, or
None: free flow (a frozen day’s own withfrozen).step_s (float) – The seconds between steps.
reward_weights (collections.abc.Mapping[str, float] | None) – Weights by name in place of
REWARD_WEIGHTS’; a name not among them is refused with the list.legs_keep (float) – The share of the trips’ legs each day keeps, drawn by the day’s seed (1: all).
zone_grid_m (float) – The side of the square zones a view groups places by, in metres (
ZONE_GRID_M, 1 000: an assumption, uncalibrated).departure_jitter_s (float) – How far each kept leg’s request moves, drawn by the day’s seed, in seconds either way (0: not at all). With these two, each seed of
resetis another day; both thin and shift the same trips, they do not draw a new demand.n (int) – How many days to step together (1: a
FleetEnvironment).
- Raises:
ValueError – As
fleet_day.- Return type:
Any
- openmobisim.fleet.road_times_read(link_bins)#
The road times of an earlier run, from its
link_bins.parquet.Each link’s mean time in each bin is
pcu_seconds / pcu; a link or bin without a row is taken at free flow. The run’s network must be the network the fleet day is given (its fingerprint is checked). These times are by the bin a vehicle left the link, which the fleet day reads as the bin it enters: an approximation.- Parameters:
link_bins (str | Any) – The path of a run’s
link_bins.parquet.- Raises:
ImportError – Without pyarrow — install
openmobisim[all].- Return type:
RoadTimes
- openmobisim.fleet.service_bike_docked(docks, *, name='bike_share', options=None)#
A docked bike-sharing service: bikes counted per dock.
- Parameters:
docks (Any) – Its docks (
dock_read_tableordock_read_gbfs).name (str) – Its name, unique among a day’s services.
options (collections.abc.Mapping[str, float] | None) – Its options by name (
walk_max_s,redirect_max,redirect_max_m,pickup_s,return_s,ride_factor,start_share,fail_s,bin_s,handling_s,van_bikes,candidates,snap_m, andlog_events: 1 to keep the day’s log of events, the default, 0 not to, for a very large run, whose results are otherwise the same); a name not among them is refused with the list. A fleet day does not readcandidatesorfail_s.
- Return type:
- openmobisim.fleet.service_taxi(vehicles, chargers=None, *, name='taxi', options=None)#
An electric taxi fleet: vehicles tracked one by one, with a battery.
- Parameters:
vehicles (Any) – Its vehicles (
vehicle_read_table).chargers (Any) – Its chargers (
charger_read_table), orNone: its vehicles never charge.name (str) – Its name, unique among a day’s services.
options (collections.abc.Mapping[str, float] | None) – Its options by name (
battery_kwh,kwh_per_km,soc_start,reserve_soc,charge_below,charge_to,charger_kw,request_cancel_s,boarding_s,dispatch_delay_s,snap_m,charger_reach_s, andlog_events: 1 by default, 0 to keep no event log in a very large run,taxi_events.parquetthen empty); a name not among them is refused with the list.request_cancel_s(600 s, an assumption): a request is cancelled if no taxi can pick it up within this time.dispatch_delay_s(120 s, an assumption): the time from a request being matched to the taxi setting off (the app’s dispatch and the driver’s acceptance), so the waiting time counts it, and a taxi is matched to a request only if the dispatch delay and its drive fit withinrequest_cancel_s; adispatch_delay_sat or aboverequest_cancel_sis refused.boarding_s(60 s, an assumption): the time to get in at the pickup.
- Return type:
- openmobisim.fleet.REWARD_WEIGHTS: dict[str, float]#
- openmobisim.fleet.TAXI_STATES: tuple[str, ...] = ('idle', 'to_pickup', 'occupied', 'to_charger', 'queued_at_charger', 'charging', 'relocating')#
- openmobisim.fleet.ZONE_GRID_M: float = 1000.0#