Cython Data Structures

This cython module wraps the struct templates exposed from C++ by data_structures_cython.pxd into extension types. Since an extension type obviously cannot be templated, we will use the The Explicit Runtime Dispatch approach approach.

class ridepy.data_structures_cython.LocType

Representing the kind of location objects the simulator supports. either of:

  1. R2LOC (for points in \(\mathbb{R}^2\), holds a tuple[float, float]).

  2. INT (for e.g. graphs).

Note

Use this for simulations using the cythonic components. For simulations using pure pythonic components, the python version of this enum i.e. data_structures.LocType has to be used.

class TransportationRequest(int request_id, double creation_timestamp, origin, destination, pickup_timewindow_min=0, pickup_timewindow_max=inf, delivery_timewindow_min=0, delivery_timewindow_max=inf)

Cython equivalent of pure python dataclass data_structures.TransportationRequest. See its docstring for details of its attributes.

Implementation details for developers

Wraps the C++ templated struct data_structures_cython.cdata_structures.pxd::TransportationRequest[Loc] into a cython extension type. The template parameter Loc defines the type of location objects (Tuple[float, float] for simulations in \(\mathbb{R}^2\)), int for graphs.

However a cython extension type obviously cannot be templated (at compile time, all possible variations of a template must be known). So we will use the Explicit Run-Time Dispatch approach, see this module’s docstring or The Explicit Runtime Dispatch approach for details.

Holds a shared_ptr to C++ templated class TransportationRequest. This class can be instantiated from an existing shared_ptr (only from the cython side and not from the calling python code). See the staticmethods cdef TransportationRequest from_c_r2loc and cdef TransportationRequest from_c_int for details.

Note

We will try to infer Loc from what origin contains. The inference can be easily fooled by passing e.g. origin = 2, destination = (0.3, 1.5).

__reduce__(self)
asdict(self)

Returns a dict representation of itself.

class InternalRequest(int request_id, double creation_timestamp, location)

Cython equivalent of pure python dataclass data_structures.InternalRequest. See its docstring for details of its attributes.

Implementation details for developers

Wraps the C++ templated struct data_structures_cython.cdata_structures.pxd::InternalRequest[Loc] into a cython extension type. The template parameter Loc defines the type of location objects (Tuple[float, float] for simulations in \(\mathbb{R}^2\)), int for graphs.

However a cython extension type obviously cannot be templated (at compile time, all possible variations of a template must be known). So we will use the Explicit Run-Time Dispatch approach, see this module’s docstring or The Explicit Runtime Dispatch approach for details.

Holds a shared_ptr to C++ templated class InternalRequest. This class can be instantiated from an existing shared_ptr (only from the cython side and not from the calling python code). See the staticmethods cdef InternalRequest from_c_r2loc and cdef InternalRequest from_c_int for details.

Note

We will try to infer Loc from what location contains.

__reduce__(self)
asdict(self)
class Stop(location, Request request, StopAction action, double estimated_arrival_time, int occupancy_after_servicing, double time_window_min=0, double time_window_max=inf)

Cython equivalent of pure python dataclass data_structures.Stop. See its docstring for details of its attributes.

Implementation details for developers

Wraps the C++ templated struct data_structures_cython.cdata_structures.pxd::Stop[Loc] into a cython extension type. The template parameter Loc defines the type of location objects (Tuple[float, float] for simulations in \(\mathbb{R}^2\)), int for graphs.

However a cython extension type obviously cannot be templated (at compile time, all possible variations of a template must be known). So we will use the Explicit Run-Time Dispatch approach, see this module’s docstring or The Explicit Runtime Dispatch approach for details.

Holds a pointer to C++ templated class Stop. This class can be instantiated from an existing pointer (only from the cython side and not from the calling python code). See the staticmethods cdef Stop from_c_r2loc and cdef Stop from_c_int for details.

Note

We will try to infer the LocType from what location contains. Do not pass incompatible combinations like a Request with LocType=R2LOC and location of type int.

__deepcopy__(self, *args, **kwargs)
__reduce__(self)
asdict(self)
class Stoplist(python_stoplist, loc_type)

The cythonic equivalent of data_structures.Stoplist, which is just a python list of data_structures.Stop.

Note

An instance of this class doies not support most of the functionalities of python lists, e.g. slicing. Please take a look at the available methods. In particular, use stoplist.remove_nth_elem(int) instead of stoplist.pop(int) or del stoplist[i].

Implementation details for developers

Wraps a C++ vector of data_structures_cython.cdata_structures.pxd::Stop[Loc] into a cython extension type. The template parameter Loc defines the type of location objects (Tuple[float, float] for simulations in \(\mathbb{R}^2\)), int for graphs.

However a cython extension type obviously cannot be templated (at compile time, all possible variations of a template must be known). So we will use the Explicit Run-Time Dispatch approach, see this module’s docstring or The Explicit Runtime Dispatch approach for details.

This class can be instantiated from an existing C++ vector, only from the cython side and not from the calling python code. See the staticmethods Stoplist from_c_r2loc and Stoplist from_c_int for details.

Parameters:
  • python_stoplist – A python list of Stop objects

  • loc_type – The type of location objects, as defined in the enum LocType

Note

Do not pass a list of pure pythonic Stop objects to __init__, this will lead to a crash. Only pass a list of cython extension Stop objects.

The Stop objects are copied here, therefore the original Stop objects can safely be garbage collected/ otherwise deleted.

__reduce__(self)
remove_nth_elem(self, int n)

Removes the nth element. Does not return anything.

to_pys(self)