Many transport companies operate in a mode where a driver-vehicle combination serves a certain geographic area, due to business constraints, to retain a strong customer relationship and for other reasons.
The Territory optimization feature allows programmatically distributing the vehicles between the specific districts or areas in the most advantageous way when optimizing tours. When optimizing territories while building your requests, you can control the balance between the workload and fleet capacity in the terms of location of the jobs to be executed. Assign your vehicles or groups of vehicles to the specific territories to allow them to operate on the desired territories, or restrict operating on the others.
In the Tour Planning, territories are used to define spatial restrictions on the jobs which a vehicle is allowed or preferred to take. When building a problem, each territory is referred to by its id, which is in full control of the user and not bound in any way to its geographical location or administrative nomenclature. The id of a territory is a unique identifier that is consistently used in both vehicle and job definitions. It is the responsibility of the user to assign territories to jobs so that they correctly represent the location of the jobs.
In this tutorial we consider three approaches to Territory optimization:
The Exclusive Territories feature can be applied when you need to restrict vehicles or groups of vehicles to execute jobs only within the specific district or area. Consider a fleet where each vehicle is only allowed to visit a specific region, e.g., a city district.
For a given vehicle type, its territories field contains the id of the territory to which the vehicle is restricted - North in the example.
In the example below we have 2 vehicles and 3 jobs to execute in different areas - job A in the North, job B in the South, and job C with no territory specified. In this problem, each vehicle is allowed to visit only one of those territories.
Figure 1. Job plan with the depot (@), three jobs (A, B, C) and exclusive territories (North in violet and South in red)
In the solution for this problem, the vehicle car_1 is only assigned to the jobs where the territoryIds attribute contains North - in this case, only job A. Accordingly, the vehicle car_2 is assigned to the job B which is in territory South. Job C, which is neither in North nor in South, is not included in the tour at all.
Figure 2. Solution for exclusive territories with car_1 (yellow tour) and car_2 (green tour)
{"statistic":{"cost":0.2675,"distance":2675,"duration":447,"times":{"driving":447,"serving":0,"waiting":0,"break":0}},"tours":[{"vehicleId":"car_2_1","typeId":"car_2","stops":[{"location":{"lat":47.625729,"lng":-122.337255},"time":{"arrival":"2021-07-04T06:03:00Z","departure":"2021-07-04T06:03:00Z"},"load":[0],"activities":[{"jobId":"departure","type":"departure"}],"distance":0},{"location":{"lat":47.623887,"lng":-122.341163},"time":{"arrival":"2021-07-04T06:04:54Z","departure":"2021-07-04T06:04:54Z"},"load":[0],"activities":[{"jobId":"B","type":"delivery"}],"distance":630},{"location":{"lat":47.625729,"lng":-122.337255},"time":{"arrival":"2021-07-04T06:06:33Z","departure":"2021-07-04T06:06:33Z"},"load":[0],"activities":[{"jobId":"arrival","type":"arrival"}],"distance":1155}],"statistic":{"cost":0.1155,"distance":1155,"duration":213,"times":{"driving":213,"serving":0,"waiting":0,"break":0}},"shiftIndex":0},{"vehicleId":"car_1_1","typeId":"car_1","stops":[{"location":{"lat":47.625729,"lng":-122.337255},"time":{"arrival":"2021-07-04T06:03:00Z","departure":"2021-07-04T06:03:00Z"},"load":[0],"activities":[{"jobId":"departure","type":"departure"}],"distance":0},{"location":{"lat":47.628661,"lng":-122.342312},"time":{"arrival":"2021-07-04T06:04:48Z","departure":"2021-07-04T06:04:48Z"},"load":[0],"activities":[{"jobId":"A","type":"delivery"}],"distance":760},{"location":{"lat":47.625729,"lng":-122.337255},"time":{"arrival":"2021-07-04T06:06:54Z","departure":"2021-07-04T06:06:54Z"},"load":[0],"activities":[{"jobId":"arrival","type":"arrival"}],"distance":1520}],"statistic":{"cost":0.152,"distance":1520,"duration":234,"times":{"driving":234,"serving":0,"waiting":0,"break":0}},"shiftIndex":0}],"unassigned":[{"jobId":"C","reasons":[{"code":"TERRITORY_CONSTRAINT","description":"cannot be assigned due to territory constraint"}]}]}
Preferred Territories
There might be vehicles in a fleet that should have preferred territories - the areas where they would operate more efficiently for some reasons, so the dispatcher would like them to operate there preferably. But they should also pick up the jobs outside of those preferred territories, if they have spare capacity and timing, so only assigning them to the specific areas would be too restrictive. The Preferred territories option allows to schedule the jobs on those preferred districts with precedence, and if possible, the other jobs from the other territories can be scheduled.
In Tour Planning, such territory preference is marked by "strict": false, as opposed to the strict limitation to a territory denoted by "strict": true.
Note that a job without the territory specified in its place can be only picked up by vehicles with preferred territories and by vehicles without any territory assigned. Vehicles with strict territories cannot serve such jobs.
In the example below we have 2 vehicles. We set one of them to operate strictly in the territory North, and another one in the territory South, but without restriction. We need to execute 5 jobs, 2 of them in the territory North, one in the South, another one in the South-East (which is not assigned to any of the vehicles), and one job outside the preferred territories.
Figure 3. Job plan with the depot (@), five jobs (A to E) and preferred territories (North in violet, South in red, South-East in orange)
From the solution, we can see that the vehicle type car_1 is only assigned to the job with territoryIds attribute North, since its territory assignment is strict. Due to the time restriction on its shift, only job A can be assigned to it.
The vehicle type car_2 is assigned to the job B, which is in its preferred territory South. Besides that, since it has spare capacity in its longer shift, it will be assigned to the job C from a territory that is not explicitly served by any vehicle (South-East), job E without any territory, and job D in the North which cannot be served by car_1 due to its time restriction.
Figure 4. Solution for preferred territories with car_1 (yellow tour) and car_2 (green tour)
If the territory limitations set for a vehicle are not strict, but more fine-grained control than offered by preferred territories is required, then the territories can be prioritized. That means that a vehicle can be assigned to several areas or districts with differing priorities. For example, to set the most prioritized territory, you should set its priority to 1, and use 2 for a territory with a lower priority, and so on, up to 5. Note that different territories can have the same priority. When evaluating schedules of the jobs for a vehicle, the jobs from its higher priority territories take precedence over the jobs from its lower priority territories.
Note that the option of setting more than one territory with the same priority for a vehicle may solve the situation when the jobs cannot be executed by the standard territory-bound vehicles. When you set several territories (or all of them) with the lower priority for one of your vehicles, then such a vehicle will serve the jobs that cannot be assigned to the rest of the vehicles. Check the vehicle type joker in the example to see how it will operate.
In the example below we have 3 vehicles:
car_1 operates strictly in 2 territories - North with higher priority and South with lower priority.
car_2 operates strictly in 3 territories - South with higher priority, and North together with South-East with lower priority.
joker operates in all 3 territories North, South, and South-East with lower priority than the rest of the fleet and is allowed to operate outside the territories as well.
Those vehicles are intended to execute 6 jobs in the different areas:
job A in the North
job B in the South
job C in the South-East
job D in the North
job E outside the prioritized territories
job F in the South-East
Figure 5. Job plan with the depot (@), six jobs (A to F) and prioritized territories (North in violet, South in red, South-East in orange)
In the solution, the vehicle type car_1 serves job A as it is in its high priority zone North, but is not assigned job D in the North or job F in South-East due to its shift time restriction.
Vehicle type car_2 serves job B as it is in its highest priority territory South, and also job D that is in its lower priority territory North, and job C in its lower priority territory South-East.
And finally, since the joker's territory preference is not strict, it will execute job F in the South-West, and job E outside the prioritized territories.
Figure 6. Solution for prioritized territories with car_1 (yellow tour), car_2 (light-green tour) and joker (dark-green tour)