Need technical support for GMPRO's advanced features? πŸ‘‹ Say Hello! to start working with Afi Labs.

GMPRO docs: Driver load balancing with soft constraints

Ways to apply vehicle loads and capacities to distribute stops evenly using the softMaxLoad and costPerUnitAboveSoftMax fields.

GMPRO docs: Driver load balancing with soft constraints

If your drivers are paid per trip, as is common for many third-party logistics (3PL) companies, it's important to distribute stops fairly so that each driver earns a similar income. In this blog post, I'll show you how to take advantage of the Google Maps Platform Route Optimization API 's load and capacities feature to balance stops evenly across routes.

A balanced route with an equal 3 stop / 2 vehicle split
A balanced route with an equal 3 stop / 2 vehicle split

I'll present two approaches. The first uses hard constraints that limit the number of stops each driver can do per route to prevent overloading any single driver with too many deliveries. The second employs soft capacities to balance routes while allowing some flexibility in overall driving distance to achieve an even distribution of work.

Part 1: GMPRO: Google Maps Platform route optimization API
Part 2: GMPRO TSP solver: Google Maps with more than 25 waypoints
Part 3: Google Maps route optimization: multi vehicle
Part 4: Fleet routing app - free Google Maps route planner for multiple stops
Part 5: GMPRO docs: Fixed vehicle costs
Part 6: GMPRO docs: Territory optimization and route planning
Part 7: GMPRO docs: Solving the VRP with route clustering and soft constraints
Part 8: GMPRO docs: Driver load balancing with soft constraints (this article)
Part 9: GMPRO docs: Driver breaks
Part 10: GMPRO docs: Complete deliveries before pickups in cargo bike logistics

Why do some routes have more stops than others?

This happens because it's often the most cost-effective way to plan the route. As I explained in my last post on route clustering, route optimization algorithms focus on minimizing the total cost or travel time for the fleet as a whole. They are not designed to account for fairness, workload balance, or equity among drivers.

πŸ‘¨β€πŸ’»
Screenshots in this blog post were taken with GMPRO-viewer , using data imported via GMPRO-json-converter. Both tools are free to use.

Consider this example: What is the lowest cost way to assign vehicles to stops to this route plan with 6 shipments and 2 vehicles? Assume that the fleet operates on a unit (1 km x 1 km) grid.

6 stop / 2 vehicle route plan before optimization
6 stop / 2 vehicle route plan before optimization

After some trial and error, you'll find that the most efficient way to solve this VRP is for the orange driver to do stops C, D, E and F and for the blue driver to do stops A and B for a total cost of 2 + 2 + 4 + 1 (orange) + 2 + 2 (blue) = 13.

Example A: Non balanced route with 6 stops / 2 vehicles

Other solutions are possible, but they require either the blue or orange drivers to travel an additional 3 units to reach the other side. Here’s a real-world example of this in action:

An unbalanced route without capacity constraints
An unbalanced route without capacity constraints

Input

{
    "model": {
        "shipments": [
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.2923352,
                            "longitude": -123.1317422
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"

                            }
                        ]
                    }
                ],
                "label": "yvr123"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.1654802,
                            "longitude": -123.1187887
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "label": "yvr456"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.313724,
                            "longitude": -123.0514561
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "label": "yvr789"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.343481,
                            "longitude": -123.0863414
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "label": "yvr987"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.3352081,
                            "longitude": -123.1453979
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "label": "yvr654"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.3513846,
                            "longitude": -123.2631103
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "label": "yvr321"
            }
        ],
        "vehicles": [
            {
                "startLocation": {
                    "latitude": 49.2808457,
                    "longitude": -123.0827831
                },
                "startTimeWindows": [
                    {
                        "startTime": "2024-07-08T16:00:00Z"
                    }
                ],
                "endTimeWindows": [
                    {
                        "endTime": "2024-07-08T18:00:00Z"
                    }
                ],
                "label": "mark-yvr",
                "costPerKilometer": 1
            },
            {
                "startLocation": {
                    "latitude": 49.3191441,
                    "longitude": -122.9522224
                },
                "startTimeWindows": [
                    {
                        "startTime": "2024-07-08T16:00:00Z"
                    }
                ],
                "endTimeWindows": [
                    {
                        "endTime": "2024-07-08T18:00:00Z"
                    }
                ],
                "label": "will-yvr",
                "costPerKilometer": 1
            }
        ],
        "globalStartTime": "2024-07-08T07:00:00Z",
        "globalEndTime": "2024-07-09T06:59:00Z"
    },
    "populatePolylines": true
}

