Inheritance: AbsNode
Ejemplo n.º 1
0
        public List<Customer> NeighbourhoodIrmSearch(List<Customer> customerList, Customer customer)
        {
            var custDist = new List<KeyValuePair<Customer, double>>();
            foreach (Customer cust in customerList)
                custDist.Add(new KeyValuePair<Customer, double>(cust, customer.Distance(cust)));
            custDist = new List<KeyValuePair<Customer, double>>(custDist.OrderBy(p => p.Value));
            double r = custDist[1].Value;
            var rnd = new Random();
            var selectedCustomers = new Dictionary<int, Customer>();

            for (int i = 0; i < IrmIterations; ++i)
            {
                double prob = 1/r;
                foreach (var cust in custDist)
                {
                    if (cust.Value > r) break;

                    double dice = rnd.NextDouble();
                    if (dice < prob)
                        if (! selectedCustomers.ContainsKey(cust.Key.Info.Id))
                            selectedCustomers.Add(cust.Key.Info.Id, cust.Key);
                }
                r *= IrmCoefA;
            }
            var neighbourhood = new List<Customer>(selectedCustomers.Values);
            return neighbourhood;
        }
Ejemplo n.º 2
0
 public Route(Problem problem, Customer seedCustomer)
 {
     Depot depot = problem.Depot;
     Problem = problem;
     Solution = null;
     RouteList = new List<AbsNode>();
     ServiceBeginingTimes = new List<double>();
     AddNode(depot);
     AddNode(seedCustomer);
     AddNode(depot);
 }
Ejemplo n.º 3
0
        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);
        }
Ejemplo n.º 4
0
 public void AddCustomer(Customer newCustomer)
 {
     newCustomer = (Customer) newCustomer.ShallowCopy();
     newCustomer.Route = this;
     AddNode(newCustomer);
 }
Ejemplo n.º 5
0
 public void InsertCustomer(Customer newCustomer, int position)
 {
     newCustomer = (Customer) newCustomer.ShallowCopy();
     newCustomer.Route = this;
     RouteList.Insert(position, newCustomer);
     ServiceBeginingTimes.Insert(position, 0.0);
     for (int i = position; i < RouteList.Count; ++i)
     {
         double newTime = NextServiceBeginTime(RouteList[i], RouteList[i - 1], ServiceBeginingTimes[i - 1]);
         ServiceBeginingTimes[i] = newTime;
     }
     UpdateId();
 }