By default the router engine looks in the list of stops yet to be assigned and selects the one with the lowest index. However, it may be useful to select the next stop to be inserted into a route differently, which means that the default behaviour needs to overridden.
The router
engine provides the Selector
option to set up a custom selector for stops. This is done by writing a function that selects the next stop or even multiple stops.
Example
The router example is used as a base, where routes are created to visit seven landmarks in Kyoto using two vehicles and a score for each stop. This time, we define a function in code, not in the input file, to create a custom selector.
Save the following information in an input.json
file (see input and output for more information on working with input files).
Code
The following program uses the CLI Runner to obtain a solution and requires access to the Nextmv code repository on GitHub. To request access, please contact support@nextmv.io.
To proceed with running the example, create a main.go
file and use the code snippet below. We create a function to select the next stop based on a score which we then pass into the Selector
option.
To execute the example, specify the path to the input.json
file using command-line flags and use jq to extract the solution state (see runners for more information on building and running programs).
Solution
The solution should look similar to this one:
To find this solution, the highest priority stops were selected and assigned first.