Changeset 8322 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs
- Timestamp:
- 07/25/12 10:14:58 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs
r8319 r8322 85 85 int bestCityIndex = (i + 1) % v1.Length; 86 86 double currDistance = distances[v1[currCityIndex], v1[bestCityIndex]]; 87 // check each guiding solution 87 88 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]); 89 91 int pred = solution[(node.Index - 1 + solution.Length) % solution.Length]; 90 92 int succ = solution[(node.Index + 1) % solution.Length]; 93 // get distances to neighbors 91 94 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; 95 98 currDistance = bestCity.Distance; 96 99 }
Note: See TracChangeset
for help on using the changeset viewer.