Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/29/11 15:51:56 (13 years ago)
Author:
svonolfe
Message:

Added support for multi depot CVRP instances (#1177)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/ExtendedPotvin
Files:
2 added
1 moved

Legend:

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

    r6838 r6851  
    3333using HeuristicLab.Problems.VehicleRouting.Variants;
    3434
    35 namespace HeuristicLab.Problems.VehicleRouting.Encodings.Potvin {
     35namespace HeuristicLab.Problems.VehicleRouting.Encodings.ExtendedPotvin {
    3636  [Item("IterativeInsertionCreator", "Creates a randomly initialized VRP solution.")]
    3737  [StorableClass]
    38   public sealed class IterativeInsertionCreator : PotvinCreator, IStochasticOperator {
     38  public sealed class IterativeInsertionCreator : ExtendedPotvinCreator, IStochasticOperator {
    3939    #region IStochasticOperator Members
    4040    public ILookupParameter<IRandom> RandomParameter {
     
    6565
    6666    private static double CalculateAngleToDepot(IVRPProblemInstance instance, int city) {
    67       double dx = instance.Coordinates[0, 0];
    68       double dy = instance.Coordinates[0, 1];
     67      double dx = instance.GetCoordinates(0)[0];
     68      double dy = instance.GetCoordinates(0)[1];
    6969
    70       double cx = instance.Coordinates[city, 0];
    71       double cy = instance.Coordinates[city, 1];
     70      double cx = instance.GetCoordinates(city)[0];
     71      double cy = instance.GetCoordinates(city)[1];
    7272
    7373      double alpha = Math.Atan((cx - dx) / (dy - cy)) * (180.0 / Math.PI);
     
    8282    }
    8383
    84     private static PotvinEncoding CreateSolution(IVRPProblemInstance instance, IRandom random, bool adhereTimeWindows) {
    85       PotvinEncoding result = new PotvinEncoding(instance);
     84    private static ExtendedPotvinEncoding CreateSolution(IVRPProblemInstance instance, IRandom random, bool adhereTimeWindows) {
     85      ExtendedPotvinEncoding result = new ExtendedPotvinEncoding(instance);
    8686
    8787      IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
     
    8989      List<int> customers = new List<int>();
    9090      for (int i = 1; i <= instance.Cities.Value; i++)
    91         if(pdp == null || pdp.Demand[i] >= 0)
     91        if(pdp == null || pdp.GetDemand(i) >= 0)
    9292          customers.Add(i);
    9393
     
    107107        int index = (i + j) % customers.Count;
    108108
    109         int stopIdx = result.FindBestInsertionPlace(currentTour, customers[index]);
     109        int stopIdx = 0;
     110        if(currentTour.Stops.Count > 0)
     111          result.FindBestInsertionPlace(currentTour, customers[index]);
    110112        currentTour.Stops.Insert(stopIdx, customers[index]);
    111113
     
    122124              currentTour.Stops.Remove(pdp.PickupDeliveryLocation[customers[index]]);
    123125
    124           if(currentTour.Stops.Count > 0)
    125             result.Tours.Add(currentTour);
     126          if (currentTour.Stops.Count == 0)
     127            result.Tours.Remove(currentTour);
    126128          currentTour = new Tour();
     129          result.Tours.Add(currentTour);
    127130         
    128131          currentTour.Stops.Add(customers[index]);
Note: See TracChangeset for help on using the changeset viewer.