Output

{
    "routes": [
        {
            "vehicleLabel": "mark-yvr",
            "vehicleStartTime": "2024-07-08T16:00:00Z",
            "vehicleEndTime": "2024-07-08T16:55:30Z",
            "visits": [
                {
                    "startTime": "2024-07-08T16:14:49Z",
                    "detour": "0s",
                    "shipmentLabel": "yvr123",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 1,
                    "startTime": "2024-07-08T16:45:30Z",
                    "detour": "1096s",
                    "shipmentLabel": "yvr456",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                }
            ],
            "transitions": [
                {
                    "travelDuration": "889s",
                    "travelDistanceMeters": 6170,
                    "waitDuration": "0s",
                    "totalDuration": "889s",
                    "startTime": "2024-07-08T16:00:00Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "2"
                        }
                    }
                },
                {
                    "travelDuration": "1241s",
                    "travelDistanceMeters": 11933,
                    "waitDuration": "0s",
                    "totalDuration": "1241s",
                    "startTime": "2024-07-08T16:24:49Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "1"
                        }
                    }
                },
                {
                    "travelDuration": "0s",
                    "waitDuration": "0s",
                    "totalDuration": "0s",
                    "startTime": "2024-07-08T16:55:30Z",
                    "vehicleLoads": {
                        "weight": {}
                    }
                }
            ],
            "routePolyline": {
                "points": "_dxkHnrfnV?`@HAN??f@Ar@@^@TDPFRBP@F?@@P?^?^?X?BAp@eBC@sFBeB@}@@mB?C@oB?O?g@?O?k@@}@?Y?S?m@@O?]A[?SAICWCa@Gc@B_@EWQ}@CMAKAME[AS?IAQAc@?g@?kA?_@RALOn@@H?|ABvA@|@?ZBvA@vAB|A@|A?vA?vAD|A@rA@xDBd@?t@@tA?jB?lA@tEBjB@R@fA@f@BRFNBV@h@Bh@B|@@^@vA@vA?r@ERALCPI`@?j@?xD@`@@r@@f@@Z?^@R?T?Z?J@N?V?n@@v@BpABr@?\\?H?PHn@BfA@zADBArA@RBtA@B?`@@R?\\?B@DAF?hAAX?B?p@AL?NAhACpA@?|@?z@?r@@l@A|BDV?^CfJA`K?~A?JAh@?v@?fB?jAAhI?x@ClC?^AdC?h@?^?v@?LAd@?X?~C?F?F?F?H?J?P?b@AV?D?F?F?D?nAAvF?v@CnI?~A?d@Ax@AVCPCr@Ar@_@|BIz@OdACXADGTER@x@AtC?h@?l@?`C?j@?`A?b@L?jDF\\AP?R?H?N@d@?B?V@T?NKxABr@@D?L?rCDb@@ApA?fA?LCfFAzDAvCAl@CxCEtE?V?RGvFGrFdBFxADD?|ABF@bBBh@@l@@|A@~ABhBBxABtA@vABzAB`@?b@@b@@fBBhBBdAF^B?d@?pAApA?bBCvB?bA?x@CzAAlA?`@AnD?h@AlA?R?XCpBAhC?ZATAlB?@AjB?HAl@?f@AhB?NClE?N?L?FAF?RA~B?d@?N?v@AnBEbE?@EnGC`CEpDAtA?F?t@C|A?`@N@PA^@V@~@BhA@fA@P?@?NEP?`ABR?l@@N?`B@zAARHDBF?|@@v@@lB@`@@lBB|@@PIfA@jCDzDDRAt@@h@?`A?pBBz@@f@?fA@L@T?dADb@Br@B`ABF?L@H?dA@@?jBB`HDXJJB|@@bA?N?fA@T@H?fDDn@?X?PA@AJEjA?fB@T@zFFN?~ADdA@tDHn@@f@@l@?DFD@D?Z@jA@j@@b@?T@P?\\Bj@A\\?L?l@@rABF?VK~@B`CDN?ZDjB@rBB|FFd@?nA?r@B`@@f@?vA?b@@D?T@T?n@BZ@RBVB^DB?^FTDVFPDZHZHZHTH@@XJXJXLZLPJVJXLB@RF@@RFDBVH`@J\\JXFf@Jb@FZDZD^DVBT@F?Z@@?\\@R@lEDtABdEDfDDrABzA@hIH`@?vBDP@T?d@@V?d@J\\@P?zAGl@E`@AB?B?XC@?D?^CtASPETE^MLENERG\\Sf@UTKNKTMd@]^Y@CZWPOZYRQf@e@bA_ApAkAv@q@l@k@x@u@TSrBmBDCtAqAd@_@\\[pAmAlAiAdDyCPMj@i@v@s@`CyBrAkAdB_BPONOBCPQdB{Af@e@dAaAj@e@HIJK~CqCJKr@o@BCz@w@NONMJIJI~@{@|@y@ROp@k@p@o@h@m@`@g@BCLSNUV_@j@aADGNWhAgBZe@d@w@h@{@l@cAPYDGt@qAj@}@FST?NGLEJAHANAX?T@H@N@tAB^@fA?bA@nC@JEFAF?|ECjA?zAAhB@lC?|C?X?lG?J@xA?jA@PAxA?T@x@?~@@Z@jB?R?Z?l@?bBAx@?rB?pAA`@@|RCN?|C?ZAx@Al@?P@ZDn@@n@?h@AJ?N?~B?`H@pB?X?D?zB?RA?rA?R?nB?rBAzB?\\?T@dA?x@?`C?lBAh@?f@d@B"
            },
            "metrics": {
                "performedShipmentCount": 2,
                "travelDuration": "2130s",
                "waitDuration": "0s",
                "delayDuration": "0s",
                "breakDuration": "0s",
                "visitDuration": "1200s",
                "totalDuration": "3330s",
                "travelDistanceMeters": 18103,
                "maxLoads": {
                    "weight": {
                        "amount": "2"
                    }
                }
            },
            "routeCosts": {
                "model.vehicles.cost_per_kilometer": 18.103
            },
            "routeTotalCost": 18.103
        },
        {
            "vehicleIndex": 1,
            "vehicleLabel": "will-yvr",
            "vehicleStartTime": "2024-07-08T16:00:00Z",
            "vehicleEndTime": "2024-07-08T17:25:07Z",
            "visits": [
                {
                    "shipmentIndex": 2,
                    "startTime": "2024-07-08T16:12:26Z",
                    "detour": "0s",
                    "shipmentLabel": "yvr789",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 3,
                    "startTime": "2024-07-08T16:32:19Z",
                    "detour": "966s",
                    "shipmentLabel": "yvr987",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 4,
                    "startTime": "2024-07-08T16:51:57Z",
                    "detour": "1951s",
                    "shipmentLabel": "yvr654",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 5,
                    "startTime": "2024-07-08T17:15:07Z",
                    "detour": "2926s",
                    "shipmentLabel": "yvr321",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                }
            ],
            "transitions": [
                {
                    "travelDuration": "746s",
                    "travelDistanceMeters": 7934,
                    "waitDuration": "0s",
                    "totalDuration": "746s",
                    "startTime": "2024-07-08T16:00:00Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "4"
                        }
                    }
                },
                {
                    "travelDuration": "593s",
                    "travelDistanceMeters": 7109,
                    "waitDuration": "0s",
                    "totalDuration": "593s",
                    "startTime": "2024-07-08T16:22:26Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "3"
                        }
                    }
                },
                {
                    "travelDuration": "578s",
                    "travelDistanceMeters": 6407,
                    "waitDuration": "0s",
                    "totalDuration": "578s",
                    "startTime": "2024-07-08T16:42:19Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "2"
                        }
                    }
                },
                {
                    "travelDuration": "790s",
                    "travelDistanceMeters": 12160,
                    "waitDuration": "0s",
                    "totalDuration": "790s",
                    "startTime": "2024-07-08T17:01:57Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "1"
                        }
                    }
                },
                {
                    "travelDuration": "0s",
                    "waitDuration": "0s",
                    "totalDuration": "0s",
                    "startTime": "2024-07-08T17:25:07Z",
                    "vehicleLoads": {
                        "weight": {}
                    }
                }
            ],
            "routePolyline": {
                "points": "eq_lHldmmVBADCB@^BAB@D@DBBB@BABCHGH?D?BC\\[JM`@c@R@H@TBAFAHAL?|@?v@A`AAt@dAFdB?fBCzAC?\\At@?v@?rAAlB@p@AdF?lB?b@CpC?lB?lBAv@?dD?zC?T?hC?PAdD?HAbBArC?hA?t@?v@A`KAvB?f@Av@?fA?~@Gb@?^?N?pB@x@?XBjB@Z?h@@t@@lA@vA@v@BxBL|HH|H?LBlB@lBD~ED~E@n@@jAAnD?lB?r@?z@AdC?t@Av@?v@?lBAt@?nBCjBAnB?t@?vAAdBAtBC|EAdDAbDAtCChB?nA?|BAjBAzE?\\AdDAdB?p@AhBAtB?BAt@?v@?hB?B?j@?D?P?T@V@VDp@Ff@D^Ff@F\\BJF\\H\\FRDR`@zA`AnCL\\?@L\\`@jAt@xBL^JXNb@n@bBHTLTZl@bArBZj@pA~BdB|CVb@p@tAh@`A`@r@r@lANZr@bBTp@Np@TlAHdABl@@n@CbACh@ALGd@EZGh@G\\Mv@Kp@Kj@AFCVE`@Ej@?BEn@AZ?N?T?R?Z?NBj@@^@T@B@TH`ALlABVFv@JdA@HFt@Hz@Dd@@HFr@Dd@B\\@^@\\?\\?BAXA\\CXCPMj@?DI\\GPCFGN]t@CFCDs@rAi@fAm@jAO\\M\\KTIVENENKd@W~AE^CXEh@Eh@?BEhAAh@?f@AjAAd@?N?T?l@?l@?`@BjA@RFtADv@BhAD`@B\\DTNv@Lj@DNFVFVLd@Nn@FZFT?BDTFf@?p@?ZALAJCTEPITELGLE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DPDP@RARKNKHSLa@Hm@Hc@HQDIPOPMRGFATCD?d@A^Cx@Bb@@R@N@b@@b@@X@H@D@JHJJHNRv@FT@DLRJHVNRPJB^LZNFD^Td@f@Z`@TXJPJN\\ZXVNJB@\\J@?ZBh@?XYR]VeANi@Pm@DKLc@@ARi@J]@?h@mALUFKNSBAVSFALCR?TD`@LVLLFHJHSHKFCL?LBD@PHn@`@Z^RPHJVXt@z@HJVb@@@Rl@Rl@@DNr@Dj@D^?V@t@@rA?X@v@?x@@j@"
            },
            "metrics": {
                "performedShipmentCount": 4,
                "travelDuration": "2707s",
                "waitDuration": "0s",
                "delayDuration": "0s",
                "breakDuration": "0s",
                "visitDuration": "2400s",
                "totalDuration": "5107s",
                "travelDistanceMeters": 33610,
                "maxLoads": {
                    "weight": {
                        "amount": "4"
                    }
                }
            },
            "routeCosts": {
                "model.vehicles.cost_per_kilometer": 33.61
            },
            "routeTotalCost": 33.61
        }
    ],
    "metrics": {
        "aggregatedRouteMetrics": {
            "performedShipmentCount": 6,
            "travelDuration": "4837s",
            "waitDuration": "0s",
            "delayDuration": "0s",
            "breakDuration": "0s",
            "visitDuration": "3600s",
            "totalDuration": "8437s",
            "travelDistanceMeters": 51713,
            "maxLoads": {
                "weight": {
                    "amount": "4"
                }
            }
        },
        "usedVehicleCount": 2,
        "earliestVehicleStartTime": "2024-07-08T16:00:00Z",
        "latestVehicleEndTime": "2024-07-08T17:25:07Z",
        "totalCost": 51.713,
        "costs": {
            "model.vehicles.cost_per_kilometer": 51.713
        }
    }
}

