本文整理汇总了C#中HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# PotvinEncoding.Clone方法的具体用法?C# PotvinEncoding.Clone怎么用?C# PotvinEncoding.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HeuristicLab.Problems.VehicleRouting.Encodings.Potvin.PotvinEncoding
的用法示例。
在下文中一共展示了PotvinEncoding.Clone方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: PotvinCustomerRelocationMove
public PotvinCustomerRelocationMove(int city, int oldTour, int tour, PotvinEncoding individual) {
City = city;
OldTour = oldTour;
Tour = tour;
this.Individual = individual.Clone() as PotvinEncoding;
}
示例2: PotvinPDShiftMove
public PotvinPDShiftMove(int city, int oldTour, int tour, PotvinEncoding individual) {
City = city;
OldTour = oldTour;
Tour = tour;
this.Individual = individual.Clone() as PotvinEncoding;
}
示例3: PotvinTwoOptStarMove
public PotvinTwoOptStarMove(int tour1, int x1, int tour2, int x2, PotvinEncoding individual) {
Tour1 = tour1;
X1 = x1;
Tour2 = tour2;
X2 = x2;
this.Individual = individual.Clone() as PotvinEncoding;
}
示例4: PotvinPDExchangeMove
public PotvinPDExchangeMove(int city, int oldTour, int tour, int replaced, PotvinEncoding individual) {
City = city;
OldTour = oldTour;
Tour = tour;
Replaced = replaced;
this.Individual = individual.Clone() as PotvinEncoding;
}
示例5: Apply
public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, IVRPProblemInstance problemInstance, bool allowInfeasible) {
PotvinEncoding child = parent1.Clone() as PotvinEncoding;
Tour newTour = new Tour();
int cities = problemInstance.Cities.Value;
if (cities > 0) {
int breakPoint1 = random.Next(1, cities + 1);
Tour tour1 = FindRoute(child, breakPoint1);
breakPoint1 = tour1.Stops.IndexOf(breakPoint1);
for (int i = 0; i < breakPoint1; i++)
newTour.Stops.Add(tour1.Stops[i]);
int breakPoint2 = random.Next(1, cities + 1);
Tour tour2 = FindRoute(parent2, breakPoint2);
breakPoint2 = tour2.Stops.IndexOf(breakPoint2);
for (int i = breakPoint2; i < tour2.Stops.Count; i++)
newTour.Stops.Add(tour2.Stops[i]);
int tour1Index = child.Tours.IndexOf(tour1);
child.Tours.Remove(tour1);
child.Tours.Insert(tour1Index, newTour);
foreach (int city in tour1.Stops)
if (FindRoute(child, city) == null && !child.Unrouted.Contains(city))
child.Unrouted.Add(city);
foreach (int city in tour2.Stops)
if (FindRoute(child, city) == null && !child.Unrouted.Contains(city))
child.Unrouted.Add(city);
if (Repair(random, child, newTour, problemInstance, allowInfeasible) || allowInfeasible) {
return child;
} else {
if (random.NextDouble() < 0.5)
return parent1.Clone() as PotvinEncoding;
else
return parent2.Clone() as PotvinEncoding;
}
} else {
return child;
}
}
示例6: Apply
public static PotvinEncoding Apply(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2, IVRPProblemInstance problemInstance, bool allowInfeasible) {
PotvinEncoding child = parent2.Clone() as PotvinEncoding;
if (parent1.Tours.Count > 0 && child.Tours.Count > 0) {
int tourParent1 = random.Next(parent1.Tours.Count);
Tour replacing = parent1.Tours[tourParent1].Clone() as Tour;
int tourParent2 = random.Next(child.Tours.Count);
Tour replaced = child.Tours[tourParent2];
child.Tours.Remove(replaced);
child.Tours.Insert(tourParent2, replacing);
Permutation vehicleAssignment = child.VehicleAssignment;
int vehicle = vehicleAssignment[tourParent2];
int vehicle2 = parent1.VehicleAssignment[tourParent1];
vehicleAssignment[tourParent2] = vehicle2;
for (int i = 0; i < vehicleAssignment.Length; i++) {
if (vehicleAssignment[i] == vehicle2 && i != tourParent2) {
vehicleAssignment[i] = vehicle;
break;
}
}
foreach (int city in replaced.Stops)
if (FindRoute(child, city) == null && !child.Unrouted.Contains(city))
child.Unrouted.Add(city);
if (Repair(random, child, replacing, problemInstance, allowInfeasible) || allowInfeasible)
return child;
else {
if (random.NextDouble() < 0.5)
return parent1.Clone() as PotvinEncoding;
else
return parent2.Clone() as PotvinEncoding;
}
} else {
return child;
}
}
示例7: Crossover
protected override PotvinEncoding Crossover(IRandom random, PotvinEncoding parent1, PotvinEncoding parent2) {
PotvinEncoding child = parent1.Clone() as PotvinEncoding;
child.Tours.Clear();
bool allowInfeasible = AllowInfeasibleSolutions.Value.Value;
List<Tour> R1 = new List<Tour>();
PotvinEncoding p1Clone = parent1.Clone() as PotvinEncoding;
int length = Math.Min(Length.Value.Value, parent1.Tours.Count) + 1;
int k = 1;
if(length > 1)
k = random.Next(1, length);
for (int i = 0; i < k; i++) {
int index = SelectRandomTourBiasedByLength(random, p1Clone);
R1.Add(p1Clone.Tours[index]);
p1Clone.Tours.RemoveAt(index);
}
foreach (Tour r1 in R1) {
List<int> R2 = new List<int>();
double r = CalculateMeanCentroidDistance(r1, parent2.Tours, ProblemInstance);
foreach (Tour tour in parent2.Tours) {
if (CalculateCentroidDistance(r1, tour, ProblemInstance) <= r) {
R2.AddRange(tour.Stops);
}
}
Tour childTour = new Tour();
child.Tours.Add(childTour);
childTour.Stops.AddRange(r1.Stops);
//DESTROY - remove cities from r1
int removed = 1;
if(r1.Stops.Count > 1)
removed = random.Next(1, r1.Stops.Count + 1);
for (int i = 0; i < removed; i++) {
childTour.Stops.RemoveAt(SelectCityBiasedByNeighborDistance(random, childTour, child));
}
//REPAIR - add cities from R2
int maxCount = 1;
if(R2.Count > 1)
maxCount = random.Next(1, Math.Min(5, R2.Count));
int count = 0;
while (count < maxCount && R2.Count != 0) {
int index = random.Next(R2.Count);
int city = R2[index];
R2.RemoveAt(index);
int place = -1;
bool found = FindRouteInsertionPlace(child, childTour, city, allowInfeasible, out place);
if (found) {
childTour.Stops.Insert(place, city);
if (!Repair(random, child, childTour, ProblemInstance, allowInfeasible)) {
childTour.Stops.RemoveAt(place);
} else {
count++;
}
}
}
Repair(random, child, childTour, ProblemInstance, allowInfeasible);
}
for (int i = 0; i < p1Clone.Tours.Count; i++) {
Tour childTour = p1Clone.Tours[i].Clone() as Tour;
child.Tours.Add(childTour);
Repair(random, child, childTour, ProblemInstance, allowInfeasible);
}
//route unrouted customers
child.Unrouted.AddRange(GetUnrouted(child, ProblemInstance.Cities.Value));
bool success = RouteUnrouted(child, allowInfeasible);
if (success || allowInfeasible)
return child;
else {
if (random.NextDouble() < 0.5)
return parent1.Clone() as PotvinEncoding;
else
return parent2.Clone() as PotvinEncoding;
}
}
示例8: PotvinVehicleAssignmentMove
public PotvinVehicleAssignmentMove(int tour1, int tour2, PotvinEncoding individual) {
Tour1 = tour1;
Tour2 = tour2;
this.Individual = individual.Clone() as PotvinEncoding;
}
示例9: PotvinPDRearrangeMove
public PotvinPDRearrangeMove(int city, int tour, PotvinEncoding individual) {
City = city;
Tour = tour;
this.Individual = individual.Clone() as PotvinEncoding;
}
示例10: ReplacePair
private static PotvinEncoding ReplacePair(PotvinEncoding individual, IVRPProblemInstance instance, int replaced, int replacing, bool allowInfeasible) {
individual = individual.Clone() as PotvinEncoding;
IPickupAndDeliveryProblemInstance pdp = instance as IPickupAndDeliveryProblemInstance;
int replacedDest = pdp.GetPickupDeliveryLocation(replaced);
int replacedSource, replacedTarget;
if (pdp.GetDemand(replaced) >= 0) {
replacedSource = replaced;
replacedTarget = replacedDest;
} else {
replacedSource = replacedDest;
replacedTarget = replaced;
}
Tour replacedSourceTour = individual.Tours.Find(t => t.Stops.Contains(replacedSource));
Tour replacedTargetTour = individual.Tours.Find(t => t.Stops.Contains(replacedTarget));
int replacingDest = pdp.GetPickupDeliveryLocation(replacing);
int replacingSource, replacingTarget;
if (pdp.GetDemand(replacing) >= 0) {
replacingSource = replacing;
replacingTarget = replacingDest;
} else {
replacingSource = replacingDest;
replacingTarget = replacing;
}
Tour replacingSourceTour = individual.Tours.Find(t => t.Stops.Contains(replacingSource));
Tour replacingTargetTour = individual.Tours.Find(t => t.Stops.Contains(replacingTarget));
replacingSourceTour.Stops.Remove(replacingSource);
replacingTargetTour.Stops.Remove(replacingTarget);
replacedSourceTour.Stops[replacedSourceTour.Stops.IndexOf(replacedSource)] = replacingSource;
if (!allowInfeasible && !instance.TourFeasible(replacedSourceTour, individual))
return null;
replacedTargetTour.Stops[replacedTargetTour.Stops.IndexOf(replacedTarget)] = replacingTarget;
if (!allowInfeasible && !instance.TourFeasible(replacedTargetTour, individual))
return null;
double bestQuality = double.MaxValue;
int bestTour = -1;
int bestPositionSource = -1;
int bestPositionTarget = -1;
int routeToAvoid = individual.Tours.IndexOf(replacingSourceTour);
for (int tourIdx = 0; tourIdx < individual.Tours.Count; tourIdx++) {
if (tourIdx != routeToAvoid) {
Tour tour = individual.Tours[tourIdx];
VRPEvaluation eval = instance.EvaluateTour(tour, individual);
individual.InsertPair(tour, replacedSource, replacedTarget, instance);
VRPEvaluation evalNew = instance.EvaluateTour(tour, individual);
double delta = evalNew.Quality - eval.Quality;
if (delta < bestQuality &&
(instance.Feasible(evalNew) || allowInfeasible)) {
bestQuality = delta;
bestTour = tourIdx;
bestPositionSource = tour.Stops.IndexOf(replacedSource);
bestPositionTarget = tour.Stops.IndexOf(replacedTarget);
}
tour.Stops.Remove(replacedSource);
tour.Stops.Remove(replacedTarget);
}
}
if (bestTour != -1) {
if (bestPositionTarget < bestPositionSource) {
individual.Tours[bestTour].Stops.Insert(bestPositionTarget, replacedTarget);
individual.Tours[bestTour].Stops.Insert(bestPositionSource, replacedSource);
} else {
individual.Tours[bestTour].Stops.Insert(bestPositionSource, replacedSource);
individual.Tours[bestTour].Stops.Insert(bestPositionTarget, replacedTarget);
}
return individual;
} else {
return null;
}
}