コード例 #1
0
        // New LS to final solutions
        public static void cluVRPLocalSearchs(CluVRPSolution cluVRPSolution, CluVRPInstance instance, Parameters parameters)
        {
            // Perform LS at cluster level
            double oldTotalDistance = cluVRPSolution.totalCustomerRouteDistance;
            var    totalWatch       = System.Diagnostics.Stopwatch.StartNew();

            swapClusters(cluVRPSolution, instance, parameters);
            cluVRPSolution.cluvrp_swapClusters_time += totalWatch.ElapsedMilliseconds;

            totalWatch = System.Diagnostics.Stopwatch.StartNew();
            swapVehicle(cluVRPSolution, instance, parameters);
            cluVRPSolution.cluvrp_swapVehicle_time += totalWatch.ElapsedMilliseconds;

            // If some cluster position change make LS at customer level
            if (cluVRPSolution.totalCustomerRouteDistance < oldTotalDistance)
            {
                // Create a local search handler for cluster-level problem
                CustomerStrongLocalSearch customerLocalSearch = new CustomerStrongLocalSearch(cluVRPSolution,
                                                                                              instance,
                                                                                              parameters.Customer_LS_TwoOpt_Iterations,
                                                                                              parameters.Customer_LS_Relocate_Iterations,
                                                                                              parameters.Customer_LS_Exchange_Iterations,
                                                                                              parameters.Customer_LS_SwapCustomers
                                                                                              );

                // Perform one iteration of LS at customer level
                customerLocalSearch.twoOpt();
                customerLocalSearch.exchange();
                customerLocalSearch.relocate();
                customerLocalSearch.swapCustomers();
            }

            // End
            return;
        }
コード例 #2
0
        /*
         *
         * Applies a list of local searchs
         *
         */
        private void localSearch(CluVRPSolution newSolution)
        {
            // Create a local search handler for cluster-level problem
            CustomerStrongLocalSearch customerLocalSearch = new CustomerStrongLocalSearch(newSolution,
                                                                                          instance,
                                                                                          parameters.Customer_LS_TwoOpt_Iterations,
                                                                                          parameters.Customer_LS_Relocate_Iterations,
                                                                                          parameters.Customer_LS_Exchange_Iterations,
                                                                                          parameters.Customer_LS_SwapCustomers
                                                                                          );


            // If random order for local searchs is activated
            if (parameters.Customer_LS_Order.Length == 0)
            {
                Functions.Shuffle(new Random(), this.localSearchsOrder);
            }

            // Execute local search in the correct order
            for (int i = 0; i < localSearchsOrder.Count; i++)
            {
                // Perform TwoOpt
                if (localSearchsOrder[i] == LocalSearch.TwoOpt && parameters.Customer_LS_TwoOpt_Iterations != 0)
                {
                    var totalWatch = System.Diagnostics.Stopwatch.StartNew();
                    customerLocalSearch.twoOpt();
                    customerLocalSearch.solution.customer_twoOpt_time += totalWatch.ElapsedMilliseconds;
                }

                // Perform Relocate
                if (localSearchsOrder[i] == LocalSearch.Relocate && parameters.Customer_LS_Relocate_Iterations != 0)
                {
                    var totalWatch = System.Diagnostics.Stopwatch.StartNew();
                    customerLocalSearch.relocate();
                    customerLocalSearch.solution.customer_relocate_time += totalWatch.ElapsedMilliseconds;
                }

                // Perform Exchange
                if (localSearchsOrder[i] == LocalSearch.Exchange && parameters.Customer_LS_Exchange_Iterations != 0)
                {
                    var totalWatch = System.Diagnostics.Stopwatch.StartNew();
                    customerLocalSearch.exchange();
                    customerLocalSearch.solution.customer_exchange_time += totalWatch.ElapsedMilliseconds;
                }

                // Perform Customer Swap
                if (localSearchsOrder[i] == LocalSearch.SwapCustomers && parameters.Customer_LS_SwapCustomers != 0)
                {
                    var totalWatch = System.Diagnostics.Stopwatch.StartNew();
                    customerLocalSearch.swapCustomers();
                    customerLocalSearch.solution.customer_swapCustomers_time += totalWatch.ElapsedMilliseconds;
                }
            }
            // Set the solution
            newSolution = customerLocalSearch.solution;
        }