Balance routes with hard constraints

So how can we balance this route? The most straightforward way to do this is to apply a route balancing policy where we introduce additional constraints to prevent any single route from being significantly longer than others. In the example above, we have 6 shipments and 2 vehicles, so we can set a target load per vehicle of 6 / 2 = 3 deliveries each.

To do this, we first set a loadLimit of 3 in the vehicle object within the GMPRO request payload, as shown below:

{
    "loadLimits": {
        "stopCount": {
            "maxLoad": 3
        }
    }
}

And include the corresponding loadDemands on each shipment object.

{
    "loadDemands": {
        "stopCount": {
            "amount": "1"
        }
    }
}

This will instruct the GMPRO solver to allocate a maximum of 3 shipments to each vehicle. Since route optimization algorithms aim to serve all shipments without leaving any unassigned, each vehicle will end up with exactly 3 shipments each.

GMPRO driver load balancing example with hard constraints

Here's what the route plan looks like with load constraints added:

A balanced route created with hard capacity constraints added
A balanced route created with hard capacity constraints added

And here's the accompanying JSON:

Input

{
    "model": {
        "shipments": [
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.2923352,
                            "longitude": -123.1317422
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"

                            }
                        ]
                    }
                ],
                "loadDemands": {
                    "weight": {
                        "amount": "1"
                    }
                },
                "label": "yvr123"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.1654802,
                            "longitude": -123.1187887
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "loadDemands": {
                    "weight": {
                        "amount": "1"
                    }
                },
                "label": "yvr456"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.313724,
                            "longitude": -123.0514561
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "loadDemands": {
                    "weight": {
                        "amount": "1"
                    }
                },
                "label": "yvr789"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.343481,
                            "longitude": -123.0863414
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "loadDemands": {
                    "weight": {
                        "amount": "1"
                    }
                },
                "label": "yvr987"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.3352081,
                            "longitude": -123.1453979
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "loadDemands": {
                    "weight": {
                        "amount": "1"
                    }
                },
                "label": "yvr654"
            },
            {
                "deliveries": [
                    {
                        "arrivalLocation": {
                            "latitude": 49.3513846,
                            "longitude": -123.2631103
                        },
                        "duration": "600s",
                        "timeWindows": [
                            {
                                "startTime": "2024-07-08T16:00:00Z",
                                "endTime": "2024-07-08T18:00:00Z"
                            }
                        ]
                    }
                ],
                "loadDemands": {
                    "weight": {
                        "amount": "1"
                    }
                },
                "label": "yvr321"
            }
        ],
        "vehicles": [
            {
                "startLocation": {
                    "latitude": 49.2808457,
                    "longitude": -123.0827831
                },
                "startTimeWindows": [
                    {
                        "startTime": "2024-07-08T16:00:00Z"
                    }
                ],
                "endTimeWindows": [
                    {
                        "endTime": "2024-07-08T18:00:00Z"
                    }
                ],
                "loadLimits": {
                    "weight": {
                        "maxLoad": 3
                    }
                },
                "label": "mark-yvr",
                "costPerKilometer": 1
            },
            {
                "startLocation": {
                    "latitude": 49.3191441,
                    "longitude": -122.9522224
                },
                "startTimeWindows": [
                    {
                        "startTime": "2024-07-08T16:00:00Z"
                    }
                ],
                "endTimeWindows": [
                    {
                        "endTime": "2024-07-08T18:00:00Z"
                    }
                ],
                 "loadLimits": {
                    "weight": {
                        "maxLoad": 3
                    }
                },
                "label": "will-yvr",
                "costPerKilometer": 1
            }
        ],
        "globalStartTime": "2024-07-08T07:00:00Z",
        "globalEndTime": "2024-07-09T06:59:00Z"
    },
    "populatePolylines": true
}

