Optimizing Shared-Bike Allocation Routes
By: Luis Flosi
Tags: Simulated Annealing, Towards Data Science, Optimization, Allocation, Linear Programming

Optimizing Shared-Bike Allocation Routes

A new way to solve the Vehicle Routing Problem for shared bikes in a large city

Photo by Gabriela Bavaresco Kataoka

Living in a large city comes with the benefit of a large range of options for getting around. In Chicago, Divvy is the bike sharing company that has over 600 stations throughout the city — though, often, you may find those stations empty, especially in crowded and popular areas. This can be detrimental to both the company and the customers looking for a cheap, efficient and healthy way to move in the city.

When looking to apply skills learned from our Masters of Analytics’ Optimization class, our group — composed of Amy Lin, Divya Ravindran, Grace Yin and Luis Flosi — decided to tackle the issue of finding the best route for a single Divvy van to travel between select bike stations, collecting and redistributing bikes to minimize the lost opportunity of missing bikes when customers most require them. Fortunately, Divvy has made data publicly available on all trips taken by its bikes in Chicago’s Data Portal. We also collected weather data from Dark Sky to enrich our models. Our final code repository can be found on GitHub.

We will start by understanding the data, then creating predictive models to understand demand and supply between stations, and finally optimize distribution routes based on two different approaches: linear programming and simulated annealing.

Data exploration

The data was imported, cleaned and structured during a previous project from a group which Amy was a part of. Our focus was on understanding patterns of ridership between days of the week, hours and months and how those changes might impact the number of bikes in a station.

What we found was that during peak hours, a considerable number of stations became empty or full. We also found that weekdays have very different patterns than weekends. Finally, seasons also have a big impact on the total number of trips taken, since Chicago can have very harsh winters. The analysis was headed by Amy, who produced the following graphs:

Assumptions

We identified how our model would be able to solve the problem given the information we had available and what we could reasonably assume:

We had access to every trip for the year 2019, each station’s bike capacity and capacity status per hour. From the weather dataset, we also managed to identify visibility and temperature for every trip.

Considering that allocation would not necessarily have to be performed every hour, we divided weekdays and weekends into timeframes as illustrated above by red lines. Bike allocations are to be performed within those time frames.

As an assumption, we proposed that a van would have a capacity of 20 bikes. This assumption can be easily tweaked in our model.

For simplicity, we also assumed constant and equal traffic for all of Chicago’s regions, which means that the distance between stations is the only factor that impacts the “cost” of a van transportation between two stations. Although this can also be easily changed for the model, the traffic information would be more complicated to gather at this point.

In our model, a van would be responsible only for a certain set of stations. In a future model, we would certainly expand it to consider an indefinite number of vans for all stations at once. However, we found that this type of optimization problem (commonly known as Vehicle Routing Problem, or VRP) is too computationally intensive when considering hundreds of stations at once.

Given this scenario, we realized that the main model input that was missing is the forecasted demand for each station at any given day.

Demand estimation

In order to estimate demand, Divya, Grace and Luis created two predictive poisson models that would estimate the number of bikes arriving and leaving each station. They take into account the weather conditions, month, hour and day of the week.

Although the models showed near-zero chi-square p-value, they also performed well with the test set, showing errors that ranged between -1 to 5 predicted trips. The p-value test can be misleading when predicting low-value rates, so we decided to use this model for predicted trips. However, in a real-life situation, we would certainly develop this model further to be more robust.

From the models above, we restricted their trips predictions to consider each station’s bike capacity. Finally, we utilized the 95% upper level of forecasted leaving trips as the actual number of trips leaving. We decided to consider the upper level to ensure that there would be no shortage of bikes on most days.

For the optimization model, we define demand as the number of bikes that need to be transported to a station so it can fulfill all customer trips. A positive demand means that a station has a surplus of bikes for a timeframe. With that in mind, we define demand as:

D = B — (UL — A)

Where D = demand, B = bikes available at start of timeframe T, A is the number of bikes arriving during timeframe T and UL as the upper-bound estimation of the number of bikes leaving the station during timeframe T.

From the number of trips arriving and leaving each station, we were able to aggregate the hourly numbers into the pre-defined timeframes where the optimizations will take place. From there, we only needed to calculate the number of bikes actually available at each station at start of time T (considering post-optimization changes).

For T = midnight, we assume that the number of bikes available is always the same, equal to the average of the historic period at midnight since Divvy has historically performed allocations at that time. From then, each time frame will have the number of bikes that will be considered: previous timeframe’s allocation results (number of bikes actually available); “A” for the previous timeframe and average of bikes that left the station (NOT the upper-bound).

B_t+1 = O — (L — A)

Where O is the optimized number of bikes available on the previous timeframe T, A is the number of bikes arriving at station in the previous timeframe and L is the average number of bikes leaving as predicted by the model for the previous time frame.

We repeat this process for every new timeframe, calculating the optimization model’s input D each time.

Allocation routes optimization

We used two different approaches to optimize the routes for bike allocation. The first is a linear programming problem solved using Julia’s Gurobi solver, and the second is solved using the Simulated Annealing (SA) technique inspired by this research paper’s results that showed that SA can be used to solve VRP problems with much fewer computations.

Both solutions take into account the same objective function, derived by Amy. We minimize the sum of absolute differences between the expected station inventory and actual inventory after optimization:

1. Linear programming solution in Julia

Variables

Constraints

The linear programming solution requires the definition of constraints to which the objective function will be subject to. The constraints not only need to define capacity (such as van and station capacities), but also create route connections and establish distances as the “cost”, for which there will be a maximum cost attainable (meaning the total time a van can travel before the timeframe expires). The functions below were also derived by Amy with support from the rest of the team:

Capacity constraints

Routing constraints

2. Simulated Annealing approach

The main weakness of the previous approach is that it can be extremely computationally intensive. Not only would it take hours or days to run the optimization for all stations at once, there are some cases where as few as 20 stations can take hours to process.

The paper previously mentioned has found an alternative to a similar VRP model using simulated annealing, an algorithm that randomly selects solutions and evaluates them until it can find the optimal solution. The unique approach of the algorithm, however, is that it allows “bad” solutions in order to escape a local optimum.

Once we were finished with the scope set by the Optimization class for a final project, we decided to go one step further and implement the SA algorithm in our data to find solutions to scenarios where we had difficulty processing. Even though we only implemented a limited, first-draft version of the SA, we had great results running cases that once took us hours to process using only a few minutes.

The adaptation of SA for our specific case was made by Luis, and is outlined here. The code can be found in our repository.

Results and final considerations

To demonstrate our results, Divya and Grace chose one “default” summer day with good visibility during a weekday at the 7pm timeframe, with 29 random stations across Chicago. After Amy processed this case with our linear model, they worked together to produced the following image to demonstrate the resulting route:

Note that the optimization could be run on any given situation, as long as it has the inputs for demand, capacity constraints and distance / travel time. Also, this is the result from our Winter Quarter presentation, where we used a prior predictive model. Since then, the model was improved as can be seen in our GitHub page.

In a real-life situation, this could be run ahead of time on any given day to create dynamic routes for vans to optimize bike distributions for a regular work day, weekends, summer or winter, and even extraordinary event days. This would allow Divvy to properly assign bikes the best and fastest way possible, maximizing not only their opportunities but overall customer satisfaction.