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)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators
Files:
2 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;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Creators/PushForwardInsertionCreator.cs

    r6856 r6857  
    3333using HeuristicLab.Problems.VehicleRouting.Variants;
    3434
    35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin {
     35namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
    3636  [Item("PushForwardInsertionCreator", "Creates a randomly initialized VRP solution.")]
    3737  [StorableClass]
    38   public sealed class PushForwardInsertionCreator : ExtendedPotvinCreator, IStochasticOperator {
     38  public sealed class PushForwardInsertionCreator : PotvinCreator, IStochasticOperator {
    3939    #region IStochasticOperator Members
    4040    public ILookupParameter<IRandom> RandomParameter {
     
    116116    }
    117117
    118     private static ExtendedPotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random,
     118    private static PotvinEncoding CreateSolution(IVRPProblemInstance problemInstance, IRandom random,
    119119      double alphaValue = 0.7, double betaValue = 0.1, double gammaValue = 0.2,
    120120      double alphaVariance = 0.5, double betaVariance = 0.07, double gammaVariance = 0.14) {
    121       ExtendedPotvinEncoding result = new ExtendedPotvinEncoding(problemInstance);
     121      PotvinEncoding result = new PotvinEncoding(problemInstance);
    122122
    123123      double alpha, beta, gamma;
Note: See TracChangeset for help on using the changeset viewer.