Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 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
Note: See TracChangeset for help on using the changeset viewer.