Ejemplo n.º 1
0
        public void TestTransitMatrix()
        {
            // Create Routing Index Manager
            RoutingIndexManager manager = new RoutingIndexManager(5 /*locations*/, 1 /*vehicle*/, 0 /*depot*/);
            // Create Routing Model.
            RoutingModel routing = new RoutingModel(manager);

            // Create a distance callback.
            long[][] matrix = new long[][] {
                new long[] { 1, 1, 1, 1, 1 },
                new long[] { 1, 1, 1, 1, 1 },
                new long[] { 1, 1, 1, 1, 1 },
                new long[] { 1, 1, 1, 1, 1 },
                new long[] { 1, 1, 1, 1, 1 },
            };
            int transitCallbackIndex = routing.RegisterTransitMatrix(matrix);

            // Define cost of each arc.
            routing.SetArcCostEvaluatorOfAllVehicles(transitCallbackIndex);
            // Setting first solution heuristic.
            RoutingSearchParameters searchParameters =
                operations_research_constraint_solver.DefaultRoutingSearchParameters();

            searchParameters.FirstSolutionStrategy = FirstSolutionStrategy.Types.Value.PathCheapestArc;
            Assignment solution = routing.SolveWithParameters(searchParameters);

            // 0 --(+1)-> 1 --(+1)-> 2 --(+1)-> 3 --(+1)-> 4 --(+1)-> 0 := +5
            Assert.Equal(5, solution.ObjectiveValue());
        }