Skip to content

Commit 162800b

Browse files
committed
* commented broken parts
* some analytics things, graph distance cache size increased * added external cost, renamed class to cls/lower cased some things * fixed some bugs * more analytics stuff * formatting * fixed analytics bug where the avg stoplist length was computed incorrectly, and cython continuous space bug, where the coord_range was not pickled * seat capacity and idling duration
1 parent 55e1c10 commit 162800b

11 files changed

Lines changed: 246 additions & 135 deletions

File tree

ridepy/cli.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@
1313

1414
@cli.command()
1515
def update_filenames(
16-
directory: Optional[Path] = typer.Option(
16+
directory: Optional[Path] = typer.Argument(
1717
None, dir_okay=True, file_okay=False, exists=True
1818
)
1919
):
2020
"""
21-
Update filenames to current simulation ids.
21+
Update filenames and JSON structure to up-to-date simulation ids.
22+
23+
This reads all `.json` files, tries to parse the possibly
24+
outdated format and generates a simulation id according
25+
to the current scheme. Afterwards, new JSON files are stored using the
26+
current format at `<new id>.json`.
27+
The simulation data files ending with `.jsonl` are not modified. Instead,
28+
symbolic links are created, pointing from `<new id>.jsonl` to `<old id>.jsonl`.
2229
"""
2330
if directory is None:
2431
directory = Path.cwd()
@@ -35,7 +42,7 @@ def update_events_files(
3542
),
3643
):
3744
"""
38-
Update events files (*.jsonl) to current, flattened structure
45+
Update events files (*.jsonl) to current, flattened structure.
3946
"""
4047
if directory is None:
4148
directory = Path.cwd()

ridepy/extras/io_utils.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
from pathlib import Path
1111

1212
import loky
13+
from tqdm import tqdm
1314

1415
from ridepy.extras.io import read_params_json, create_params_json, ParamsJSONDecoder
1516
from ridepy.extras.simulation_set import SimulationSet, make_file_path
@@ -44,7 +45,7 @@ def update_filenames(target_directory_path: Path):
4445

4546
new_default_base_params = SimulationSet(data_dir=Path()).default_base_params
4647

47-
for old_id in old_ids:
48+
for old_id in tqdm(old_ids):
4849
old_params_path = get_params_path(old_id)
4950
old_events_path = get_events_path(old_id)
5051

@@ -70,6 +71,11 @@ def update_filenames(target_directory_path: Path):
7071
"taxicab_dispatcher_drive_first",
7172
"TaxicabDispatcherDriveFirst",
7273
)
74+
.replace("TransportationRequestCls", "transportation_request_cls")
75+
.replace("VehicleStateCls", "vehicle_state_cls")
76+
.replace("FleetStateCls", "fleet_state_cls")
77+
.replace("RequestGeneratorCls", "request_generator_cls")
78+
.replace("dispatcher_class", "dispatcher_cls")
7379
)
7480

7581
params = json.loads(params_json, cls=ParamsJSONDecoder)
@@ -82,7 +88,7 @@ def update_filenames(target_directory_path: Path):
8288
)
8389

8490
if "general" in params and "dispatcher" in params["general"]:
85-
params["dispatcher"]["dispatcher_class"] = params["general"]["dispatcher"]
91+
params["dispatcher"]["dispatcher_cls"] = params["general"]["dispatcher"]
8692
del params["general"]["dispatcher"]
8793

8894
new_params_json = create_params_json(params=params)

ridepy/extras/simulation_set.py