Output

{
    "routes": [
        {
            "vehicleLabel": "mark-yvr",
            "vehicleStartTime": "2024-07-08T16:00:00Z",
            "vehicleEndTime": "2024-07-08T17:37:01Z",
            "visits": [
                {
                    "startTime": "2024-07-08T16:14:20Z",
                    "detour": "0s",
                    "shipmentLabel": "yvr123",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 4,
                    "startTime": "2024-07-08T16:34:34Z",
                    "detour": "791s",
                    "shipmentLabel": "yvr654",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 1,
                    "startTime": "2024-07-08T17:27:01Z",
                    "detour": "3592s",
                    "shipmentLabel": "yvr456",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                }
            ],
            "transitions": [
                {
                    "travelDuration": "860s",
                    "travelDistanceMeters": 4984,
                    "waitDuration": "0s",
                    "totalDuration": "860s",
                    "startTime": "2024-07-08T16:00:00Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "3"
                        }
                    }
                },
                {
                    "travelDuration": "614s",
                    "travelDistanceMeters": 7187,
                    "waitDuration": "0s",
                    "totalDuration": "614s",
                    "startTime": "2024-07-08T16:24:20Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "2"
                        }
                    }
                },
                {
                    "travelDuration": "2547s",
                    "travelDistanceMeters": 22936,
                    "waitDuration": "0s",
                    "totalDuration": "2547s",
                    "startTime": "2024-07-08T16:44:34Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "1"
                        }
                    }
                },
                {
                    "travelDuration": "0s",
                    "waitDuration": "0s",
                    "totalDuration": "0s",
                    "startTime": "2024-07-08T17:37:01Z",
                    "vehicleLoads": {
                        "weight": {}
                    }
                }
            ],
            "routePolyline": {
                "points": "_dxkHnrfnV?`@HAN??O?k@?i@TBVDXHl@T`BfA@@LFNFPDH@HB@?B?PBVB`CHr@ClAF~@B@y@@sAj@@J@Z?R??P?L?J?J@J?J?F@J?H@H?F@H@F@L@DBN@FBNDRBLDPDRDP?@BRBRBR?N@H?D@J?H?H?L?J?L?P?l@EbK?LAX?XApB?t@Av@?FC|C?t@ArBAv@AlBAlBCzEAv@AlBElKApAA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HIJK~CqCJKr@o@BCz@w@NONMJIJI~@{@|@y@ROp@k@p@o@h@m@`@g@BCLSNUV_@j@aADGNWhAgBZe@d@w@h@{@l@cAPYDGt@qAj@}@FST?NGLEJAHANAX?T@H@N@tAB^@fA?bA@nC@JEFAF?|ECjA?zAAhB@lC?|C?X?lG?J@xA?jA@PAxA?T@x@?~@@Z@jB?R?Z?l@?bBAb@?T?rB?pAA`@@`LAzEAN?|C?ZAx@Al@?P@ZDn@@n@?h@AJ?N?~B?`H@pB?X?D?zB?RA?rA?R?nB?rBAzB?\\?T@dA?x@?`C?lBAh@?f@d@B"
            },
            "metrics": {
                "performedShipmentCount": 3,
                "travelDuration": "4021s",
                "waitDuration": "0s",
                "delayDuration": "0s",
                "breakDuration": "0s",
                "visitDuration": "1800s",
                "totalDuration": "5821s",
                "travelDistanceMeters": 35107,
                "maxLoads": {
                    "weight": {
                        "amount": "3"
                    }
                }
            },
            "routeCosts": {
                "model.vehicles.cost_per_kilometer": 35.107
            },
            "routeTotalCost": 35.107
        },
        {
            "vehicleIndex": 1,
            "vehicleLabel": "will-yvr",
            "vehicleStartTime": "2024-07-08T16:00:00Z",
            "vehicleEndTime": "2024-07-08T17:08:27Z",
            "visits": [
                {
                    "shipmentIndex": 2,
                    "startTime": "2024-07-08T16:12:11Z",
                    "detour": "0s",
                    "shipmentLabel": "yvr789",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 3,
                    "startTime": "2024-07-08T16:31:38Z",
                    "detour": "940s",
                    "shipmentLabel": "yvr987",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                },
                {
                    "shipmentIndex": 5,
                    "startTime": "2024-07-08T16:58:27Z",
                    "detour": "1938s",
                    "shipmentLabel": "yvr321",
                    "loadDemands": {
                        "weight": {
                            "amount": "-1"
                        }
                    }
                }
            ],
            "transitions": [
                {
                    "travelDuration": "731s",
                    "travelDistanceMeters": 7966,
                    "waitDuration": "0s",
                    "totalDuration": "731s",
                    "startTime": "2024-07-08T16:00:00Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "3"
                        }
                    }
                },
                {
                    "travelDuration": "567s",
                    "travelDistanceMeters": 7109,
                    "waitDuration": "0s",
                    "totalDuration": "567s",
                    "startTime": "2024-07-08T16:22:11Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "2"
                        }
                    }
                },
                {
                    "travelDuration": "1009s",
                    "travelDistanceMeters": 16891,
                    "waitDuration": "0s",
                    "totalDuration": "1009s",
                    "startTime": "2024-07-08T16:41:38Z",
                    "vehicleLoads": {
                        "weight": {
                            "amount": "1"
                        }
                    }
                },
                {
                    "travelDuration": "0s",
                    "waitDuration": "0s",
                    "totalDuration": "0s",
                    "startTime": "2024-07-08T17:08:27Z",
                    "vehicleLoads": {
                        "weight": {}
                    }
                }
            ],
            "routePolyline": {
                "points": "ks_lHbfmmV?l@s@??l@?LAp@L?F?rA@~@@x@A~AGJ?dAFdB?j@Az@AzAC?\\At@?v@?rAAlB@p@AdF?lB?b@CpC?lB?lBAv@?dD?zC?T?hC?PAdD?H?r@An@ArC?hA?t@?v@A`KAvB?f@Av@?fA?~@Gb@?^?N?pB@x@?XBjB@Z?h@@t@@lA@vA@v@BxBL|HH|H?LBlB@lBD~ED~E@n@@jAAnD?lB?r@?z@AdC?t@Av@?v@?lBAt@?nBCjBAnB?t@?vAAdBAtBC|EAdDAbDAtCChB?nA?|BAjBAzE?\\AdDAdB?p@AhBAtB?BAt@?v@?hB?B?j@?D?P?T@V@VDp@Ff@D^Ff@F\\BJF\\H\\FRDR`@zAj@|ATp@L\\?@L\\HVVr@t@xBL^JXNb@n@bBHTLTZl@bArBZj@pA~BnAxBTb@Vb@p@tAh@`A`@r@r@lANZr@bBTp@Np@TlAHdABl@@n@CbACh@ALGd@EZGh@G\\Mv@Kp@Kj@AFCP?DE`@Ej@?BEn@AZ?N?T?R?Z?NBj@@^@T@B@TH`ALlABVFv@JdA@HFt@Hz@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\CTAZ?JDbAB\\Fp@?BF^PtAF|@@bAARC|@CrA@f@B`@Dt@@L@V@N@DBZ?D?L@p@?DA`@?BANANCXOv@If@G`@Gd@ANATIpA?BEh@AJIh@CHQh@M\\CJAFAD?J?LBFFJFHJHHDPDP@RARKNKHSLa@Hm@Hc@HQDIPOPMRGFATCD?d@A^Cx@Bb@@R@N@b@@b@@X@H@D@JHJJHNRv@FT@DLRJHVNRPJB^LZNFD^Td@f@Z`@TXJPJN\\ZXVNJB@\\J@?ZBh@?XYR]VeANi@Pm@DKLc@@ARi@J]@?h@mALUFKNSBAVSFALCR?TD`@LVLLFHJHSHKFCL?LBD@PHn@`@Z^RPHJVXt@z@HJVb@@@Rl@Rl@@DNr@Dj@D^?V@t@@rA?X@v@?x@@j@"
            },
            "metrics": {
                "performedShipmentCount": 3,
                "travelDuration": "2307s",
                "waitDuration": "0s",
                "delayDuration": "0s",
                "breakDuration": "0s",
                "visitDuration": "1800s",
                "totalDuration": "4107s",
                "travelDistanceMeters": 31966,
                "maxLoads": {
                    "weight": {
                        "amount": "3"
                    }
                }
            },
            "routeCosts": {
                "model.vehicles.cost_per_kilometer": 31.966
            },
            "routeTotalCost": 31.966
        }
    ],
    "metrics": {
        "aggregatedRouteMetrics": {
            "performedShipmentCount": 6,
            "travelDuration": "6328s",
            "waitDuration": "0s",
            "delayDuration": "0s",
            "breakDuration": "0s",
            "visitDuration": "3600s",
            "totalDuration": "9928s",
            "travelDistanceMeters": 67073,
            "maxLoads": {
                "weight": {
                    "amount": "3"
                }
            }
        },
        "usedVehicleCount": 2,
        "earliestVehicleStartTime": "2024-07-08T16:00:00Z",
        "latestVehicleEndTime": "2024-07-08T17:37:01Z",
        "totalCost": 67.073000000000008,
        "costs": {
            "model.vehicles.cost_per_kilometer": 67.073000000000008
        }
    }
}

