17 using System.Collections.Generic;
19 using Google.Protobuf.WellKnownTypes;
30 static void PrintSolution(
35 long maxRouteDistance = 0;
36 for (
int i = 0; i < manager.GetNumberOfVehicles(); ++i) {
37 Console.WriteLine(
"Route for Vehicle {0}:", i);
38 long routeDistance = 0;
39 var index = routing.Start(i);
40 while (routing.IsEnd(index) ==
false) {
41 Console.Write(
"{0} -> ", manager.IndexToNode((
int)index));
42 var previousIndex = index;
43 index = solution.Value(routing.NextVar(index));
44 routeDistance += routing.GetArcCostForVehicle(previousIndex, index, 0);
46 Console.WriteLine(
"{0}", manager.IndexToNode((
int)index));
47 Console.WriteLine(
"Distance of the route: {0}m", routeDistance);
48 maxRouteDistance = Math.Max(routeDistance, maxRouteDistance);
50 Console.WriteLine(
"Maximum distance of the routes: {0}m", maxRouteDistance);
54 public static void Main(String[] args) {
57 int locationNumber = 20;
58 int vehicleNumber = 5;
79 (
long fromIndex,
long toIndex) => {
111 searchParameters.
TimeLimit =
new Duration { Seconds = 10 };
121 PrintSolution(manager, routing, solution);
Minimal TSP using distance matrix.
static void Main(String[] args)