public KeyValuePair<Solution, double> BestInsertionPlaceCzech2001(Solution solution, Customer customer, Route route) { // Route customerRoute = solution.Routes[customerRouteIndex]; // Customer customer = (Customer)customerRoute.RouteList[cusotomerIndex]; // Route targetRoute = solution.Routes[targetRouteIndex]; //int bestSolution = -1; double bestCost = solution.TotalDistance(); //solution.Routes[cusotomerIndex] = customerRoute.Copy(); //solution.Routes[cusotomerIndex].RouteList.RemoveAt(cusotomerIndex); var routeIndex = route.Index(); var newSolution = solution.Copy(); var oldRouteIdx = customer.Route.Index(); var oldRoute = newSolution.Routes[oldRouteIdx].Copy(); oldRoute.RemoveAt(customer.Index()); newSolution.Routes[oldRouteIdx] = oldRoute; Solution bestSolutionCopy = null; for (int i = 1; i < route.RouteList.Count; ++i) { var newRoute = solution.Routes[routeIndex].Copy(); newRoute.InsertCustomer(customer, i); newSolution.Routes[routeIndex] = newRoute; double newCost = newSolution.TotalDistance(); if (newRoute.IsFeasible() && newCost < bestCost) { bestSolutionCopy = newSolution.Copy(); bestCost = newCost; } } return new KeyValuePair<Solution, double>(bestSolutionCopy, bestCost); }
public List<Route> OrderRoutesWithProb(Solution solution, double prob) { var routes = solution.Copy().Routes; var rnd = new Random(); var dice = rnd.NextDouble(); if(dice > prob) return new List<Route>(routes); return routes.OrderBy(r => r.RouteList.Count).ToList(); }