Changeset 9836 for branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape.VRP/Manipulators/OrOptManipulator.cs
- Timestamp:
- 08/01/13 13:55:01 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/FitnessLandscapeAnalysis/HeuristicLab.Analysis.FitnessLandscape.VRP/Manipulators/OrOptManipulator.cs
r9750 r9836 30 30 using HeuristicLab.Problems.VehicleRouting; 31 31 using System; 32 using HeuristicLab.Problems.VehicleRouting.Interfaces; 32 33 33 34 namespace HeuristicLab.Analysis.FitnessLandscape.VRP { … … 47 48 } 48 49 49 public static void Apply(IRandom random, PotvinEncoding individual ) {50 public static void Apply(IRandom random, PotvinEncoding individual, IVRPProblemInstance instance, bool allowInfeasible) { 50 51 List<Tour> tours = individual.Tours.FindAll(t => t.Stops.Count >= 2); 52 if (tours.Count == 0) return; 53 bool feasible; 54 int count = 0; 51 55 52 if (tours.Count > 0) { 56 do { 57 feasible = true; 53 58 int tourIdx = random.Next(tours.Count); 54 59 Tour tour = tours[tourIdx]; … … 58 63 if (segmentStart == 0) { 59 64 segmentLength = 1 + random.Next(tour.Stops.Count - 1); 60 } else { 65 } 66 else { 61 67 segmentLength = 1 + random.Next(tour.Stops.Count - segmentStart); 62 68 } 69 70 bool originalFeasible = instance.TourFeasible(tour, individual); 63 71 64 72 List<int> segment = tour.Stops.GetRange(segmentStart, segmentLength); … … 73 81 newPos++; 74 82 tour.Stops.InsertRange(newPos, segment); 75 } 83 84 if (!allowInfeasible && originalFeasible) { 85 feasible = instance.TourFeasible(tour, individual); 86 if (!feasible) { 87 tour.Stops.RemoveRange(newPos, segment.Count); 88 tour.Stops.InsertRange(segmentStart, segment); 89 } 90 } 91 } while (!feasible && count++ < 100); 76 92 } 77 93 78 94 protected override void Manipulate(IRandom random, PotvinEncoding individual) { 79 Apply(random, individual); 95 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 96 Apply(random, individual, ProblemInstance, allowInfeasible); 80 97 } 81 98 }
Note: See TracChangeset
for help on using the changeset viewer.