Generally, if you have n shipments and k vehicles, setting each vehicle's loadLimit to n/k rounded up can help distribute stops evenly across your fleet. This type of rebalancing policy is known as a hard constraint because the route optimization solver will make sure that a vehicle's load never exceeds its capacity, even if it means leaving some stops unassigned.

Balance routes with soft constraints

A more effective approach to setting up a route balancing policy is to use soft constraints, which allow you to trade off route efficiency for route equality. For example, consider the scenario we looked at earlier with 6 shipments and 2 vehicles, with each driver having a maximum capacity of 3.

Example B: Balanced route with 6 stops / 2 vehicles

The total cost now is 2 + 2 + 4 + 1 (orange) + 2 + 2 +3 (blue) = 16, or 3 more than the route optimal solution we saw in the first instance (Example A). The difference in cost can be entirely attributed to the detour of 3 units that driver blue had to make in going from B to D to keep the route balanced.

If we want the GMPRO solver to ignore the capacity constraint if it means that one or more vehicles have to make large detours to maintain it, we can add a small penalty for each stop above a vehicle's target capacity. In the example above, we could add a penalty of 2.5 units (which is less than the detour value of 3 units) for each stop above a vehicle's target capacity like so:

{
    "loadLimits": {
        "stopCount": {
            "softMaxLoad": 3,
            "costPerUnitAboveSoftMax": 2.5
        }
    }
}

