Changeset 17698 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/PathRelinkers
- Timestamp:
- 07/24/20 00:58:42 (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.VehicleRouting/3.4/PathRelinkers/VRPPathRelinker.cs
r17226 r17698 72 72 } 73 73 74 public static ItemArray<IItem> Apply(PotvinEncod ing initiator, PotvinEncodingguide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) {74 public static ItemArray<IItem> Apply(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, PercentValue n, int sampleSize, int iterations, IRandom rand, IVRPProblemInstance problemInstance) { 75 75 if (initiator == null || guide == null) 76 76 throw new ArgumentException("Cannot relink path because one of the provided solutions or both are null."); … … 87 87 originalTardinessPenalty.Value = (problemInstance as ITimeWindowedProblemInstance).TardinessPenalty.Value; 88 88 89 PotvinEncod ingcurrent = MatchTours(initiator, guide, problemInstance);89 PotvinEncodedSolution current = MatchTours(initiator, guide, problemInstance); 90 90 double currentSimilarity = VRPSimilarityCalculator.CalculateSimilarity(current, guide); 91 91 92 IList<PotvinEncod ing> solutions = new List<PotvinEncoding>();92 IList<PotvinEncodedSolution> solutions = new List<PotvinEncodedSolution>(); 93 93 int i = 0; 94 94 while (i < iterations && !currentSimilarity.IsAlmost(1.0)) { … … 98 98 if (currentSimilarity < 1.0) { 99 99 for (int sample = 0; sample < sampleSize; sample++) { 100 var next = current.Clone() as PotvinEncod ing;100 var next = current.Clone() as PotvinEncodedSolution; 101 101 102 102 int neighborhood = rand.Next(3); … … 159 159 } 160 160 161 private static IList<IItem> ChooseSelection(IList<PotvinEncod ing> solutions, PercentValue n) {161 private static IList<IItem> ChooseSelection(IList<PotvinEncodedSolution> solutions, PercentValue n) { 162 162 IList<IItem> selection = new List<IItem>(); 163 163 if (solutions.Count > 0) { … … 176 176 throw new ArgumentException("The number of parents is not equal to 2."); 177 177 178 if (!(parents[0] is PotvinEncod ing))179 parents[0] = PotvinEncod ing.ConvertFrom(parents[0] as IVRPEncoding, ProblemInstanceParameter.ActualValue);180 if (!(parents[1] is PotvinEncod ing))181 parents[1] = PotvinEncod ing.ConvertFrom(parents[1] as IVRPEncoding, ProblemInstanceParameter.ActualValue);182 183 return Apply(parents[0] as PotvinEncod ing, parents[1] as PotvinEncoding, n,178 if (!(parents[0] is PotvinEncodedSolution)) 179 parents[0] = PotvinEncodedSolution.ConvertFrom(parents[0] as IVRPEncodedSolution, ProblemInstanceParameter.ActualValue); 180 if (!(parents[1] is PotvinEncodedSolution)) 181 parents[1] = PotvinEncodedSolution.ConvertFrom(parents[1] as IVRPEncodedSolution, ProblemInstanceParameter.ActualValue); 182 183 return Apply(parents[0] as PotvinEncodedSolution, parents[1] as PotvinEncodedSolution, n, 184 184 SampleSizeParameter.Value.Value, IterationsParameter.Value.Value, RandomParameter.ActualValue, ProblemInstanceParameter.ActualValue); 185 185 } … … 189 189 } 190 190 191 private static PotvinEncod ing MatchTours(PotvinEncoding initiator, PotvinEncodingguide, IVRPProblemInstance problemInstance) {192 var result = new PotvinEncod ing(problemInstance);191 private static PotvinEncodedSolution MatchTours(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IVRPProblemInstance problemInstance) { 192 var result = new PotvinEncodedSolution(problemInstance); 193 193 194 194 var used = new List<bool>(); … … 226 226 227 227 #region moves 228 public static PotvinEncod ing RouteBasedXOver(PotvinEncoding initiator, PotvinEncodingguide, IRandom random, IVRPProblemInstance problemInstance) {228 public static PotvinEncodedSolution RouteBasedXOver(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IRandom random, IVRPProblemInstance problemInstance) { 229 229 return PotvinRouteBasedCrossover.Apply(random, initiator, guide, problemInstance, false); 230 230 } 231 231 232 public static PotvinEncod ing SequenceBasedXOver(PotvinEncoding initiator, PotvinEncodingguide, IRandom random, IVRPProblemInstance problemInstance) {232 public static PotvinEncodedSolution SequenceBasedXOver(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IRandom random, IVRPProblemInstance problemInstance) { 233 233 return PotvinSequenceBasedCrossover.Apply(random, initiator, guide, problemInstance, false); 234 234 } 235 235 236 public static void GuidedRelocateMove(PotvinEncod ing initiator, PotvinEncodingguide, IRandom random) {236 public static void GuidedRelocateMove(PotvinEncodedSolution initiator, PotvinEncodedSolution guide, IRandom random) { 237 237 List<int> cities = new List<int>(); 238 238 foreach (Tour tour in initiator.Tours) { … … 291 291 } 292 292 293 public static void RelocateMove(PotvinEncod ingindividual, IRandom random) {293 public static void RelocateMove(PotvinEncodedSolution individual, IRandom random) { 294 294 int cities = individual.Cities; 295 295 int city = 1 + random.Next(cities);
Note: See TracChangeset
for help on using the changeset viewer.