diff --git a/notebooks/MC_RAPTOR.ipynb b/notebooks/MC_RAPTOR.ipynb index 9dcdc9f..7435ae8 100644 --- a/notebooks/MC_RAPTOR.ipynb +++ b/notebooks/MC_RAPTOR.ipynb @@ -1,1673 +1,1613 @@ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Reversed MC RAPTOR\n", "\n", "## Left out at this stage:\n", "\n", "- Real probabilities\n", "- Realistic time to get out of one transport and walk to the platform of the next. Instead, we just set it to 2 minutes, no matter what.\n", "\n", "## Encoding the data structures\n", "### General considerations\n", "We adhere to the data structures proposed by Delling et al. These structures aim to minimize read times in memory by making use of consecutive in-memory adresses. Thus, structures with varying dimensions (e.g dataframes, python lists) are excluded. We illustrate the difficulty with an example. \n", "\n", "Each route has a potentially unique number of stops. Therefore, we cannot store stops in a 2D array of routes by stops, as the number of stops is not the same for each route. We adress this problem by storing stops consecutively by route, and keeping track of the index of the first stop for each route.\n", "\n", "This general strategy is applied to all the required data structures, where possible.\n", "\n", "### routes\n", "The `routes` array will contain arrays `[n_trips, n_stops, pt_1st_stop, pt_1st_trip]` where all four values are `int`. To avoid overcomplicating things and try to mimic pointers in python, `pt_1st_stop` and `pt_1st_trip` contain integer indices." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "lines_to_next_cell": 0 }, "outputs": [], "source": [ "import numpy as np\n", "import pickle\n", "\n", "def pkload(path):\n", " with open(path, 'rb') as f:\n", " obj = pickle.load(f)\n", " return obj" ] }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 3, "metadata": { "lines_to_next_cell": 0 }, "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "(741, 4)\n" + ] + }, { "data": { "text/plain": [ - "array([[ 1, 11, 0, 0],\n", - " [ 1, 11, 11, 11],\n", - " [ 1, 11, 22, 22],\n", + "array([[ 26, 3, 0, 0],\n", + " [ 24, 14, 3, 78],\n", + " [ 24, 14, 17, 414],\n", " ...,\n", - " [ 1, 6, 237432, 245713],\n", - " [ 1, 13, 237438, 245719],\n", - " [ 3, 2, 237451, 245732]], dtype=uint32)" + " [ 27, 8, 7828, 245237],\n", + " [ 25, 11, 7836, 245453],\n", + " [ 5, 2, 7847, 245728]], dtype=uint32)" ] }, - "execution_count": 2, + "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "routes = pkload(\"../data/routes_array.pkl\").astype(np.uint32)\n", + "print(routes.shape)\n", "routes" ] }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 4, "metadata": { "lines_to_next_cell": 0 }, "outputs": [], "source": [ "# routes = np.array([[2, 3, 0, 0], #r0\n", "# [2, 3, 3, 6], #r1\n", "# [2, 2, 6, 12], #r2\n", "# [2, 2, 8, 16]]) # r3" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### routeStops\n", "`routeStops` is an array that contains the ordered lists of stops for each route. `pt_1st_stop` in `routes` is required to get to the first stop of the route. is itself an array that contains the sequence of stops for route $r_i$." ] }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 5, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "(237453,)\n", + "(7849,)\n", "1406\n" ] }, { "data": { "text/plain": [ - "array([ 0, 1, 2, ..., 1187, 573, 778], dtype=uint16)" + "array([ 0, 1, 2, ..., 759, 554, 493], dtype=uint16)" ] }, - "execution_count": 4, + "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "routeStops = pkload(\"../data/route_stops_array.pkl\").astype(np.uint16)\n", "print(routeStops.shape)\n", "print(routeStops.max())\n", "routeStops" ] }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 6, "metadata": { "lines_to_next_cell": 0 }, "outputs": [], "source": [ "# routeStops = np.array([0, 1, 2, # A, B, C\n", "# 3, 2, 4, # D, C, E\n", "# 0, 4, # A, E\n", "# 5, 4]) #F, E" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### stopTimes\n", "\n", "The i-th entry in the `stopTimes` array is itself an array which contains the arrival and departure time at a particular stop for a particular trip. `stopTimes` is sorted by routes, and then by trips. We retrieve the index of the first (earliest) trip of the route with the pointer `pt_1st_trip` stored in `routes`. We may use the built-in `numpy` [date and time data structures](https://blog.finxter.com/how-to-work-with-dates-and-times-in-python/). In short, declaring dates and times is done like this: `np.datetime64('YYYY-MM-DDThh:mm')`. Entries with a `NaT` arrival or departure times correspond to beginning and end of trips respectively.\n", "\n", "Note that trips are indexed implicitely in stopTimes, but we decided to change a little bit from the paper and index them according to their parent route instead of giving them an absolute index. It makes things a bit easier when coding the algorithm." ] }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 7, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "(245738, 2)\n" ] }, { "data": { "text/plain": [ - "array([[ 'NaT', '2020-05-21T16:53:00.000000000'],\n", - " ['2020-05-21T16:55:00.000000000', '2020-05-21T16:55:00.000000000'],\n", - " ['2020-05-21T16:57:00.000000000', '2020-05-21T16:57:00.000000000'],\n", + "array([[ 'NaT', '2020-05-21T07:18:00.000000000'],\n", + " ['2020-05-21T07:23:00.000000000', '2020-05-21T07:23:00.000000000'],\n", + " ['2020-05-21T07:29:00.000000000', 'NaT'],\n", " ...,\n", " ['2020-05-21T15:10:00.000000000', 'NaT'],\n", - " [ 'NaT', '2020-05-21T16:45:00.000000000'],\n", - " ['2020-05-21T17:05:00.000000000', 'NaT']],\n", + " ['2020-05-21T19:00:00.000000000', '2020-05-21T19:05:00.000000000'],\n", + " ['2020-05-21T19:20:00.000000000', 'NaT']],\n", " dtype='datetime64[ns]')" ] }, - "execution_count": 6, + "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stopTimes = pkload(\"../data/stop_times_array.pkl\")\n", "print(stopTimes.shape)\n", "stopTimes" ] }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 8, "metadata": {}, "outputs": [], "source": [ "# stopTimes = np.array([\n", "# # r0, t0\n", "# [None, '2020-05-11T08:00'],\n", "# ['2020-05-11T08:25', '2020-05-11T08:30'],\n", "# ['2020-05-11T08:55', None],\n", "\n", "# # ro, t1\n", "# [None, '2020-05-11T08:10'],\n", "# ['2020-05-11T08:35', '2020-05-11T08:40'],\n", "# ['2020-05-11T09:05', None],\n", " \n", "# # r1, t0 \n", "# [None, '2020-05-11T08:00'],\n", "# ['2020-05-11T08:05', '2020-05-11T08:10'],\n", "# ['2020-05-11T08:15', None],\n", "\n", "# # r1, t1\n", "# [None, '2020-05-11T09:00'],\n", "# ['2020-05-11T09:05', '2020-05-11T09:10'],\n", "# ['2020-05-11T09:15', None],\n", " \n", "# #r2, t0\n", "# [None, '2020-05-11T08:20'],\n", "# ['2020-05-11T09:20', None],\n", " \n", "# #r2, t1\n", "# [None, '2020-05-11T08:00'],\n", "# ['2020-05-11T08:45', None],\n", " \n", "# #r3, t0\n", "# [None, '2020-05-11T08:05'],\n", "# ['2020-05-11T08:25', None],\n", "\n", "# #r3, t1\n", "# [None, '2020-05-11T08:45'],\n", "# ['2020-05-11T09:05', None]],\n", "# dtype='datetime64')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "`NaT` is the `None` equivalent for `numpy datetime64`." ] }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 9, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "[ True False]\n" ] } ], "source": [ "print(np.isnat(stopTimes[0]))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "### stopRoutes\n", "\n", "`stopRoutes` contains the routes associated with each stop. We need the pointer in `stops` to index `stopRoutes` correctly." ] }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 10, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "(237810,)\n" + "(7849,)\n" ] }, { "data": { "text/plain": [ - "array([ 0, 1, 2, ..., 16136, 16146, 16147], dtype=uint32)" + "array([ 0, 1, 88, ..., 736, 735, 736], dtype=uint32)" ] }, - "execution_count": 9, + "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stopRoutes = pkload(\"../data/stop_routes_array.pkl\").flatten().astype(np.uint32)\n", "print(stopRoutes.shape)\n", "stopRoutes" ] }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ "# stopRoutes = np.array([0, 2, # A\n", "# 0, # B\n", "# 0,1, # C\n", "# 1, # D\n", "# 1, 2, 3, # E\n", "# 3]) # F" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## transfers\n", "The `transfers` is a 2D `np.ndarray` where each entry `[p_j, time]` represents the time it takes to reach p_j from stop p_i. The correspondance between the indexing of `transfers` and p_i is done via `stops[p_i][1]`, i.e the first entry in `transfers` containing a connection from stop p_i.\n", "\n", "As we cannot store different data types in numpy arras, `time` will have to be converted to `np.timedelta64`, the format used to make differences between `np.datetime.64` variables. We will consider all `time` values as **positive values in seconds**." ] }, { "cell_type": "code", - "execution_count": 11, + "execution_count": 18, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ - "(12564, 2)\n" + "(6276, 4)\n" ] }, { "data": { "text/plain": [ - "array([[1166, 146],\n", - " [1270, 360],\n", - " [ 2, 8],\n", + "array([[0, 399, 361, '8502208'],\n", + " [0, 400, 377, '8502208'],\n", + " [0, 401, 41, '8502208'],\n", " ...,\n", - " [ 108, 371],\n", - " [ 102, 439],\n", - " [1739, 519]], dtype=uint16)" + " [1406, 559, 527, '8595713'],\n", + " [1406, 1404, 489, '8595713'],\n", + " [1406, 1405, 304, '8595713']], dtype=object)" ] }, - "execution_count": 11, + "execution_count": 18, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "transfers = pkload(\"../data/transfer_array.pkl\").astype(np.uint16)\n", + "transfers = pkload(\"../data/transfer_array.pkl\")#.astype(np.uint16)\n", "print(transfers.shape)\n", "transfers" ] }, { "cell_type": "code", - "execution_count": 12, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "# transfers = np.array([[5, 3600], # A <- F\n", "# [5, 300], # E <- F\n", "# [0, 3600], # F <- A\n", "# [4, 300] # F <- E\n", "# ])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## stops\n", "\n", "`stops` stores the indices in `stopRoutes` and in `transfers` corresponding to each stop.\n", "\n", "`stopRoutes[stops[p][0]:stops[p][1]]` returns the routes serving stop p.\n", "\n", "`transfers[stops[p][2]:stops[p][3]]` returns the footpaths arriving at stop p." ] }, { "cell_type": "code", - "execution_count": 13, + "execution_count": 34, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ + "[ 0 70]\n", "(1407, 2)\n" ] }, { "data": { "text/plain": [ - "array([[ 0, 747],\n", - " [ 747, 921],\n", - " [ 921, 1095],\n", + "array([[ 0, 4, 0, 8],\n", + " [ 4, 7, 8, 14],\n", + " [ 7, 19, 14, 21],\n", " ...,\n", - " [237334, 237389],\n", - " [237389, 237444],\n", - " [237444, 237810]], dtype=uint32)" + " [7841, 7844, 6263, 6268],\n", + " [7844, 7847, 6268, 6271],\n", + " [7847, 7849, 6271, 6276]], dtype=uint32)" ] }, - "execution_count": 13, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stops = pkload(\"../data/stops_array.pkl\")\n", + "print(np.equal(stops, None).sum(axis=0))\n", "print(stops.shape)\n", + "stops = stops[:,[0,0,1,1]]\n", + "# Make column 1 contain the start_index of the next stop in stopRoutes\n", "stops[:-1,1] = stops[1:,0]\n", "stops[-1, 1] = stopRoutes.shape[0]\n", + "# Make column 2 contain the start_index of the next stop in stopRoutes\n", + "for i in np.where(np.equal(stops[:,2], None))[0]:\n", + " stops[i,2] = stops[i-1,2]\n", + "stops[:-1,3] = stops[1:,2]\n", + "stops[-1, 3] = transfers.shape[0]\n", + "# Convert to int\n", "stops = stops.astype(np.uint32)\n", "stops" ] }, { "cell_type": "code", - "execution_count": 14, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ "# stopRoutes[stops[p][0]:stops[p][1]] returns the routes serving stop p.\n", "# transfers[stops[p][2]:stops[p][3]] returns the footpaths arriving at stop p.\n", "# stops = np.array([[0,2, 0,1 ], # A\n", "# [2,3, 1,1 ], # B\n", "# [3,5, 1,1 ], # C\n", "# [5,6, 1,1 ], # D\n", "# [6,9, 1,2 ], # E\n", "# [9,stopRoutes.shape[0], 2,transfers.shape[0]] # F\n", "# ])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ - "## Coding the reversed Multiple Criteria RAPTOR\n", + "## Implementing the reversed Multiple Criteria RAPTOR\n", "\n", "Based on modified version of RAPTOR (reversed RAPTOR), we implement a multiple criteria RAPTOR algorithm.\n", "The optimization criteria are:\n", "- Latest departure\n", "- Highest probability of success of the entire trip\n", "- Lowest number of connections (implicit with the round-based approach)" ] }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 36, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "numpy.datetime64('2020-05-11T15:28')" ] }, - "execution_count": 15, + "execution_count": 36, "metadata": {}, "output_type": "execute_result" } ], "source": [ "# absolute constants:\n", "\n", "tau_change_platform = np.timedelta64(2, 'm')\n", "np.datetime64('2020-05-11T15:30') - tau_change_platform" ] }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ "# helper functions\n", "\n", "def arr_and_dep_time(r, t, offset_p):\n", " \"\"\"This function should not be called directly.\n", " Use arrival_time and departure_time.\n", " In particular, this function relies on \"t is not None\"-\n", " \"\"\"\n", " return stopTimes[routes[r][3] # 1st trip of route\n", " + t * routes[r][1] # offset for the right trip\n", " + offset_p # offset for the right stop\n", " ]\n", "\n", "def arrival_time(r, t, offset_p):\n", " \"\"\"Returns 2000 (instead of 0) if t is None.\n", " Otherwise, returns the arrival time of the t-th trip of route r\n", " at the offset_p-th stop of route r.\n", " trips and stops of route r start at t=0, offset_p=0.\n", " \"\"\"\n", " if t is None:\n", " return np.datetime64('2000-01-01T01:00')\n", " \n", " return arr_and_dep_time(r,t,offset_p)[0] # 0 for arrival time\n", "\n", "def departure_time(r, t, offset_p):\n", " \"\"\"Throws TypeError if t is None.\n", " Otherwise, returns the departure time of the t-th trip of route r\n", " at the offset_p-th stop of route r.\n", " trips and stops of route r start at t=0 & offset_p=0.\n", " \"\"\"\n", " if t is None:\n", " raise TypeError(\"Requested departure time of None trip!\")\n", " \n", " return arr_and_dep_time(r,t,offset_p)[1] # 1 for departure time\n", "\n", "def get_stops(r):\n", " \"\"\"Returns the stops of route r\"\"\"\n", " idx_first_stop = routes[r][2]\n", " return routeStops[idx_first_stop:idx_first_stop+routes[r][1]] # n_stops = routes[r][1] " ] }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ "class InstantiationException(Exception):\n", " pass\n", "\n", "class BaseLabel:\n", " \"\"\"An abstract base class for Labels. Do not instantiate.\n", " A label corresponds to a recursive (partial) solution, going\n", " to the target stop from the stop currently under consideration.\n", " \"\"\"\n", " def __init__(self, stop, tau_dep, Pr):\n", " self.stop = stop\n", " self.tau_dep = tau_dep\n", " self.Pr = Pr\n", " \n", " def dominates(self, other):\n", " \"\"\"Returns True if self dominates other, else returns False.\n", " other: another Label instance.\n", " \"\"\"\n", " if self.tau_dep >= other.tau_dep and self.Pr >= other.Pr:\n", " return True\n", " return False\n", " \n", " def print_journey(self):\n", " print(\"Journey begins at stop {stop} at time {tau}, with an \"\n", " \"overall probability of success = {Pr} \\n\".format(\n", " stop = self.stop,\n", " tau = self.tau_dep,\n", " Pr = self.Pr\n", " )\n", " )\n", " self.print_instructions()\n", " \n", " def to_str(self):\n", " s = \"Departure at {0} from stop {1}.\".format(self.tau_dep, self.stop)\n", " return repr(type(self)) + s\n", " \n", " def pprint(self, indent=''):\n", " print(indent, self.to_str())\n", " \n", " def copy(self):\n", " raise InstantiationException(\"class BaseLabel should never \"\n", " \"be instantiated.\"\n", " )\n", "\n", "class ImmutableLabel(BaseLabel):\n", " \"\"\"Base class for immutable Labels\"\"\"\n", " def copy(self):\n", " return self\n", "\n", "class TargetLabel(ImmutableLabel):\n", " \"\"\"A special type of label reserved for the target stop.\"\"\"\n", " def __init__(self, stop, tau_dep):\n", " BaseLabel.__init__(self, stop, tau_dep, 1.)\n", " \n", " def print_instructions(self):\n", " \"\"\"Finish printing instructions for the journey.\"\"\"\n", " print(\"You have arrived at the target stop ({stop}) \"\n", " \"before the target time of {tau}.\".format(\n", " stop=self.stop,\n", " tau=self.tau_dep\n", " ))\n", "\n", "class WalkLabel(ImmutableLabel):\n", " \"\"\"A special type of label for walking connections.\"\"\"\n", " def __init__(self, stop, tau_walk, next_label):\n", " \"\"\"Creat a new WalkLabel instance.\n", " stop: stop where you start walking.\n", " tau_walk: (np.timedelta64) duration of the walk.\n", " next_label: label describing the rest of the trip after walking.\n", " \"\"\"\n", " if isinstance(next_label, WalkLabel):\n", " raise ValueError(\"Cannot chain two consecutive WalkLabels!\")\n", " tau_dep = next_label.tau_dep - tau_walk - tau_change_platform\n", " BaseLabel.__init__(self, stop, tau_dep, next_label.Pr)\n", " self.tau_walk = tau_walk\n", " self.next_label = next_label\n", " \n", " def print_instructions(self):\n", " \"\"\"Recursively print instructions for the whole journey.\"\"\"\n", " print(\"Walk {tau} minutes from stop {p1} to stop {p2}\"\n", " \".\".format(\n", " tau = self.tau_walk,\n", " p1 = self.stop,\n", " p2 = self.next_label.stop\n", " ))\n", " self.next_label.print_instructions()\n", "\n", "class RouteLabel(BaseLabel):\n", " \"\"\"A type of label for regular transports.\"\"\"\n", " def __init__(self,\n", " stop,\n", " tau_dep,\n", " r,\n", " t,\n", " next_label,\n", " Pr_connection_success):\n", " \n", " Pr = Pr_connection_success * next_label.Pr\n", " BaseLabel.__init__(self, stop, tau_dep, Pr)\n", " \n", " self.r = r\n", " self.t = t\n", " self.next_label = next_label\n", " self.route_stops = get_stops(r)\n", " self.offset_p = np.where(self.route_stops == stop)[0][0]\n", " # Store Pr_connection_success for self.copy()\n", " self.Pr_connection_success = Pr_connection_success\n", " \n", " def update_stop(self, stop):\n", " self.stop = stop\n", " self.offset_p = self.offset_p - 1\n", " # Sanity check:\n", " assert self.route_stops[self.offset_p] == stop\n", " self.tau_dep = departure_time(self.r, self.t, self.offset_p)\n", " \n", " def print_instructions(self):\n", " \"\"\"Recursively print instructions for the whole journey.\"\"\"\n", " print(\" \"*4 + \"At stop {stop}, take route {r} at time \"\n", " \"{tau}.\".format(stop=self.stop,\n", " r=self.r,\n", " tau=self.tau_dep\n", " )\n", " )\n", " tau_arr = arrival_time(\n", " self.r,\n", " self.t,\n", " np.where(self.route_stops == self.next_label.stop)\n", " )\n", " print(\" \"*4 + \"Get out at stop {stop} at time {tau}\"\n", " \".\".format(stop=self.next_label.stop, tau=tau_arr)\n", " )\n", " self.next_label.print_instructions()\n", " \n", " def copy(self):\n", " \"\"\"When RouteLabels are merged into the bag of a stop,\n", " they must be copied (because they will subsequently\n", " be changed with self.update_stop()).\n", " \"\"\"\n", " return RouteLabel(self.stop,\n", " self.tau_dep,\n", " self.r,\n", " self.t,\n", " self.next_label,\n", " self.Pr_connection_success\n", " )" ] }, { "cell_type": "code", - "execution_count": 46, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ - "def run_mc_raptor(p_s, p_t, tau_0, Pr_min, incoherences):\n", + "def run_mc_raptor(p_s, p_t, tau_0, Pr_min\n", + " , incoherences\n", + " ):\n", " \"\"\"Run MC RAPTOR, using the data defined in cells above (stopRoutes etc.).\n", " Inputs:\n", " p_s: source stop\n", " p_t: target stop\n", " tau_0: latest acceptable arrival time\n", " Pr_min: minimum acceptable probability of success\n", " Output:\n", " bags_p_s: bags_p_s[k] contains the pareto set of non-dominated journeys\n", " from p_s to p_t that use at most k different trips (i.e,\n", " getting in at most k different vehicles), under the given\n", " constraints:\n", " 1. Each journey must succeed with a probability\n", " greater or equal to Pr_min.\n", " 2. The journey is a success if and only if all individual\n", " connections succeed, including the user's appointment\n", " in p_t at tau_0.\n", " 3. A connection succeeds if, and only if, the user reaches\n", " the platform before or on the scheduled departure time\n", " (allowing some time to change platforms)\n", " Non-dominated:\n", " A journey J1 is *dominated* by another journey J2, if\n", " J2 departs no earlier than J1 AND the probability of\n", " success of J2 is no less than that of J1.\n", " Pareto set:\n", " Each bag in bags_p_s contains only journeys that are not\n", " dominated by any other possible journey. Such a collection\n", " of non-dominated solutions is called a *Pareto set*.\n", " \n", " Each journey is represented as a Label that forms the start of a chain.\n", " The journey can be reconstructed by calling label.print_journey().\n", " \"\"\"\n", "# initialization\n", " # For each route and for each label at each stop p, we will look at the n latest\n", " # trips until we find a trip for which the individual connection at stop p\n", " # succeeds with a probability at least equal to Pr_threshold.\n", " # Under some reasonable assumptions, setting Pr_threshold = Pr_min**(1/k)\n", " # guarantees that we will find a solution, if a solution exists involving at\n", " # most k connections (including the user's appointment in p_t at tau_0).\n", " Pr_threshold = Pr_min**(0.1)\n", " \n", "\n", " # Initialize empty bags for each stop for round 0:\n", " n_stops = stops.shape[0]\n", " bags = [\n", " [\n", " [] # an empty bag\n", " for _ in range(n_stops)] # one empty bag per stop\n", " ]\n", "\n", " # Create a TargetLabel for p_t, and mark p_t\n", " bags[0][p_t].append(TargetLabel(p_t, tau_0))\n", " marked = {p_t}\n", "\n", "# Define bag operations (they depend on p_s and Pr_min for target pruning):\n", " def update_bag(bag, label, k):\n", " \"\"\"Add label to bag and remove dominated labels.\n", " bag is altered in-place.\n", "\n", " k: Round number, used for target pruning.\n", "\n", " returns: Boolean indicating whether bag was altered.\n", " \"\"\"\n", " # Apply the Pr_min constraint to label:\n", " if label.Pr < Pr_min:\n", " return False\n", "\n", " # Prune label if it is dominated by bags[k][p_s]:\n", " for L_star in bags[k][p_s]:\n", " if L_star.dominates(label):\n", " return False\n", "\n", " # Otherwise, merge label into bag1\n", " changed = False\n", " for L_old in bag:\n", " if L_old.dominates(label):\n", " return changed\n", " if label.dominates(L_old):\n", " bag.remove(L_old)\n", " changed = True\n", " bag.append(label.copy())\n", " return True\n", "\n", " def merge_bags(bag1, bag2, k):\n", " \"\"\"Merge bag2 into bag1 in-place.\n", " k: Round number, used for target pruning.\n", " returns: Boolean indicating whether bag was altered.\n", " \"\"\"\n", " changed = False\n", " for label in bag2:\n", " changed = changed or update_bag(bag1, label, k)\n", " return changed\n", " \n", "# Define the footpaths-checking function (depends on update_bag)\n", " def check_footpaths(bags, marked, k):\n", " \"\"\"Modify bags and marked in-place to account for foot-paths.\"\"\"\n", " pass # Leave out footpaths until transfers is ready.\n", "# q = []\n", "# for p in marked:\n", "# for pPrime, delta_seconds in transfers[stops[p][2]:stops[p][3]]:\n", "# q.append((p, pPrime, delta_seconds))\n", "# for p, pPrime, delta_seconds in q:\n", "# for L_k in bags[k][p]:\n", "# # We do not allow two consecutive walking trips\n", "# if not isinstance(L_k, WalkLabel):\n", "# L_new = WalkLabel(pPrime, np.timedelta64(delta_seconds, 's'), L_k)\n", "# if update_bag(bags[k][pPrime], L_new, k):\n", "# marked.add(pPrime)\n", "\n", "# main loop\n", " indent= ' '*4\n", "\n", " k = 0\n", " # Check footpaths leading to p_t at k=0:\n", " check_footpaths(bags, marked, k)\n", " while True:\n", " k += 1 # k=1 at fist round, as it should.\n", "\n", " # Instead of using best bags, carry over the bags from last round.\n", " # if len(bags <= k):\n", "\n", " bags.append([bags[-1][p].copy() for p in range(n_stops)])\n", "\n", " print('\\n******************************STARTING round k={}******************************'.format(k))\n", " # accumulate routes serving marked stops from previous rounds\n", " q = []\n", " print('Marked stops at the start of the round: {}'.format(marked))\n", " for p in marked:\n", " for r in stopRoutes[stops[p][0]:stops[p][1]]: # foreach route r serving p\n", " append_r_p = True\n", " for idx, (rPrime, pPrime) in enumerate(q): # is there already a stop from the same route in q ?\n", " if rPrime == r:\n", " append_r_p = False\n", " p_pos_in_r = np.where(get_stops(r) == p)\n", " pPrime_pos_in_r = np.where(get_stops(r) == pPrime)\n", " if p_pos_in_r > pPrime_pos_in_r:\n", " q[idx] = (r, p) # substituting (rPrime, pPrime) by (r, p)\n", " if append_r_p:\n", " q.append((r, p))\n", " marked.clear() # unmarking all stops\n", "\n", "# print('Queue before traversing each route: {}'.format(q))\n", " # traverse each route\n", " for (r, p) in q:\n", "# print('\\n****TRAVERSING ROUTE r={0} from stop p={1}****'.format(r, p))\n", " B_route = [] # new empty route bag\n", "\n", " # we traverse the route backwards (starting at p, not from the end of the route)\n", " stops_of_current_route = get_stops(r)\n", "# print('Stops of current route:', stops_of_current_route)\n", " offset_p = np.asarray(stops_of_current_route == p).nonzero()[0]\n", " if offset_p.size < 1:\n", " if not p in incoherences:\n", " incoherences[p] = set()\n", " incoherences[p].add(r)\n", "# print(\"WARNING: route {r} is said to serve stop {p} in stopRoutes, but stop {p} \"\n", "# \"is not included as a stop of route {r} in routeStops...\".format(p=p, r=r))\n", " offset_p = -1\n", " else:\n", " offset_p = offset_p[0]\n", " for offset_p_i in range(offset_p, -1, -1):\n", " p_i = stops_of_current_route[offset_p_i]\n", "# print('\\n\\n'+indent+\"p_i: {}\".format(p_i))\n", "\n", " # Update the labels of the route bag:\n", " for L in B_route:\n", " L.update_stop(p_i)\n", "\n", " # Merge B_route into bags[k][p_i]\n", " if merge_bags(bags[k][p_i], B_route, k):\n", " marked.add(p_i)\n", "\n", " # Can we step out of a later trip at p_i ?\n", " # This is only possible if we already know a way to get from p_i to p_t in < k vehicles\n", " # (i.e., if there is at least one label in bags[k][p_i])\n", " for L_k in bags[k][p_i]:\n", " # Note that k starts at 1 and bags[0][p_t] contains a TargetLabel.\n", "# print('\\n'+indent+'----scanning arrival times for route r={0} at stop p_i={1}----'.format(r, p_i))\n", "\n", " # We check the trips from latest to earliest\n", " for t in range(routes[r][0]-1, -1, -1): # n_trips = routes[r][0]\n", " # Does t_r arrive early enough for us to make the rest \n", " # of the journey from here (tau[k-1][p_i])?\n", " tau_arr = arrival_time(r, t, offset_p_i)\n", "# print(indent+'arrival time: ', tau_arr)\n", " if tau_arr <= L_k.tau_dep - tau_change_platform:\n", "\n", " max_delay = L_k.tau_dep - tau_arr - tau_change_platform\n", " Pr_connection = 1 # This is a placeholder.\n", " L_new = RouteLabel(p_i,\n", " departure_time(r, t, offset_p_i),\n", " r,\n", " t,\n", " L_k,\n", " Pr_connection\n", " )\n", " update_bag(B_route, L_new, k)#:\n", "# print(indent+\"Explored connection from\")\n", "# L_new.pprint(indent*2)\n", "# print(indent+\"to\")\n", "# L_k.pprint(indent*2)\n", "\n", " # We don't want to add a label for every trip that's earlier than tau_dep.\n", " # Instead, we stop once we've found a trip that's safe enough.\n", " if Pr_connection > Pr_threshold:\n", " break\n", " \n", " # Look at foot-paths (bags and marked are altered in-place):\n", " check_footpaths(bags, marked, k)\n", " \n", " # stopping criteria\n", " if not marked:\n", " print(\"\\n\" + \"*\"*15 + \" THE END \" + \"*\"*15)\n", " print(\"Equilibrium reached. The end.\")\n", " break\n", " if k>2:\n", " if bags[k-1][p_s]:\n", " print(\"\\n\" + \"*\"*15 + \" THE END \" + \"*\"*15)\n", " print(\"There is a solution with {0} connections. We shall not \"\n", " \"search for solutions with {1} or more connections\"\n", " \".\".format(k-2, k)\n", " )\n", " break\n", " return [bags[K][p_s] for K in range(len(bags))]" ] }, { "cell_type": "code", - "execution_count": 45, + "execution_count": 40, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "******************************STARTING round k=1******************************\n", - "Marked stops at the start of the round: {172}\n", + "Marked stops at the start of the round: {763}\n", "\n", "******************************STARTING round k=2******************************\n", - "Marked stops at the start of the round: {512, 513, 153, 138, 139, 529, 530, 531, 532, 146, 150, 151, 152, 921, 154, 155, 156, 157, 158, 159, 160, 161, 930, 163, 164, 165, 166, 167, 168, 169, 170, 171, 173, 162, 952, 953, 973, 206, 208, 209, 210, 979, 211, 981, 982, 983, 984, 985, 986, 238, 149, 379}\n" - ] - }, - { - "name": "stderr", - "output_type": "stream", - "text": [ - "/opt/conda/lib/python3.7/site-packages/ipykernel_launcher.py:136: DeprecationWarning: The truth value of an empty array is ambiguous. Returning False, but in future this will result in an error. Use `array.size > 0` to check that an array is not empty.\n" - ] - }, - { - "name": "stdout", - "output_type": "stream", - "text": [ + "Marked stops at the start of the round: {344, 122, 440, 345, 717, 1358, 721, 342, 343, 760, 761, 762, 733, 734, 735}\n", "\n", "******************************STARTING round k=3******************************\n", - "Marked stops at the start of the round: {0, 1, 2, 3, 4, 5, 6, 7, 62, 101, 111, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 140, 141, 142, 143, 144, 145, 147, 148, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 257, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 372, 373, 374, 375, 376, 377, 378, 380, 381, 422, 423, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 533, 534, 535, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, 670, 801, 807, 830, 831, 832, 833, 834, 835, 836, 837, 838, 842, 847, 848, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 922, 923, 931, 932, 933, 934, 935, 951, 958, 962, 964, 965, 966, 973, 974, 975, 976, 977, 978, 980, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, 997, 998, 1000, 1001, 1002, 1024, 1025, 1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1039, 1040, 1041, 1042, 1061, 1062, 1063, 1064, 1065, 1066, 1068, 1103, 1104, 1105, 1106, 1107, 1110, 1111, 1112, 1113, 1114, 1115, 1117, 1118, 1119, 1120, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1287, 1288, 1289, 1290, 1291, 1345, 1346, 1347, 1369, 1370, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1399, 1400, 1403, 1404, 1405}\n", + "Marked stops at the start of the round: {1040, 1041, 1046, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, 1087, 1088, 1089, 756, 728, 1108, 1109, 1110, 1111, 1112, 729, 730, 731, 777, 732, 757, 758, 120, 121, 778, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 1164, 140, 142, 143, 1167, 1168, 1169, 147, 148, 149, 150, 151, 152, 153, 154, 1170, 759, 162, 746, 1357, 1359, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 1229, 1230, 199, 1232, 1233, 1234, 1231, 1235, 1236, 1237, 1238, 719, 720, 724, 779, 725, 726, 734, 727, 1248, 1249, 1250, 1251, 739, 740, 741, 742, 736, 737, 234, 738, 748, 743, 744, 745, 1264, 1265, 1266, 1267, 747, 749, 750, 751, 752, 753, 754, 755, 764, 765, 766, 767, 768, 769, 770, 771, 260, 261, 1286, 1287, 1288, 1289, 1290, 1291, 262, 263, 264, 265, 266, 267, 1298, 1299, 1300, 1301, 278, 279, 280, 281, 1303, 283, 1302, 282, 286, 300, 772, 303, 816, 817, 773, 774, 775, 1342, 1343, 319, 776, 326, 327, 328, 329, 330, 331, 332, 333, 1358, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 780, 781, 862, 782, 783, 873, 784, 879, 277, 786, 441, 442, 443, 444, 445, 454, 455, 193, 977, 978, 979, 141, 198}\n", + "\n", + "******************************STARTING round k=4******************************\n", + "Marked stops at the start of the round: {512, 522, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 43, 44, 45, 46, 1080, 1081, 1086, 1107, 1114, 1115, 618, 1139, 120, 121, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, 1162, 139, 140, 141, 1163, 144, 145, 146, 148, 149, 150, 151, 152, 153, 154, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 162, 1178, 1309, 163, 164, 165, 1220, 1221, 1222, 1223, 1224, 1225, 1226, 1228, 718, 1235, 1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 736, 737, 1250, 1251, 738, 1253, 1254, 1252, 1255, 1256, 1257, 1258, 751, 964, 965, 253, 254, 255, 256, 257, 258, 259, 265, 266, 267, 779, 269, 270, 271, 272, 273, 268, 274, 275, 277, 276, 1294, 1304, 1305, 1306, 1307, 284, 285, 1308, 287, 288, 289, 290, 291, 292, 293, 1177, 294, 801, 802, 1321, 1322, 1323, 1324, 1325, 815, 814, 304, 305, 813, 308, 309, 310, 311, 313, 1338, 1339, 1340, 1337, 318, 1343, 1344, 317, 320, 1347, 1348, 321, 1349, 1350, 1351, 1352, 1353, 846, 847, 1361, 1365, 1366, 1367, 342, 345, 862, 863, 864, 1377, 1376, 1375, 1374, 1383, 1384, 873, 1293, 1389, 879, 880, 881, 882, 883, 429, 430, 431, 432, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 1310, 453, 966, 967, 968, 969, 1312, 971, 972, 973, 974, 1313, 976, 975, 804, 970, 1314, 981, 1315, 990, 991, 992, 1000, 810, 811, 502, 503, 504, 812, 510, 511}\n", "\n", "*************** THE END ***************\n", - "There is a solution with 1 connections. We shall not search for solutions with 3 or more connections.\n" + "There is a solution with 2 connections. We shall not search for solutions with 4 or more connections.\n" ] } ], "source": [ "p_s = 1000 # start stop\n", - "p_t = 172 # target stop\n", + "p_t = np.random.randint(stops.shape[0]) # target stop\n", "tau_0 = np.datetime64('2020-05-21T17:30') # arrival time\n", "Pr_min = 0.9\n", "incoherences = {}\n", - "bags_p_s = run_mc_raptor(p_s, p_t, tau_0, Pr_min, incoherences)" - ] - }, - { - "cell_type": "code", - "execution_count": 44, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "32.80722891566265" - ] - }, - "execution_count": 44, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "np.mean([len(v) for v in incoherences.values()])" + "bags_p_s = run_mc_raptor(p_s, p_t, tau_0, Pr_min\n", + " , incoherences\n", + " )" ] }, { "cell_type": "code", - "execution_count": 33, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "array([26378, 26598], dtype=uint32)" - ] - }, - "execution_count": 33, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "stops[149]" - ] - }, - { - "cell_type": "code", - "execution_count": 34, + "execution_count": 41, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([14536, 14537, 14538, 14539, 14540, 14542, 14543, 14545, 14546,\n", - " 14547, 14574, 14586, 14589, 14591, 14593, 14594, 14595, 14785,\n", - " 14848, 14855, 14856, 14862, 14863, 14868, 14869, 14870, 14871,\n", - " 14874, 14876, 14879, 14885, 14891, 14900, 14903, 14904, 14906,\n", - " 15057, 15065, 15066, 15070, 15073, 15074, 15076, 15079, 15081,\n", - " 15083, 15084, 15086, 15089, 15090, 15091, 15092, 15093, 15094,\n", - " 15095, 15098, 15104, 15105, 15106, 15107, 15108, 15109, 15110,\n", - " 15111, 15112, 15113, 15175, 15177, 15178, 15179, 15181, 15182,\n", - " 15185, 15186, 15188, 15189, 15190, 15191, 15192, 15193, 15194,\n", - " 15197, 15198, 15200, 15201, 15202, 15203, 15204, 15205, 15213,\n", - " 15227, 15230, 15231, 15232, 15233, 15237, 15238, 15241, 15242,\n", - " 15243, 15244, 15245, 15246, 15248, 15249, 15251, 15252, 15253,\n", - " 15257, 15297, 15298, 15299, 15300, 15301, 15302, 15303, 15356,\n", - " 15360, 15365, 15367, 15428, 15433, 15435, 15508, 15509, 15510,\n", - " 15514, 15515, 15516, 15536, 15537, 15538, 15539, 15540, 15541,\n", - " 15542, 15543, 15544, 15545, 15546, 15547, 15548, 15549, 15643,\n", - " 15644, 15646, 15649, 15650, 15651, 194, 195, 196, 200,\n", - " 203, 205, 208, 209, 213, 214, 223, 3916, 3917,\n", - " 3919, 3927, 3932, 3936, 3937, 3941, 3943, 3955, 3959,\n", - " 3960, 3961, 3962, 3963, 3964, 3965, 3966, 3967, 3968,\n", - " 3969, 9902, 9903, 9904, 9905, 9906, 9907, 9908, 10088,\n", - " 10107, 10108, 10111, 10113, 10120, 10121, 10126, 10130, 10419,\n", - " 10420, 10423, 10424, 10429, 10431, 10828, 10829, 10830, 10831,\n", - " 10832, 10833, 10834, 10835, 10836, 10837, 10848, 10849, 10859,\n", - " 10860, 10861, 10868, 10973], dtype=uint32)" + "{}" ] }, - "execution_count": 34, + "execution_count": 41, "metadata": {}, "output_type": "execute_result" } ], "source": [ - "stopRoutes[stops[149][0]:stops[149][1]]" + "incoherences" ] }, { "cell_type": "code", - "execution_count": 35, + "execution_count": 46, "metadata": {}, "outputs": [ { "data": { "text/plain": [ - "array([930, 238, 147, 931, 148, 932, 933, 215, 216, 217, 218, 934, 935,\n", - " 502], dtype=uint16)" + "5" ] }, - "execution_count": 35, + "execution_count": 46, "metadata": {}, "output_type": "execute_result" } ], - "source": [ - "get_stops(15179)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], "source": [ "len(bags_p_s)" ] }, { "cell_type": "code", - "execution_count": 41, + "execution_count": 47, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "\n", "\n", - " ---------- OPTION 0\n", - "Journey begins at stop 1000 at time 2020-05-21T09:36:00.000000000, with an overall probability of success = 1.0 \n", + " ---------- OPTION 1\n", + "Journey begins at stop 1000 at time 2020-05-21T16:57:00.000000000, with an overall probability of success = 1.0 \n", "\n", - " At stop 1000, take route 3764 at time 2020-05-21T09:36:00.000000000.\n", - " Get out at stop 151 at time [['2020-05-21T09:44:00.000000000' 'NaT']].\n", - " At stop 151, take route 11373 at time 2020-05-21T09:52:00.000000000.\n", - " Get out at stop 172 at time [['2020-05-21T10:22:00.000000000' '2020-05-21T10:22:00.000000000']].\n", - "You have arrived at the target stop (172) before the target time of 2020-05-21T10:30.\n" + " At stop 1000, take route 399 at time 2020-05-21T16:57:00.000000000.\n", + " Get out at stop 143 at time [['2020-05-21T17:23:00.000000000' '2020-05-21T17:23:00.000000000']].\n", + " At stop 143, take route 539 at time 2020-05-21T17:26:00.000000000.\n", + " Get out at stop 345 at time [['2020-05-21T17:33:00.000000000' '2020-05-21T17:33:00.000000000']].\n", + " At stop 345, take route 619 at time 2020-05-21T17:36:00.000000000.\n", + " Get out at stop 763 at time [['2020-05-21T17:26:00.000000000' '2020-05-21T17:26:00.000000000']].\n", + "You have arrived at the target stop (763) before the target time of 2020-05-21T17:30.\n" ] } ], "source": [ "for i, label in enumerate(bags_p_s[-1]):\n", - " print('\\n'*2,'-'*10, 'OPTION', i)\n", + " print('\\n'*2,'-'*10, 'OPTION', i+1)\n", " label.print_journey()" ] }, { "cell_type": "code", - "execution_count": 36, + "execution_count": 45, "metadata": {}, "outputs": [], "source": [ - "for i, label in enumerate(bags_p_s[1]):\n", - " print('\\n'*2,'-'*10, 'OPTION', i, 'with at most k trips')\n", + "for i, label in enumerate(bags_p_s[2]):\n", + " print('\\n'*2,'-'*10, 'OPTION', i, 'with at most 2 trips')\n", " label.print_journey()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Code for prototyping and debugging:" ] }, { "cell_type": "code", "execution_count": 28, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "iinfo(min=0, max=4294967295, dtype=uint32)" ] }, "execution_count": 28, "metadata": {}, "output_type": "execute_result" } ], "source": [ "np.iinfo(np.uint32)" ] }, { "cell_type": "code", "execution_count": 26, "metadata": {}, "outputs": [ { "ename": "RuntimeError", "evalue": "Set changed size during iteration", "output_type": "error", "traceback": [ "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", "\u001b[0;31mRuntimeError\u001b[0m Traceback (most recent call last)", "\u001b[0;32m\u001b[0m in \u001b[0;36m\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0ms1\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m{\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m3\u001b[0m\u001b[0;34m}\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 2\u001b[0;31m \u001b[0;32mfor\u001b[0m \u001b[0mi\u001b[0m \u001b[0;32min\u001b[0m \u001b[0ms1\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 3\u001b[0m \u001b[0ms1\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0madd\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mi\u001b[0m\u001b[0;34m*\u001b[0m\u001b[0;36m10\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 4\u001b[0m \u001b[0ms1\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n", "\u001b[0;31mRuntimeError\u001b[0m: Set changed size during iteration" ] } ], "source": [ "s1 = {1,2,3}\n", "for i in s1:\n", " s1.add(i*10)\n", "s1" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "(array([99., 80., 47., 22., 15., 11., 3., 0., 1., 1.]),\n", " array([1.0, 6.9, 12.8, 18.700000000000003, 24.6, 30.5, 36.400000000000006,\n", " 42.300000000000004, 48.2, 54.1, 60.0], dtype=object),\n", " )" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" }, { "data": { "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXcAAAD4CAYAAAAXUaZHAAAABHNCSVQICAgIfAhkiAAAAA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+plWsK9eTX4tT1V30tN8j7ga8Bnquoni9dNUz9V9T9VdSmDM94rgIsmXNLIknwMOF5V+yddywr6UFVdzmBa9tYkH168coqOtVXA5cC9VXUZ8FNOmoJZyV6mJdxbvaXBa0nWA3SPxydcz7IleQ+DYH+wqr7eDU9tPwBV9SbwJINpi9VJ3rrIb5qOt6uBjyc5wuCOrNcwmOed1n6oqle6x+PA3zD4BTyNx9pR4GhV7euWH2UQ9mPpZVrCvdVbGuwBtnbPtzKYuz7tJQlwP3Coqr64aNXU9ZNkJsnq7vl7GXx2cIhByN/UbTYVvQBU1e1VtbGqZhn8d/LtqvokU9pPknOS/Mpbz4HfAw4whcdaVb0KvJzkA93QFuAg4+pl0h8yDPFhxHXAPzOYD/2TSdczQv0PAceAnzP4Db6NwVzoXuAF4O+Bcydd5zJ7+RCD/3X8AfBM93PdNPYD/BbwdNfLAeBPu/HfAL4LHAb+GvjlSdc6Qm8fAR6b5n66ur/f/Tz31n/703isdXVfCsx3x9vfAmvG1Yu3H5CkBk3LtIwkaQiGuyQ1yHCXpAYZ7pLUIMNdkhpkuEtSgwx3SWrQ/wJ3eeD1vPXiQgAAAABJRU5ErkJggg==\n", "text/plain": [ "
" ] }, "metadata": { "needs_background": "light" }, "output_type": "display_data" } ], "source": [ "import matplotlib.pyplot as plt\n", "# Plot distribution of n_stops\n", "plt.hist(routes[:,1])" ] }, { "cell_type": "code", "execution_count": 95, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[0]" ] }, "execution_count": 95, "metadata": {}, "output_type": "execute_result" } ], "source": [ "list(range(0,-1,-1))" ] }, { "cell_type": "code", "execution_count": 42, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[[], [<__main__.RouteLabel at 0x7fd99af341d0>]],\n", " [[], [<__main__.RouteLabel at 0x7fd99af341d0>]]]" ] }, "execution_count": 42, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = [[[RouteLabel(1,1,0,1,TargetLabel(p_t, tau_0),1)] for _ in range(2)]]\n", "l.append(l[-1].copy())\n", "l[1][0].remove(l[1][0][0])\n", "l" ] }, { "cell_type": "code", "execution_count": 49, "metadata": { "scrolled": true }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "None\n" ] }, { "data": { "text/plain": [ "[0, 1, 3, 4, 5]" ] }, "execution_count": 49, "metadata": {}, "output_type": "execute_result" } ], "source": [ "l = list(range(6))\n", "ret = l.remove(2)\n", "print(ret)\n", "l" ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Departure at 2020-05-11T08:00 from stop 0.\n", " Departure at 2020-05-11T08:10 from stop 0.\n" ] } ], "source": [ "B = [RouteLabel(1,1,0,0,TargetLabel(p_t, tau_0),0.8), RouteLabel(1,1,0,1,TargetLabel(p_t, tau_0),1)]\n", "B[0].update_stop(0)\n", "B[1].update_stop(0)\n", "for l in B:\n", " l.pprint()" ] }, { "cell_type": "code", "execution_count": 15, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ " Departure at 2020-05-11T08:20 from stop 0.\n", "True\n", " Departure at 2020-05-11T08:10 from stop 0.\n", " Departure at 2020-05-11T08:20 from stop 555.\n", "----------\n", " Departure at 2020-05-11T08:20 from stop 555.\n" ] } ], "source": [ "label = RouteLabel(4,0, 2, 0, TargetLabel(p_t, tau_0), 0.9)\n", "label.update_stop(0)\n", "label.pprint()\n", "print(update_bag(B, label, 0))\n", "label.stop = 555\n", "for l in B:\n", " l.pprint()\n", "print('-'*10)\n", "label.pprint()" ] }, { "cell_type": "code", "execution_count": 27, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "[[1, 2, 3], [1, 2, 666]]" ] }, "execution_count": 27, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bags = [[1,2,3]]\n", "bags.append(bags[-1].copy())\n", "bags[1][2] = 666\n", "bags" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p_s = 0 # start stop = A\n", "p_t = 4 # target stop = E\n", "tau_0 = np.datetime64('2020-05-11T08:05') # departure time 08:05\n", "k_max = 10 # we set a maximum number of transports to pre-allocate memory for the numpy array tau_i" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# initialization\n", "n_stops = len(stops)\n", "\n", "# earliest arrival time at each stop for each round.\n", "tau = np.full(shape=(k_max, n_stops), fill_value = np.datetime64('2100-01-01T00:00')) # 2100 instead of infinity # number of stops * max number of transports\n", "\n", "# earliest arrival time at each stop, indep. of round\n", "tau_star = np.full(shape=n_stops, fill_value = np.datetime64('2100-01-01T00:00'))\n", "\n", "marked = [p_s]\n", "q = []\n", "tau[0, p_s] = tau_0" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.where(routeStops[routes[r][2]:routes[r][2]+routes[r][1]] == p_i)[0][0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "routeStops[routes[r][2]:routes[r][2]+routes[r][1]] == p_i" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "p_i" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "t_r_dep = stopTimes[routes[r][3]+\\\n", " # offset corresponding to stop p_i in route r\n", " np.where(routeStops[routes[r][2]:routes[r][2]+routes[r][1]] == p_i)[0][0] + \\\n", " routes[r][1]*t_r][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if np.where(routeStops[routes[1][2]:routes[1][2]+routes[1][1]] == 2) <\\\n", "np.where(routeStops[routes[1][2]:routes[1][2]+routes[1][1]] == 3):\n", " print(\"hello\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "routeStops[routes[1][2] + np.where(routeStops[routes[1][2]:routes[1][2]+routes[1][1]] == 2)[0][0]:routes[1][2]+routes[1][1]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "routeStops[routes[1][2] + np.where(routeStops[routes[1][2]:routes[1][2]+routes[1][1]] == 2)[0][0]:6]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "routeStops[routes[1][2]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "routeStops[np.where(routeStops[routes[1][2]:routes[1][2]+routes[1][1]] == 2)[0][0]]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "if True and \\\n", " True:\n", " print(\"hello\")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "tau[0][0]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "stopTimes[3][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a = np.arange(1, 10)\n", "a" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "a[1:10:2]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stopTimes[routes[0][3]+\\\n", " # offset corresponding to stop p_i in route r\n", " np.where(routeStops[routes[0][2]:routes[0][2]+routes[0][1]] == 0)[0][0]:\\\n", " # end of the trips of r\n", " routes[0][3]+routes[0][0]*routes[0][1]:\\\n", " # we can jump from the number of stops in r to find the next departure of route r at p_i\n", " routes[0][1]\n", " ]\n", "# we may more simply loop through all trips, and stop as soon as the departure time is after the arrival time\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stopTimes[routes[0][3]+\\\n", " # offset corresponding to stop p_i in route r\n", " np.where(routeStops[routes[0][2]:routes[0][2]+routes[0][1]] == 0)[0][0]][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "stopTimes[routes[1][3]+\\\n", " # offset corresponding to stop p_i in route r\n", " np.where(routeStops[routes[1][2]:routes[1][2]+routes[1][1]] == 3)[0][0] + \\\n", " routes[1][1]*1][1]" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# t_r is a trip that belongs to route r. t_r can take value 0 to routes[r][0]-1\n", "t = None\n", "r = 1\n", "tau_k_1 = tau[0][0]\n", "p_i = 3\n", "\n", "t_r = 0\n", "while True:\n", " \n", " t_r_dep = stopTimes[routes[r][3]+\\\n", " # offset corresponding to stop p_i in route r\n", " np.where(routeStops[routes[r][2]:routes[r][2]+routes[r][1]] == p_i)[0][0] + \\\n", " routes[r][1]*t_r][1]\n", " \n", " if t_r_dep > tau_k_1:\n", " # retrieving the index of the departure time of the trip in stopTimes\n", " #t = routes[r][3] + t_r * routes[r][1]\n", " t = t_r\n", " break\n", " t_r += 1\n", " # we could not hop on any trip at this stop\n", " if t_r == routes[r][0]:\n", " break\n", " \n", "print(\"done\")\n", "print(t)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "r = 1\n", "t = 1\n", "p_i = 2\n", "# 1st trip of route + offset for the right trip + offset for the right stop\n", "stopTimes[routes[r][3] + t * routes[r][1] + np.where(routeStops[routes[r][2]:routes[r][2]+routes[r][1]] == p_i)]" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "d = []\n", "not d" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "scrolled": true }, "outputs": [], "source": [ "r = 1\n", "t = 0\n", "p_i = 4\n", "arr_t_p_i = stopTimes[routes[r][3] + \\\n", " t * routes[r][1] + \\\n", " np.where(routeStops[routes[r][2]:routes[r][2]+routes[r][1]] == p_i)[0][0]][0]\n", "arr_t_p_i" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.datetime64('NaT') > np.datetime64('2100-01-01')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "np.datetime64('NaT') < np.datetime64('2100-01-01')" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "jupytext": { "formats": "ipynb,md,py:percent" }, "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" } }, "nbformat": 4, "nbformat_minor": 4 }