Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/20/10 11:43:31 (14 years ago)
Author:
svonolfe
Message:

Code cleanup (#1039)

Location:
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/GVR
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/GVR/GVREncoding.cs

    r4268 r4270  
    4040
    4141    public override List<Tour> GetTours(ILookupParameter<DoubleMatrix> distanceMatrix = null, int maxVehicles = int.MaxValue) {
    42       List<Tour> tours = new List<Tour>();
    43       Tour newTour = new Tour();
    44       double currentDemand = 0;
     42      List<Tour> tours = new List<Tour>();   
    4543
    46       int toursProcessed = 0;
    4744      foreach (Tour tour in base.Tours) {
    48         if (maxVehicles > tours.Count) {
    49           newTour = new Tour();
    50           currentDemand = 0;
    51         }
     45        Tour newTour = new Tour();
     46        double currentDemand = 0;
    5247
    5348        foreach (int city in tour.Cities) {
    5449          currentDemand += demand[city];
    5550
    56           if (maxVehicles > tours.Count &&
    57             currentDemand > capacity.Value) {
     51          if (currentDemand > capacity.Value) {
    5852            if(newTour.Cities.Count > 0)
    5953              tours.Add(newTour);
     
    6761        }
    6862
    69         if (newTour.Cities.Count > 0 &&
    70           maxVehicles > tours.Count)
     63        if (newTour.Cities.Count > 0)
    7164          tours.Add(newTour);
     65      }
    7266
    73         toursProcessed++;
    74       }
     67      //repair if there are too many vehicles used
     68      while (tours.Count > maxVehicles) {
     69        Tour tour = tours[tours.Count - 1];
     70        tours[tours.Count - 2].Cities.AddRange(tour.Cities);
     71
     72        tours.Remove(tour);
     73      }
    7574
    7675      return tours;
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/GVR/Manipulators/GVRInsertionManipulator.cs

    r4231 r4270  
    5555      } else {
    5656        Tour newTour = individual.Tours[random.Next(individual.Tours.Count)];
    57         int newPosition = newTour.Cities.Count;
     57        int newPosition = random.Next(newTour.Cities.Count + 1);
    5858
    5959        newTour.Cities.Insert(newPosition, customer);
Note: See TracChangeset for help on using the changeset viewer.