The total cost of an unbalanced 4 stop (orange) + 2 stop (blue) route solution is now 2 + 2 + 4 + 1 + 2.5 (penalty) for orange and 2 + 2 for blue = 15.5. This is less than the total cost of 16 in the perfectly balanced route given in Example B, so the unbalanced solution is preferred.

Example C: Non balanced route with 6 stops / 2 vehicles and a small penalty

If the detour was smaller because the stops were closer together as shown in Example D:

Example D: Balanced route with 6 stops / 2 vehicles and soft capacities

The total cost is now 2 + 2 + 4 + 1 (orange) + 2 + 2 + 2 (blue) = 15, which is less than the 15.5 total cost for the unbalanced route in Example C. This means that the 3 stop per driver balanced solution is preferred.

GMPRO driver load balancing example with soft constraints

Let's test out soft constraints in our real world, 6 shipment 2 vehicle example. If we compare the total mileage from the optimal, unbalanced route solution with the suboptimal balanced one, we get a difference of 65,989m (balanced) - 54,049m (unbalanced) = 11,940m. This is effectively the length of the round trip detour from blue stop 1 to blue stop 2. Since we've set "costPerKilometer": 1 for both drivers, the effective cost of this detour is 11.94.

Balanced (suboptimal) vs Unbalanced (optimal) routes with detours included
Balanced (suboptimal) vs Unbalanced (optimal) routes with detours included

