Exemple #1
0
 public double CriterionC11(int i, AbsNode u, int j, Route route)
 {
     var custI = route.RouteList[i];
     var custJ = route.RouteList[j];
     double distIu = custI.Distance(u);
     double distUj = u.Distance(custJ);
     double distJi = custJ.Distance(custI);
     return distIu + distUj + CoefMu*distJi;
 }
Exemple #2
0
 public double CriterionC12(int i, AbsNode u, int j, Route route)
 {
     var custI = route.RouteList[i];
     var custJ = route.RouteList[j];
     double bI = route.ServiceBeginingTimes[i];
     double bU = route.NextServiceBeginTime(u, custI, bI);
     double bJu = route.NextServiceBeginTime(custJ, u, bU);
     double bJ = route.ServiceBeginingTimes[j];
     return bJu - bJ;
 }
Exemple #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);
        }
Exemple #4
0
        public override Solution Solve(Problem problem, Solution initialSolution = null)
        {
            var solution = new Solution(problem);
            var unroutedCustomers = new List<Customer>(problem.Customers);
            int seedId = SelectSeedCustomer(unroutedCustomers, problem.Depot);
            Customer seed = unroutedCustomers[seedId];
            unroutedCustomers.RemoveAt(seedId);
            var partialRoute = new Route(problem, seed);

            while (unroutedCustomers.Count > 0)
            {
                Route newRoute = partialRoute.Copy();
                var bestU = new List<int>();
                var c1Vals = new List<double>();
                foreach (Customer cust in unroutedCustomers)
                {
                    double minC1 = double.MaxValue;
                    int optimalU = 1;
                    for (int i = 1; i < newRoute.RouteList.Count - 1; ++i)
                    {
                        double c1 = CriterionC1(i, cust, i + 1, newRoute);
                        if (c1 < minC1)
                        {
                            minC1 = c1;
                            optimalU = i;
                        }
                    }
                    bestU.Add(optimalU);
                    c1Vals.Add(minC1);
                }

                int bestCust = 0;
                double minC2 = double.MaxValue;
                for (int i = 0; i < unroutedCustomers.Count; ++i)
                {
                    double c2 = CriterionC2(unroutedCustomers[i], c1Vals[i], newRoute);
                    if (c2 < minC2)
                    {
                        minC2 = c2;
                        bestCust = i;
                    }
                }

                Customer newCustomer = unroutedCustomers[bestCust];
                newRoute.InsertCustomer(newCustomer, bestU[bestCust]);

                if (newRoute.IsFeasible())
                {
                    unroutedCustomers.RemoveAt(bestCust);
                    partialRoute = newRoute;
                }
                else
                {
                    solution.AddRoute(partialRoute);
                    seedId = SelectSeedCustomer(unroutedCustomers, problem.Depot);
                    seed = unroutedCustomers[seedId];
                    unroutedCustomers.RemoveAt(seedId);
                    partialRoute = new Route(problem, seed);
                }

                if (unroutedCustomers.Count == 0)
                    solution.AddRoute(partialRoute);
            }

            return solution;
        }
Exemple #5
0
 public double CriterionC2(AbsNode u, double c1Value, Route route)
 {
     double d0U = route.RouteList[0].Distance(u);
     return CoefLambda*d0U - c1Value;
 }
Exemple #6
0
 public double CriterionC1(int i, AbsNode u, int j, Route route)
 {
     return CoefAlpha1*CriterionC11(i, u, i, route) + CoefAlpha2*CriterionC12(i, u, j, route);
 }
Exemple #7
0
 public Route Copy()
 {
     var newRouteList = new List<AbsNode>(RouteList.Count);
     newRouteList.AddRange(RouteList.Select(node => node.ShallowCopy()));
     var r = new Route(Problem)
                 {
                     RouteList = newRouteList,
                     ServiceBeginingTimes = new List<double>(ServiceBeginingTimes)
                 };
     for (int i = 1; i < RouteList.Count - 1; ++i)
         ((Customer) r.RouteList[i]).Route = r;
     r.UpdateId();
     return r;
 }
Exemple #8
0
 public void AddRoute(Route route)
 {
     Route newRoute = route.Copy();
     newRoute.Solution = this;
     Routes.Add(newRoute);
 }
Exemple #9
0
 public Customer(NodeInfo info)
 {
     Info  = info;
     Route = null;
 }