Free cookie consent management tool by TermsFeed Policy Generator

Changeset 5368


Ignore:
Timestamp:
01/25/11 09:46:11 (14 years ago)
Author:
svonolfe
Message:

Fixed some minor issues in the VRP operators (#1177)

Location:
trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeSingleMoveGenerator.cs

    r4722 r5368  
    6363      List<Tour> tours = individual.GetTours();
    6464
    65       int route1Index = rand.Next(tours.Count);
    66       Tour route1 = tours[route1Index];
     65      if (tours.Count > 1) {
     66        int route1Index = rand.Next(tours.Count);
     67        Tour route1 = tours[route1Index];
    6768
    68       int route2Index = rand.Next(tours.Count - 1);
    69       if (route2Index >= route1Index)
    70         route2Index += 1;
    71       Tour route2 = tours[route2Index];
     69        int route2Index = rand.Next(tours.Count - 1);
     70        if (route2Index >= route1Index)
     71          route2Index += 1;
     72        Tour route2 = tours[route2Index];
    7273
    73       int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1));
    74       int index1 = rand.Next(route1.Cities.Count - length1 + 1);
     74        int length1 = rand.Next(Math.Min(lambda + 1, route1.Cities.Count + 1));
     75        int index1 = rand.Next(route1.Cities.Count - length1 + 1);
    7576
    76       int l2Min = 0;
    77       if (length1 == 0)
    78         l2Min = 1;
    79       int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Cities.Count + 1));
    80       int index2 = rand.Next(route2.Cities.Count - length2 + 1);
     77        int l2Min = 0;
     78        if (length1 == 0)
     79          l2Min = 1;
     80        int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Cities.Count + 1));
     81        int index2 = rand.Next(route2.Cities.Count - length2 + 1);
    8182
    82       return new AlbaLambdaInterchangeMove(route1Index, index1, length1, route2Index, index2, length2, individual);
     83        return new AlbaLambdaInterchangeMove(route1Index, index1, length1, route2Index, index2, length2, individual);
     84      } else {
     85        return new AlbaLambdaInterchangeMove(0, 0, 0, 0, 0, 0, individual);
     86      }
    8387    }
    8488
  • trunk/sources/HeuristicLab.Problems.VehicleRouting/3.3/Encodings/Potvin/Manipulators/PotvinTwoLevelExchangeManipulator.cs

    r4722 r5368  
    3838    protected override void Manipulate(IRandom random, PotvinEncoding individual) {
    3939      int selectedIndex = SelectRandomTourBiasedByLength(random, individual);
    40       Tour route1 =
    41         individual.Tours[selectedIndex];
     40      Tour route1 = individual.Tours[selectedIndex];
    4241
    43       for (int customer1Position = 0; customer1Position < route1.Cities.Count; customer1Position++) {
     42      bool performed = false;
     43      int customer1Position = 0;
     44      while (customer1Position < route1.Cities.Count) {
     45        performed = false;
     46
    4447        foreach (Tour tour in individual.Tours) {
    4548          if (tour != route1) {
     
    5154              tour.Cities[customer2Position] = customer1;
    5255              if (Feasible(tour)) {
    53                 int route, place;
     56                int routeIdx, place;
    5457                if (FindInsertionPlace(individual,
    55                   customer2, selectedIndex, out route, out place)) {
    56                   individual.Tours[route].Cities.Insert(place, customer2);
    57                   route1.Cities.RemoveAt(customer1Position);
     58                  customer2, selectedIndex, out routeIdx, out place)) {
     59                    individual.Tours[routeIdx].Cities.Insert(place, customer2);
     60                    route1.Cities.RemoveAt(customer1Position);
    5861
    59                   if (route1.Cities.Count == 0)
     62                    if (route1.Cities.Count == 0)
    6063                    individual.Tours.Remove(route1);
    6164
    6265                  //two-level exchange has been performed
    63                   return;
     66                  performed = true;
     67                  break;
    6468                } else {
    6569                  tour.Cities[customer2Position] = customer2;
     
    7074            }
    7175          }
     76
     77          if (performed)
     78            break;
    7279        }
     80
     81        if (!performed)
     82          customer1Position++;
    7383      }
    7484    }
Note: See TracChangeset for help on using the changeset viewer.