Let's set "softMaxLoad": 3 and "costPerUnitAboveSoftMax": 12. This configuration tells GMPRO that if any vehicle exceeds a load of 3, a penalty of 12 units will be added to the route solution, which makes it more cost-effective to balance routes by allowing the blue driver to take a detour of up to 11,940 meters.

Input ("softMaxLoad":3 and "costPerUnitAboveSoftMax": 12)

Output

Result (balanced route)

Balanced routes using soft capacity constraints
Balanced routes using soft capacity constraints

As expected, the soft constraints gave us a balanced route of 2 vehicles with 3 shipments each.

Next, let's change the value of costPerUnitAboveSoftMax to something small like 5. Such a small penalty means that unbalanced routes will generally be preferred, unless the detour cost is less than 5 units.

Input ("softMaxLoad":3 and "costPerUnitAboveSoftMax": 5)

Output

Result (unbalanced route)

Unbalanced routes using non-binding soft capacity constraints
Unbalanced routes using non-binding soft capacity constraints

Since the penalty of 5 units is too small to matter, we get an unbalanced (but optimal) route with a 4 shipment / 2 vehicle split.

Conclusion

In this blog post, I showed how to balance routes produced by the Google Maps Platform Route Optimization API using two methods. The first method divides the total number of stops by the number of drivers, rounds up, and sets this as the maximum number of stops per vehicle. The second uses soft constraints to achieve a balance between route efficiency and fairness, favoring a balanced solution only when the additional cost is below a specified threshold. Both methods have their place, and as route planners it is your job to decide which one best balances (haha) driver satisfaction with operational efficiency.

πŸ‘‹ As always, if you have any questions or suggestions for me, please reach out or say hello on LinkedIn.

Next: Part 9: GMPRO docs: Driver breaks