Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/25/12 10:14:58 (12 years ago)
Author:
jkarder
Message:

#1331:

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs

    r8319 r8322  
    8585        int bestCityIndex = (i + 1) % v1.Length;
    8686        double currDistance = distances[v1[currCityIndex], v1[bestCityIndex]];
     87        // check each guiding solution
    8788        targets.ToList().ForEach(solution => {
    88           var node = solution.Select((x, index) => new { Id = x, Index = index }).First(x => x.Id == v1[currCityIndex]);
     89          // locate current city
     90          var node = solution.Select((x, index) => new { Id = x, Index = index }).Single(x => x.Id == v1[currCityIndex]);
    8991          int pred = solution[(node.Index - 1 + solution.Length) % solution.Length];
    9092          int succ = solution[(node.Index + 1) % solution.Length];
     93          // get distances to neighbors
    9194          var results = new[] { pred, succ }.Select(x => new { Id = x, Distance = distances[x, node.Id] });
    92           if (results.Any(x => x.Distance < currDistance)) {
    93             var bestCity = results.OrderBy(x => x.Distance).First();
    94             bestCityIndex = v1.Select((x, index) => new { Id = x, Index = index }).First(x => x.Id == bestCity.Id).Index;
     95          var bestCity = results.Where(x => x.Distance < currDistance).OrderBy(x => x.Distance).FirstOrDefault();
     96          if (bestCity != null) {
     97            bestCityIndex = v1.Select((x, index) => new { Id = x, Index = index }).Single(x => x.Id == bestCity.Id).Index;
    9598            currDistance = bestCity.Distance;
    9699          }
Note: See TracChangeset for help on using the changeset viewer.