Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/06/10 16:08:46 (14 years ago)
Author:
svonolfe
Message:

Refactored VRP, added some Potvin operators (WIP) (#1039)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/PotvinEncoding.cs

    r4150 r4174  
    3131  [Item("PotvinEncoding", "Represents a potvin encoding of VRP solutions.")]
    3232  [StorableClass]
    33   class PotvinEncoding : Item, IVRPEncoding {
     33  public class PotvinEncoding : Item, IVRPEncoding {
    3434    public override Image ItemImage {
    3535      get { return HeuristicLab.Common.Resources.VS2008ImageLibrary.Class; }
     
    4646
    4747        foreach (Tour tour in Tours) {
    48           cities += tour.Count;
     48          cities += tour.Cities.Count;
    4949        }
    5050
     
    5555
    5656    [Storable]
    57     public ItemList<IntValue> Unrouted { get; set; }
     57    public List<int> Unrouted { get; set; }
    5858
    5959    public override IDeepCloneable Clone(HeuristicLab.Common.Cloner cloner) {
     
    6161      cloner.RegisterClonedObject(this, clone);
    6262      clone.Tours = (ItemList<Tour>)cloner.Clone(this.Tours);
    63       clone.Unrouted = (ItemList<IntValue>)cloner.Clone(this.Unrouted);
     63      clone.Unrouted = new List<int>(Unrouted);
    6464      return clone;
    6565    }
     
    6767    public PotvinEncoding() {
    6868      Tours = new ItemList<Tour>();
    69       Unrouted = new ItemList<IntValue>();
     69      Unrouted = new List<int>();
    7070    }
    7171   
     
    8585      for (int i = 0; i < route.Count; i++) {
    8686        if (route[i] == 0) {
    87           if (tour.Count > 0) {
     87          if (tour.Cities.Count > 0) {
    8888            solution.Tours.Add(tour);
    8989            tour = new Tour();
    9090          }
    9191        } else {
    92           tour.Add(new IntValue(route[i]));
     92          tour.Cities.Add(route[i]);
    9393        }
    9494      }
     
    9696      return solution;
    9797    }
     98
     99    public bool FindInsertionPlace(
     100      DoubleArray dueTimeArray,
     101      DoubleArray serviceTimeArray, DoubleArray readyTimeArray, DoubleArray demandArray, DoubleValue capacity,
     102      DoubleMatrix coordinates, ILookupParameter<DoubleMatrix> distanceMatrix, BoolValue useDistanceMatrix,
     103      int city, int routeToAvoid, out int route, out int place) {
     104      route = -1;
     105      place = -1;
     106      double minDetour = 0;
     107
     108      for (int tour = 0; tour < Tours.Count; tour++) {
     109        if (tour != routeToAvoid) {
     110          for (int i = 0; i <= Tours[tour].Cities.Count; i++) {
     111            double length = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
     112
     113            Tours[tour].Cities.Insert(i, city);
     114
     115            if (Tours[tour].Feasible(dueTimeArray, serviceTimeArray, readyTimeArray, demandArray,
     116              capacity, coordinates, distanceMatrix, useDistanceMatrix)) {
     117              double newLength = Tours[tour].GetLength(coordinates, distanceMatrix, useDistanceMatrix);
     118
     119              double detour = newLength - length;
     120
     121              if (route <= 0 || detour < minDetour) {
     122                route = tour;
     123                place = i;
     124                minDetour = detour;
     125              }
     126            }
     127
     128            Tours[tour].Cities.RemoveAt(i);
     129          }
     130        }
     131      }
     132
     133      return route >= 0 && place >= 0;
     134    }
    98135  }
    99136}
Note: See TracChangeset for help on using the changeset viewer.