Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/30/11 15:23:48 (13 years ago)
Author:
svonolfe
Message:

Added vehicle assignment manipulator and move for multi depot instances (#1177)

File:
1 copied

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/IterativeInsertionCreator.cs

    r6753 r6857  
    3131using HeuristicLab.Problems.VehicleRouting.Interfaces;
    3232using HeuristicLab.Problems.VehicleRouting.ProblemInstances;
     33using HeuristicLab.Problems.VehicleRouting.Variants;
    3334
    3435namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     
    6465
    6566    private static double CalculateAngleToDepot(IVRPProblemInstance instance, int city) {
    66       double dx = instance.Coordinates[0, 0];
    67       double dy = instance.Coordinates[0, 1];
     67      double dx = instance.GetCoordinates(0)[0];
     68      double dy = instance.GetCoordinates(0)[1];
    6869
    69       double cx = instance.Coordinates[city, 0];
    70       double cy = instance.Coordinates[city, 1];
     70      double cx = instance.GetCoordinates(city)[0];
     71      double cy = instance.GetCoordinates(city)[1];
    7172
    7273      double alpha = Math.Atan((cx - dx) / (dy - cy)) * (180.0 / Math.PI);
     
    8485      PotvinEncoding result = new PotvinEncoding(instance);
    8586
     87      IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     88
    8689      List<int> customers = new List<int>();
    87       for (int i = 0; i < instance.Cities.Value; i++)
    88         customers.Add(i + 1);
     90      for (int i = 1; i <= instance.Cities.Value; i++)
     91        if(pdp == null || pdp.GetDemand(i) >= 0)
     92          customers.Add(i);
     93
    8994      customers.Sort(delegate(int city1, int city2)
    9095          {
     
    96101
    97102      Tour currentTour = new Tour();
     103      result.Tours.Add(currentTour);
    98104
    99105      int j = random.Next(customers.Count);
     
    101107        int index = (i + j) % customers.Count;
    102108
    103         int stopIdx = result.FindBestInsertionPlace(currentTour, customers[index]);
     109        int stopIdx = 0;
     110        if(currentTour.Stops.Count > 0)
     111          result.FindBestInsertionPlace(currentTour, customers[index]);
    104112        currentTour.Stops.Insert(stopIdx, customers[index]);
    105113
    106         CVRPEvaluation evaluation = instance.Evaluate(currentTour) as CVRPEvaluation;
     114        if (pdp != null) {
     115          stopIdx = result.FindBestInsertionPlace(currentTour, pdp.GetPickupDeliveryLocation(customers[index]));
     116          currentTour.Stops.Insert(stopIdx, pdp.GetPickupDeliveryLocation(customers[index]));
     117        }
     118
     119        CVRPEvaluation evaluation = instance.EvaluateTour(currentTour, result) as CVRPEvaluation;
    107120        if (result.Tours.Count < instance.Vehicles.Value &&
    108121          ((adhereTimeWindows && !instance.Feasible(evaluation)) || ((!adhereTimeWindows) && evaluation.Overload > double.Epsilon))) {
    109           currentTour.Stops.RemoveAt(stopIdx);
     122            currentTour.Stops.Remove(customers[index]);
     123            if (pdp != null)
     124              currentTour.Stops.Remove(pdp.GetPickupDeliveryLocation(customers[index]));
    110125
    111           if(currentTour.Stops.Count > 0)
    112             result.Tours.Add(currentTour);
     126          if (currentTour.Stops.Count == 0)
     127            result.Tours.Remove(currentTour);
    113128          currentTour = new Tour();
     129          result.Tours.Add(currentTour);
    114130         
    115131          currentTour.Stops.Add(customers[index]);
     132          if (pdp != null) {
     133            currentTour.Stops.Add(pdp.GetPickupDeliveryLocation(customers[index]));
     134          }
    116135        }
    117136      }
    118137
    119       if (currentTour.Stops.Count > 0)
    120         result.Tours.Add(currentTour);
     138      if (currentTour.Stops.Count == 0)
     139        result.Tours.Remove(currentTour);
    121140
    122141      return result;
Note: See TracChangeset for help on using the changeset viewer.