Territories
The Territory class enables users to manage geographical areas within the VRP system. Territories are used to define service areas, organize operations, and manage orders within specific regions. This API provides endpoints to:
- Add new territories to the system.
- Retrieve and update territory details such as name, type, and geographical data.
- Delete territories when they are no longer needed.
- Generate territories dynamically based on provided coordinates.
- Retrieve orders inside the territory, then those orders can be used to create a new optimization.
Territory Structure
Each territory object consists of the following attributes:
| Name | Type | Description | Setter | Getter |
|---|---|---|---|---|
| Id | LargeInteger | Unique identifier for the territory. | ❌ | ✅ |
| Name | String | Name of the territory. | ✅ | ✅ |
| Type | ETerritoryType | Type of the territory | ✅ | ✅ |
| Data | DoubleListList | Data defining the territory shape. | ✅ | ✅ |
| Color | Rgba | Color of the territory. | ✅ | ✅ |
| Orders | OrderList | List of orders located inside the territory. | ❌ | ✅ |
Managing Territories
Creating a Territory
Territories must be created before they can be used for optimizations.
If the operation is successful, the territory will have an id assigned; which can be retrieved using the method territory.getId().
How it works
- Create a
vrp::Territoryand set the name, type (Circle, in this case), color and data. The data must contain the center's coordinates and the radius. - Create a
ProgressListenerandvrp::Service. - Call the
addTerritory()method from thevrp::Serviceusing thevrp::TerritoryandProgressListenerand wait for the operation to be done.
Example
Retrieving Territories
There are two ways to retrieve territory data:
a) Get a Territory by ID
Get a certain territory.
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::Territory. - Call the
getTerritory()method from thevrp::Serviceusing thevrp::Territoryfrom 1.), the ID of the territory that you want to retrieve and theProgressListener. - Once the operation completes, the
vrp::Territoryfrom 1.) will be populated.
b) Get All Territories (with optional filtering)
Returns all territories of the API user (which contain the search term).
How it works
- Create a
ProgressListener, avrp::Serviceand avrp::TerritoryList. - Call the
getAllTerritories()method from thevrp::Serviceusing the list from 1.) and theProgressListener. - Once the operation completes, the list from 1.) will be populated.
Updating a Territory
Territories can be updated with new names, types, or geographical data.
If the shape or the size of the territory is updated, then the list of orders that are inside the territory was also updated. You can access it using the method territory.getOrders().
How it works
- Create a
ProgressListenerand avrp::Service. - Retrieve the territory you want to update (see Get Territory) in a
vrp::Territory. - Change the desired fields of the
vrp::Territory. - Call the
updateTerritory()method from thevrp::Serviceusing thevrp::Territoryfrom 2.) and theProgressListenerand wait for the operation to be done.
Example
Deleting a Territory
Territories can be deleted individually or in bulk.
How it works
- Create a
ProgressListenerandvrp::Service. - Call the
deleteTerritory()method from thevrp::Serviceusing the territory's ID andProgressListenerand wait for the operation to be done.
Retrieving Territory Orders
Returns all orders that are inside the territory with the ID sent from the user.
How it works
- Create a
ProgressListenerandvrp::Serviceand avrp::OrderListin which the orders will be returned. - Call the
getTerritoriesOrders()method fromvrp::Serviceand theProgressListener. using the lists from . - Once the operation completes, the list from 1.) will contain the orders that are inside territory.
Example
Generating Territories
Generate territories based on a list of coordinates.
To generate one territory, minimum 3 coordinates are needed; remember that the number of coordinates should be at least 3 times the number of territories that you want to create.If the number of territories to be created is not specified, the algorithm will determinate how many should be created.
How it works
- Create a
CoordinatesListand add all theCoordinates. - Create a
ProgressListener,vrp::Serviceandvrp::Territorylist, in which the territories will be returned. - Call the
generateTerritories()method fromvrp::Serviceusing the lists from 2.) and 1., specify the number of territories that you want to create and the progress listener. - Once the operation completes, the list from 2.) will contain the generated territories.
Example
Error Handling
This API returns specific error codes to indicate potential issues. Below is a summary of common errors and how to resolve them:
| Error Code | Description | Solution |
|---|---|---|
KInvalidInput | Missing required fields or invalid territory data. | Ensure all mandatory fields are properly filled. |
KNotFound | The specified territory ID does not exist. | Verify that the correct territory ID is provided. |
KInternalAbort | Server-side issue or unexpected parsing error. | Retry the request or check API status. |