Lines changed: 25 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ def perform_single_simulation(
173173
- ``seat_capacity``
174174
- (``initial_location`` and ``n_vehicles``) or ``initial_locations``
175175
- ``space``
176-
- ``TransportationRequestCls``
177-
- ``VehicleStateCls``
178-
- ``FleetStateCls``
176+
- ``transportation_request_cls``
177+
- ``vehicle_state_cls``
178+
- ``fleet_state_cls``
179179
- ``request_generator``
180-
- ``RequestGeneratorCls``
180+
- ``request_generator_cls``
181181
- ``dispatcher``
182-
- ``dispatcher_class``
182+
- ``dispatcher_cls``
183183
- ...
184184
data_dir
185185
Existing directory in which to store parameters and events.
@@ -224,14 +224,14 @@ def perform_single_simulation(
224224
event_path.unlink()
225225

226226
space = params["general"]["space"]
227-
RequestGeneratorCls = params["request_generator"].pop("RequestGeneratorCls")
228-
rg = RequestGeneratorCls(
227+
request_generator_cls = params["request_generator"].pop("request_generator_cls")
228+
rg = request_generator_cls(
229229
space=space,
230-
request_class=params["general"]["TransportationRequestCls"],
230+
request_class=params["general"]["transportation_request_cls"],
231231
**params["request_generator"],
232232
)
233233

234-
dispatcher = params["dispatcher"].pop("dispatcher_class")
234+
dispatcher = params["dispatcher"].pop("dispatcher_cls")
235235
if (
236236
params["general"].get("n_vehicles") is not None
237237
and params["general"].get("initial_location") is not None
@@ -256,12 +256,12 @@ def perform_single_simulation(
256256
"must either specify 'n_vehicles' and 'initial_location' or 'initial_locations'"
257257
)
258258

259-
fs = params["general"]["FleetStateCls"](
259+
fs = params["general"]["fleet_state_cls"](
260260
initial_locations=initial_locations,
261261
space=space,
262262
dispatcher=dispatcher(loc_type=space.loc_type, **params["dispatcher"]),
263263
seat_capacities=params["general"]["seat_capacity"],
264-
vehicle_state_class=params["general"]["VehicleStateCls"],
264+
vehicle_state_class=params["general"]["vehicle_state_cls"],
265265
)
266266

267267
# NOTE: this string is matched for testing
@@ -496,39 +496,35 @@ def __init__(
496496
self._param_path_suffix = param_path_suffix
497497

498498
if cython:
499-
SpaceObj = CyEuclidean2D()
499+
space_obj = CyEuclidean2D()
500500
dispatcher = CyBruteForceTotalTravelTimeMinimizingDispatcher
501-
TransportationRequestCls = CyTransportationRequest
502-
VehicleStateCls = CyVehicleState
501+
transportation_request_cls = CyTransportationRequest
502+
vehicle_state_cls = CyVehicleState
503503
else:
504-
SpaceObj = Euclidean2D()
504+
space_obj = Euclidean2D()
505505
dispatcher = BruteForceTotalTravelTimeMinimizingDispatcher
506-
TransportationRequestCls = TransportationRequest
507-
VehicleStateCls = VehicleState
506+
transportation_request_cls = TransportationRequest
507+
vehicle_state_cls = VehicleState
508508

509-
FleetStateCls = SlowSimpleFleetState
510-
RequestGeneratorCls = RandomRequestGenerator
509+
fleet_state_cls = SlowSimpleFleetState
510+
request_generator_cls = RandomRequestGenerator
511511

512512
self.default_base_params = dict(
513513
general=dict(
514514
n_reqs=100,
515515
t_cutoff=None,
516-
space=SpaceObj,
516+
space=space_obj,
517517
n_vehicles=10,
518518
initial_location=(0, 0),
519519
initial_locations=None,
520520
seat_capacity=8,
521-
TransportationRequestCls=TransportationRequestCls,
522-
VehicleStateCls=VehicleStateCls,
523-
FleetStateCls=FleetStateCls,
521+
transportation_request_cls=transportation_request_cls,
522+
vehicle_state_cls=vehicle_state_cls,
523+
fleet_state_cls=fleet_state_cls,
524524
),
525-
dispatcher=dict(dispatcher_class=dispatcher),
525+
dispatcher=dict(dispatcher_cls=dispatcher),
526526
request_generator=dict(
527-
RequestGeneratorCls=RequestGeneratorCls,
528-
rate=10,
529-
max_pickup_delay=3,
530-
max_delivery_delay_rel=1.9,
531-
seed=42,
527+
request_generator_cls=request_generator_cls,
532528
),
533529
)
534530

0 commit comments

Comments
 (0)