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/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.