Skip to content

Commit

Permalink
Added request generator interface (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
fxjung authored Apr 8, 2024
1 parent b2b3f58 commit 2e96956
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 10 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
repos:
- repo: https://github.com/python/black
rev: 24.1.1
rev: 24.3.0
hooks:
- id: black
language_version: python3.9
Expand All @@ -9,4 +9,4 @@ repos:
hooks:
- id: blacken-docs
additional_dependencies:
- black==24.2.0
- black==24.3.0
4 changes: 4 additions & 0 deletions doc/request-generator-guide.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Writing a request generator
===========================

Request generators are iterators
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ dependencies = [

[project.optional-dependencies]
dev = [
"black==24.2.0",
"black==24.3.0",
"commitizen",
"pdbpp",
"pre-commit",
Expand Down
5 changes: 5 additions & 0 deletions src/ridepy/data_structures.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from collections.abc import Iterator

from numpy import inf
from abc import ABC, abstractmethod
from enum import Enum
Expand Down Expand Up @@ -219,6 +221,9 @@ def __eq__(self, other: "TransportSpace"):
return type(self) == type(other) and self.asdict() == other.asdict()


class RequestGenerator(Iterator): ...


Stoplist = List[Stop]
"""A list of `.Stop` objects. Specifies completely the current position and future actions a vehicle will make."""

Expand Down
37 changes: 30 additions & 7 deletions src/ridepy/util/request_generators.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import random
from abc import (
ABC,
abstractmethod,
abstractproperty,
abstractclassmethod,
abstractstaticmethod,
)
from typing import Optional, Union

import numpy as np

from ridepy.data_structures import TransportSpace, TransportationRequest
from ridepy.data_structures import (
TransportSpace,
TransportationRequest,
RequestGenerator,
)

from ridepy.util.spaces import Euclidean2D
from ridepy.util.spaces_cython import Euclidean2D as CyEuclidean2D


class RandomRequestGenerator:
class RandomRequestGenerator(RequestGenerator):
"""
Generates random requests in the chosen transport space with a certain rate.
The timewindows for the request are configurable.
Expand Down Expand Up @@ -39,16 +55,23 @@ def __init__(
the rate of requests per time unit
seed
the random seed
pickup_timewindow_offset
each request's pickup_timewindow_min will be this much from the creation timestamp
request_class
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
timestamp.
max_pickup_delay
see class docstring
The maximum delay between the request creation timestamp and the pickup
time.
max_delivery_delay_abs
see class docstring
The maximum absolute delay between the request creation timestamp and the
delivery time.
max_delivery_delay_rel
see class docstring
The maximum **delay** between the request creation timestamp and the delivery
time relative to the direct actual direct travel time. Example: if the
direct travel time is 10 minutes and ``max_delivery_delay_rel`` is 0.5,
the delivery time will be at most 15 minutes after request creation.
I.e., delta_max = 1 + max_delivery_delay_rel.
"""
if seed is not None:
np.random.seed(seed)
Expand Down

0 comments on commit 2e96956

Please sign in to comment.