- Timestamp:
- 05/14/12 15:46:27 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/PathRelinkers/VRPPathRelinker.cs
r7793 r7806 21 21 22 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 23 25 using HeuristicLab.Common; 24 26 using HeuristicLab.Core; … … 26 28 using HeuristicLab.Optimization.Operators; 27 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.VehicleRouting.Encodings; 31 using HeuristicLab.Problems.VehicleRouting.Encodings.Potvin; 28 32 29 33 namespace HeuristicLab.Problems.VehicleRouting { … … 44 48 45 49 public static ItemArray<IItem> Apply(IItem initiator, IItem guide, PercentValue n) { 46 // TODO: path relinking 47 return new ItemArray<IItem>(); 50 PotvinEncoding sol1 = initiator.Clone() as PotvinEncoding; 51 PotvinEncoding sol2 = guide.Clone() as PotvinEncoding; 52 PotvinEncoding sol3 = new PotvinEncoding(); 53 54 // match tours 55 foreach (Tour tour1 in sol1.Tours) { 56 int highestMatch = -1; 57 Tour bestMatchingTour = null; 58 foreach (Tour tour2 in sol2.Tours) { 59 int matchingCities = MatchingCities(tour1, tour2); 60 if (matchingCities > highestMatch) { 61 bestMatchingTour = tour2; 62 highestMatch = matchingCities; 63 } 64 } 65 sol2.Tours.Remove(bestMatchingTour); 66 sol3.Tours.Add(bestMatchingTour); 67 } 68 // add all remaining tours 69 sol3.Tours.AddRange(sol2.Tours); 70 71 IList<PotvinEncoding> solutions = new List<PotvinEncoding>(); 72 // TODO: add local search 73 74 IList<IItem> selection = new List<IItem>(); 75 if (solutions.Count > 0) { 76 int noSol = (int)(solutions.Count * n.Value); 77 if (noSol <= 0) noSol++; 78 double stepSize = (double)solutions.Count / (double)noSol; 79 for (int i = 0; i < noSol; i++) 80 selection.Add(solutions.ElementAt((int)((i + 1) * stepSize - stepSize * 0.5))); 81 } 82 83 return new ItemArray<IItem>(selection); 84 } 85 86 private static int MatchingCities(Tour tour1, Tour tour2) { 87 return tour1.Cities.Intersect(tour2.Cities).Count(); 48 88 } 49 89
Note: See TracChangeset
for help on using the changeset viewer.