Changeset 6607 for branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers
- Timestamp:
- 07/28/11 14:16:21 (13 years ago)
- Location:
- branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinCrossover.cs
r4752 r6607 39 39 } 40 40 41 public IValueParameter<BoolValue> AllowInfeasibleSolutions { 42 get { return (IValueParameter<BoolValue>)Parameters["AllowInfeasibleSolutions"]; } 43 } 44 41 45 [StorableConstructor] 42 46 protected PotvinCrossover(bool deserializing) : base(deserializing) { } … … 44 48 public PotvinCrossover() { 45 49 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic manipulation operators.")); 50 Parameters.Add(new ValueParameter<BoolValue>("AllowInfeasibleSolutions", "Indicates if infeasible solutions should be allowed.", new BoolValue(false))); 46 51 } 47 52 … … 52 57 protected abstract PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2); 53 58 54 protected bool FindInsertionPlace(PotvinEncoding individual, int city, out int route, out int place) { 59 protected static bool FindInsertionPlace(PotvinEncoding individual, int city, bool allowInfeasible, 60 out int route, out int place) { 55 61 return individual.FindInsertionPlace( 56 city, -1, out route, out place); 62 city, -1, allowInfeasible, 63 out route, out place); 57 64 } 58 65 … … 70 77 } 71 78 72 protected bool Repair(IRandom random, PotvinEncoding solution, Tour newTour) {79 protected static bool RouteUnrouted(PotvinEncoding solution, bool allowInfeasible) { 73 80 bool success = true; 74 81 int index = 0; 82 while (index < solution.Unrouted.Count && success) { 83 int unrouted = solution.Unrouted[index]; 84 85 int route, place; 86 if (FindInsertionPlace(solution, unrouted, allowInfeasible, 87 out route, out place)) { 88 solution.Tours[route].Stops.Insert(place, unrouted); 89 } else { 90 success = false; 91 } 92 93 index++; 94 } 95 96 for (int i = 0; i < index; i++) 97 solution.Unrouted.RemoveAt(0); 98 99 return success; 100 } 101 102 protected static bool Repair(IRandom random, PotvinEncoding solution, Tour newTour, IVRPProblemInstance instance, bool allowInfeasible) { 103 bool success = true; 104 75 105 //remove duplicates from new tour 76 106 for (int i = 0; i < newTour.Stops.Count; i++) { … … 106 136 } 107 137 138 if (!allowInfeasible && !instance.Feasible(newTour)) 139 return false; 140 108 141 //route unrouted vehicles 109 int index = 0; 110 while (index < solution.Unrouted.Count && success) { 111 int unrouted = solution.Unrouted[index]; 112 113 int route, place; 114 if(FindInsertionPlace(solution, unrouted, out route, out place)) { 115 solution.Tours[route].Stops.Insert(place, unrouted); 116 } else { 117 success = false; 118 } 119 120 index++; 121 } 122 123 for (int i = 0; i < index; i++) 124 solution.Unrouted.RemoveAt(0); 142 success = RouteUnrouted(solution, allowInfeasible); 125 143 126 144 return success; -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinRouteBasedCrossover.cs
r4752 r6607 46 46 47 47 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 48 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 49 48 50 PotvinEncoding child = parent2.Clone() as PotvinEncoding; 49 51 … … 61 63 child.Unrouted.Add(city); 62 64 63 if (Repair(random, child, replacing ))65 if (Repair(random, child, replacing, ProblemInstance, allowInfeasible) || allowInfeasible) 64 66 return child; 65 67 else { -
branches/VRP/HeuristicLab.Problems.VehicleRouting/3.4/Encodings/Potvin/Crossovers/PotvinSequenceBasedCrossover.cs
r4752 r6607 46 46 47 47 protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) { 48 bool allowInfeasible = AllowInfeasibleSolutions.Value.Value; 49 48 50 PotvinEncoding child = parent1.Clone() as PotvinEncoding; 49 51 Tour newTour = new Tour(); … … 76 78 child.Unrouted.Add(city); 77 79 78 if (ProblemInstance.Feasible(newTour) && 79 Repair(random, child, newTour)) { 80 if (Repair(random, child, newTour, ProblemInstance, allowInfeasible) || allowInfeasible) { 80 81 return child; 81 82 } else {
Note: See TracChangeset
for help on using the changeset viewer.