Skip to content

Commit

Permalink
Harmonize request generator signature (#270)
Browse files Browse the repository at this point in the history
* harmonized spelling, using cls for class

* fixed notebooks
  • Loading branch information
fxjung authored Sep 5, 2024
1 parent bf1863e commit 41b9085
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions doc/notebooks/introduction_cython.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ from ridepy.util.dispatchers_cython import (

Now that's basically it. We will now do the same configuration as above, using the new Cython components.

There are two little extra changes we have to make: The first is to supply our `RandomRequestGenerator` with the Cython `TransportationRequest` type as `request_class` to make it supply those instead of the Python ones.
There are two little extra changes we have to make: The first is to supply our `RandomRequestGenerator` with the Cython `TransportationRequest` type as `request_cls` to make it supply those instead of the Python ones.

Secondly, the Cython `Dispatcher` needs to know about the type of spatial coordinates it is dealing with and therefore needs to be handed the `TransportSpace`'s `loc_type` attribute.

Expand All @@ -122,7 +122,7 @@ rg = RandomRequestGenerator(
max_delivery_delay_rel=1.9,
space=space,
seed=42,
request_class=CyTransportationRequest
request_cls=CyTransportationRequest
)
n_buses = 50
Expand Down
2 changes: 1 addition & 1 deletion doc/notebooks/introduction_cython_graph.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ rg = RandomRequestGenerator(
max_delivery_delay_rel=1.9,
space=space,
seed=42,
request_class=CyTransportationRequest
request_cls=CyTransportationRequest
)
n_buses = 50
Expand Down
10 changes: 5 additions & 5 deletions src/ridepy/extras/simulation_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,11 @@ def perform_single_simulation(

space = params["general"]["space"]
request_generator_cls = params["request_generator"].pop("request_generator_cls")
rg = request_generator_cls(
space=space,
request_class=params["general"]["transportation_request_cls"],
**params["request_generator"],
)
request_generator_kwargs = {
"space": space,
"request_cls": params["general"]["transportation_request_cls"],
} | params["request_generator"]
rg = request_generator_cls(**request_generator_kwargs)

dispatcher = params["dispatcher"].pop("dispatcher_cls")
if (
Expand Down
6 changes: 3 additions & 3 deletions src/ridepy/util/request_generators.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
rate=1,
seed=42,
pickup_timewindow_offset=0,
request_class=TransportationRequest,
request_cls=TransportationRequest,
max_pickup_delay: float = np.inf,
max_delivery_delay_abs: float = np.inf,
max_delivery_delay_rel: float = np.inf,
Expand All @@ -55,7 +55,7 @@ def __init__(
the rate of requests per time unit
seed
the random seed
request_class
request_cls
the generated requests will be instances of this class. Needed to generate pythonic or cythonic requests at will.
pickup_timewindow_offset
Each request's pickup_timewindow_min will be this much from the creation
Expand All @@ -79,7 +79,7 @@ def __init__(

self.transport_space = space
self.rate = rate
self.request_class = request_class
self.request_class = request_cls
self.pickup_timewindow_offset = pickup_timewindow_offset
self.max_pickup_delay = max_pickup_delay
self.max_delivery_delay_abs = max_delivery_delay_abs
Expand Down
2 changes: 1 addition & 1 deletion test/simulate_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ def simulate(
rg = RandomRequestGenerator(
space=space,
rate=rate,
request_class=request_class,
request_cls=request_class,
seed=seed,
**request_kwargs,
)
Expand Down
6 changes: 3 additions & 3 deletions test/test_bruteforce_dispatcher_cython.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ def test_equivalence_simulator_cython_and_python_bruteforce_dispatcher(seed=42):
)
rg = RandomRequestGenerator(
space=py_space,
request_class=pyds.TransportationRequest,
request_cls=pyds.TransportationRequest,
seed=seed,
rate=1.5,
)
Expand All @@ -176,7 +176,7 @@ def test_equivalence_simulator_cython_and_python_bruteforce_dispatcher(seed=42):
)
rg = RandomRequestGenerator(
space=cy_space,
request_class=cyds.TransportationRequest,
request_cls=cyds.TransportationRequest,
seed=seed,
rate=1.5,
)
Expand Down Expand Up @@ -214,7 +214,7 @@ def test_sanity_in_graph():
space=space,
max_pickup_delay=0,
max_delivery_delay_abs=0,
request_class=cyds.TransportationRequest,
request_cls=cyds.TransportationRequest,
)

transportation_requests = list(it.islice(rg, 1000))
Expand Down

0 comments on commit 41b9085

Please sign in to comment.