Introduction to the Custom Sorting Algorithm
This article explains how the custom sorting algorithm ranks pickable tours for each driver and which options you can configure.
INFO
The custom sorting algorithm isn't a self-service setting. Our support team enables it and sets up your formula for you, so contact them if you want to use it. For the standard sorting options, read Define how pickable tours are displayed in the Driver App first.
What the Custom Sorting Algorithm Does
By default, the pickable tours list is sorted by a single criterion: either the scheduled time of a tour or the distance from the driver to its first stop. Every driver sees the same list in the same order.
That forces a choice between two things that both matter. Sorting by scheduled time puts the most urgent tour first but ignores how far a driver has to travel to reach it. Sorting by distance puts the closest tour first but ignores a tour that's already running late. Neither works well on its own for a workforce that's constantly moving.
The custom sorting algorithm removes that either/or. Instead of one criterion, it uses a formula that combines several factors into a single score for each tour. Because one of the factors is the driver's own location, the score is calculated per driver: two drivers looking at the same pickable tours at the same moment can see them in a different order, each ranked for where that driver actually is.
How Tours Are Scored
Each tour in a driver's pickable list is scored by the formula, and the list is then ordered by that score. The score is recalculated as the underlying data changes, so a tour climbs the list as it becomes more urgent and moves down as the driver travels away from it.
A formula adds together the variables below, each multiplied by a weight you choose. The weights are what let you tune the ranking to your operation.
The Variables You Can Use
Three variables are available:
| Variable | What it measures | Notes |
|---|---|---|
scheduled_in_seconds | Seconds between now and the tour's scheduled time | Turns negative once the scheduled time has passed, so an overdue tour has a negative value |
driver_distance_meters | Distance from the driver's current location to the tour's first stop | This is the factor that makes the ranking personal to each driver |
tour_distance_meters | Total route distance of the tour | Reflects how much work, and typically how much revenue, the tour represents |
Values are in seconds and meters, so formulas usually divide them into more convenient units, for example scheduled_in_seconds / 60 for minutes or driver_distance_meters / 1000 for kilometers.
Choosing the Weights
Each variable is multiplied by a weight before the parts are added together. Two things decide what a weight does:
- The sign decides the direction. A positive weight means a larger value scores higher; a negative weight means a smaller value scores higher. Because a driver should usually see nearby tours first,
driver_distance_metersnormally gets a negative weight. - The size decides the influence. A weight of
2gives a variable twice the pull of a weight of1. Setting a weight to0removes that variable from the ranking.
Weights only matter relative to each other, so it's easiest to start with the factor that matters most to you, give it a weight of 1, and express the others as a fraction or multiple of it.
WARNING
The score is only meaningful together with the sort direction. A formula written so that a higher score means a better tour needs the direction set to descending, otherwise the least suitable tours appear at the top of the list. Whoever sets up your formula will match the two, but it's worth confirming the behavior when you first try it out.
An Example
Here's a formula that balances all three factors:
(-1 * (scheduled_in_seconds / 60))
+ (-1 * (driver_distance_meters / 1000))
+ (0.5 * tour_distance_meters / 1000)It's used with the sort direction set to descending, so the highest score appears first. Reading it line by line:
- Urgency. Minutes until the scheduled time, with a weight of
-1. A tour that's still 20 minutes away contributes-20, while a tour that's 10 minutes overdue contributes+10. Overdue tours therefore rise to the top, and the later a tour runs, the higher it climbs. - Proximity. Kilometers to the first stop, with a weight of
-1. A stop 2 km away contributes-2and one 8 km away contributes-8, so closer tours rank higher. It carries the same weight as urgency, meaning one minute of delay offsets roughly one kilometer of travel. - Tour length. Kilometers of total route distance, with a weight of
0.5. Longer tours score higher, so they're favored when two tours are otherwise similar. At half the weight of the other two factors, it acts as a tiebreaker rather than something that overrides urgency.
Adjusting this to your own operation is a matter of changing the weights. Raising the weight on tour length pushes drivers towards longer, higher-value tours. Raising the weight on proximity keeps drivers closer to home and cuts approach times. Lowering the weight on urgency lets punctuality give way to efficiency.
How It Works With the Other Settings
Custom sorting replaces how the pickable list is ordered. The other settings described in Define how pickable tours are displayed in the Driver App continue to apply:
- Sort direction decides whether the highest or the lowest score comes first. Read the warning under Choosing the Weights.
- Results limit caps how many tours a driver sees. With custom sorting this is a useful way to show only the best few matches instead of the whole list.
- Distance restrictions still limit the list to tours within the radius you set, so a tour beyond it doesn't appear however well it would score.
Related Features
Custom sorting changes the order in which a driver sees tours, but every eligible driver still sees them all. If you also want to control which drivers a tour is offered to, and in what order, see Introduction to the Driver Ranking & Gradual rollout feature.