Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/03/11 16:18:37 (14 years ago)
Author:
svonolfe
Message:

Fixed some Problems with the Alba Encoding (#1177)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Alba/Moves/LambdaInterchange/AlbaStochasticLambdaInterchangeSingleMoveGenerator.cs

    r4752 r5201  
    6767      List<Tour> tours = individual.GetTours();
    6868
    69       int route1Index = rand.Next(tours.Count);
    70       Tour route1 = tours[route1Index];
     69      if (tours.Count > 1) {
     70        int route1Index = rand.Next(tours.Count);
     71        Tour route1 = tours[route1Index];
    7172
    72       int route2Index = rand.Next(tours.Count - 1);
    73       if (route2Index >= route1Index)
    74         route2Index += 1;
    75       Tour route2 = tours[route2Index];
     73        int route2Index = rand.Next(tours.Count - 1);
     74        if (route2Index >= route1Index)
     75          route2Index += 1;
    7676
    77       int length1 = rand.Next(Math.Min(lambda + 1, route1.Stops.Count + 1));
    78       int index1 = rand.Next(route1.Stops.Count - length1 + 1);
     77        Tour route2 = tours[route2Index];
    7978
    80       int l2Min = 0;
    81       if (length1 == 0)
    82         l2Min = 1;
    83       int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Stops.Count + 1));
    84       int index2 = rand.Next(route2.Stops.Count - length2 + 1);
     79        int length1 = rand.Next(Math.Min(lambda + 1, route1.Stops.Count + 1));
     80        int index1 = rand.Next(route1.Stops.Count - length1 + 1);
    8581
    86       return new AlbaLambdaInterchangeMove(route1Index, index1, length1, route2Index, index2, length2, individual);
     82        int l2Min = 0;
     83        if (length1 == 0)
     84          l2Min = 1;
     85        int length2 = rand.Next(l2Min, Math.Min(lambda + 1, route2.Stops.Count + 1));
     86        int index2 = rand.Next(route2.Stops.Count - length2 + 1);
     87
     88        return new AlbaLambdaInterchangeMove(route1Index, index1, length1, route2Index, index2, length2, individual);
     89      } else {
     90        return new AlbaLambdaInterchangeMove(0, 0, 0, 0, 0, 0, individual);
     91      }
    8792    }
    8893
Note: See TracChangeset for help on using the changeset viewer.