By default, the router engine marshals the solution state with basic information, similar to this structure:
In the above snippet, you can observe that only the unassigned stops and the routes assigned to the vehicles are shown. Sometimes it is useful to modify the output to achieve a desired structure or to showcase custom information. The router
engine provides the Output
option to set up a custom output marshaler, relying on the fleet engine. Given this, the Output
option takes one argument: a Marshaler
interface, part of the route
package. You can specify a custom type to implement this interface and personalize the state output marshaling in the underlying fleet
engine.
Example
The aim of this example is to define a custom output when using multiple vehicles. The introductory router example is used as a base, where routes are created to visit seven landmarks in Kyoto using two vehicles.
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. A custom type called marshaler
is defined to implement the Marshaler
interface. To modify the default output, only the total number of stops are displayed per route, as opposed to listing all stops. The same change is applied to the unassigned stops.
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:
You can see that the marshalled solution state is different than the introductory router solution.