/// <summary>
            /// Constructs the dimension.
            /// </summary>
            /// <param name="context"></param>
            /// <param name="scope"></param>
            /// <see cref="!:https://developers.google.com/optimization/routing/tsp#distance_callback"/>
            public TestDimension(RoutingContext context, CircuitBoardCaseStudyScope scope)
                : base(context, scope.DimensionCoefficient)
            {
                if (this.Coefficient > 0)
                {
                    this.Scope = scope;

                    var evaluatorIndex = this.RegisterTransitEvaluationCallback(this.OnEvaluateTransit);

                    // TODO: TBD: I'm not sure we actually ever add the dimension here ...
                    // TODO: TBD: should review the example again to make sure that we actually should/are/do... (take your pick)
                    this.SetArcCostEvaluators(evaluatorIndex);
                }
            }
Exemplo n.º 2
0
        public void Verify_ProblemSolver_GuidedLocal_Solution(CircuitBoardCaseStudyScope scope)
        {
            $"Verify {nameof(scope)}".x(() => scope = this.Scope.AssertNotNull());

            void OnArrangeGuidedLocalSolutionScope()
            {
                //// TODO: TBD: it was not the expected 2672, but it was pretty close, 2671...
                //// TODO: TBD: could even be a rouding issue?
                //scope.ExpectedTotalDistance = 2672;
                //was: scope.ExpectedTotalDistance = 2671;
                scope.AssertNotNull().ExpectedTotalDistance = 2659;

                scope.ExpectedPaths = Range <int[]>(
                    Range(0, 3, 276, 4, 5, 6, 8, 7, 9, 10, 11, 14, 12, 13, 23, 22, 24, 21
                          , 25, 26, 27, 28, 125, 126, 127, 20, 19, 130, 129, 128, 153, 154, 152
                          , 155, 151, 150, 177, 176, 175, 180, 161, 160, 174, 159, 158, 157, 156
                          , 118, 119, 120, 121, 122, 123, 124, 29, 30, 31, 32, 33, 34, 35, 36
                          , 37, 38, 39, 40, 41, 42, 59, 60, 58, 43, 44, 45, 46, 47, 48, 49
                          , 50, 51, 52, 53, 54, 55, 56, 57, 67, 68, 66, 69, 70, 71, 72, 73
                          , 75, 74, 76, 77, 78, 80, 81, 88, 79, 92, 93, 94, 95, 96, 97, 98
                          , 99, 100, 101, 102, 91, 90, 89, 108, 111, 87, 82, 83, 86, 112, 115
                          , 85, 84, 64, 65, 63, 62, 61, 117, 116, 114, 113, 110, 109, 107, 103
                          , 104, 105, 106, 173, 172, 171, 170, 169, 168, 167, 166, 165, 164, 163
                          , 162, 187, 188, 189, 190, 191, 192, 185, 186, 184, 183, 182, 181, 179
                          , 178, 149, 148, 138, 137, 136, 266, 267, 135, 134, 268, 269, 133, 132
                          , 131, 18, 17, 16, 15, 270, 271, 272, 273, 274, 275, 259, 258, 260, 261
                          , 262, 263, 264, 265, 139, 140, 147, 146, 141, 142, 145, 144, 198, 197
                          , 196, 193, 194, 195, 200, 201, 199, 143, 202, 203, 204, 205, 206, 207
                          , 252, 253, 256, 257, 255, 254, 251, 208, 209, 210, 211, 212, 213, 214
                          , 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 232
                          , 233, 234, 235, 236, 237, 230, 231, 228, 229, 250, 245, 238, 239, 240
                          , 241, 242, 243, 244, 246, 249, 248, 247, 277, 278, 2, 279, 1, 0).ToArray()
                    ).ToList();
            }

            $"Arrange {nameof(scope)} expectations".x(OnArrangeGuidedLocalSolutionScope);

            void OnConfigureSearchParameters(object sender, RoutingSearchParametersEventArgs e)
            {
                var e_params = e.Parameters.AssertNotNull();

                e_params.FirstSolutionStrategy    = FirstSolutionStrategy.PathCheapestArc;
                e_params.LocalSearchMetaheuristic = LocalSearchMetaheuristic.GuidedLocalSearch;
                e_params.TimeLimit = 30L.AsDuration();
                e_params.LogSearch = true;
            }

            void OnConfigureSearchParametersCallback()
            {
                this.Scope.ProblemSolver.ConfigureSearchParameters += OnConfigureSearchParameters;
            }

            void OnRollbackSearchParametersCallback()
            {
                this.Scope.ProblemSolver.ConfigureSearchParameters -= OnConfigureSearchParameters;
            }

            $"Configure search parameters callbacks".x(OnConfigureSearchParametersCallback)
            .Rollback(OnRollbackSearchParametersCallback);

            $"Solve routing problem given {nameof(scope)}.{nameof(scope.Context)}".x(
                () => scope.ProblemSolver.Solve(scope.Context)
                );
        }