Go to the documentation of this file.
24 public static void Main(String[] args) {
27 const int numLocation = 5;
28 const int numVehicles = 1;
34 RoutingIndexManager manager =
new RoutingIndexManager(
42 RoutingModel routing =
new RoutingModel(manager);
47 int transitCallbackIndex = routing.RegisterTransitCallback(
48 (
long fromIndex,
long toIndex) => {
50 var fromNode = manager.IndexToNode(fromIndex);
51 var toNode = manager.IndexToNode(toIndex);
52 return Math.Abs(toNode - fromNode);
58 routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex);
63 RoutingSearchParameters searchParameters =
64 operations_research_constraint_solver.DefaultRoutingSearchParameters();
65 searchParameters.FirstSolutionStrategy =
66 FirstSolutionStrategy.Types.Value.PathCheapestArc;
71 Assignment solution = routing.SolveWithParameters(searchParameters);
76 Console.WriteLine(
"Objective: {0}", solution.ObjectiveValue());
78 long index = routing.Start(0);
79 Console.WriteLine(
"Route for Vehicle 0:");
80 long route_distance = 0;
81 while (routing.IsEnd(index) ==
false) {
82 Console.Write(
"{0} -> ", manager.IndexToNode((
int)index));
83 long previousIndex = index;
84 index = solution.Value(routing.NextVar(index));
85 route_distance += routing.GetArcCostForVehicle(previousIndex, index, 0);
87 Console.WriteLine(
"{0}", manager.IndexToNode(index));
88 Console.WriteLine(
"Distance of the route: {0}m", route_distance);
This is a sample using the routing library .Net wrapper.
static void Main(String[] args)