本文整理汇总了C#中HeuristicLab.Encodings.PermutationEncoding.Permutation.GetCircular方法的典型用法代码示例。如果您正苦于以下问题:C# Permutation.GetCircular方法的具体用法?C# Permutation.GetCircular怎么用?C# Permutation.GetCircular使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HeuristicLab.Encodings.PermutationEncoding.Permutation
的用法示例。
在下文中一共展示了Permutation.GetCircular方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: EvaluateByCoordinates
public static double EvaluateByCoordinates(Permutation permutation, TranslocationMove move, DoubleMatrix coordinates, TSPTranslocationMovePathEvaluator evaluator) {
if (move.Index1 == move.Index3
|| move.Index2 == permutation.Length - 1 && move.Index3 == 0
|| move.Index1 == 0 && move.Index3 == permutation.Length - 1 - move.Index2) return 0;
int edge1source = permutation.GetCircular(move.Index1 - 1);
int edge1target = permutation[move.Index1];
int edge2source = permutation[move.Index2];
int edge2target = permutation.GetCircular(move.Index2 + 1);
int edge3source, edge3target;
if (move.Index3 > move.Index1) {
edge3source = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1);
edge3target = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1 + 1);
} else {
edge3source = permutation.GetCircular(move.Index3 - 1);
edge3target = permutation[move.Index3];
}
double moveQuality = 0;
// remove three edges
moveQuality -= evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
coordinates[edge1target, 0], coordinates[edge1target, 1]);
moveQuality -= evaluator.CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
coordinates[edge2target, 0], coordinates[edge2target, 1]);
moveQuality -= evaluator.CalculateDistance(coordinates[edge3source, 0], coordinates[edge3source, 1],
coordinates[edge3target, 0], coordinates[edge3target, 1]);
// add three edges
moveQuality += evaluator.CalculateDistance(coordinates[edge3source, 0], coordinates[edge3source, 1],
coordinates[edge1target, 0], coordinates[edge1target, 1]);
moveQuality += evaluator.CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
coordinates[edge3target, 0], coordinates[edge3target, 1]);
moveQuality += evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
coordinates[edge2target, 0], coordinates[edge2target, 1]);
return moveQuality;
}
示例2: EvaluateByDistanceMatrix
public static double EvaluateByDistanceMatrix(Permutation permutation, InversionMove move, DistanceMatrix distanceMatrix) {
int edge1source = permutation.GetCircular(move.Index1 - 1);
int edge1target = permutation[move.Index1];
int edge2source = permutation[move.Index2];
int edge2target = permutation.GetCircular(move.Index2 + 1);
if (move.Index2 - move.Index1 >= permutation.Length - 2) return 0;
double moveQuality = 0;
// remove two edges
moveQuality -= distanceMatrix[edge1source, edge1target];
moveQuality -= distanceMatrix[edge2source, edge2target];
// add two edges
moveQuality += distanceMatrix[edge1source, edge2source];
moveQuality += distanceMatrix[edge1target, edge2target];
return moveQuality;
}
示例3: EvaluateByCoordinates
public static double EvaluateByCoordinates(Permutation permutation, InversionMove move, DoubleMatrix coordinates, TSPInversionMovePathEvaluator evaluator) {
int edge1source = permutation.GetCircular(move.Index1 - 1);
int edge1target = permutation[move.Index1];
int edge2source = permutation[move.Index2];
int edge2target = permutation.GetCircular(move.Index2 + 1);
if (move.Index2 - move.Index1 >= permutation.Length - 2) return 0;
double moveQuality = 0;
// remove two edges
moveQuality -= evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
coordinates[edge1target, 0], coordinates[edge1target, 1]);
moveQuality -= evaluator.CalculateDistance(coordinates[edge2source, 0], coordinates[edge2source, 1],
coordinates[edge2target, 0], coordinates[edge2target, 1]);
// add two edges
moveQuality += evaluator.CalculateDistance(coordinates[edge1source, 0], coordinates[edge1source, 1],
coordinates[edge2source, 0], coordinates[edge2source, 1]);
moveQuality += evaluator.CalculateDistance(coordinates[edge1target, 0], coordinates[edge1target, 1],
coordinates[edge2target, 0], coordinates[edge2target, 1]);
return moveQuality;
}
示例4: EvaluateMove
public static double EvaluateMove(Permutation tour, InversionMove move, Func<int, int, double> distance, ItemList<BoolArray> realizations) {
double moveQuality = 0;
var edges = new int[4];
var indices = new int[4];
edges[0] = tour.GetCircular(move.Index1 - 1);
indices[0] = move.Index1 - 1;
if (indices[0] == -1) indices[0] = tour.Length - 1;
edges[1] = tour[move.Index1];
indices[1] = move.Index1;
edges[2] = tour[move.Index2];
indices[2] = move.Index2;
edges[3] = tour.GetCircular(move.Index2 + 1);
indices[3] = move.Index2 + 1;
if (indices[3] == tour.Length + 1) indices[3] = 0;
var aPosteriori = new int[4];
foreach (var realization in realizations) {
for (var i = 0; i < edges.Length; i++) {
if (realization[edges[i]]) {
aPosteriori[i] = edges[i];
} else {
var j = 1;
if (i % 2 == 0) {
// find nearest predecessor in realization if source edge
while (!realization[tour.GetCircular(indices[i] - j)]) {
j++;
}
aPosteriori[i] = tour.GetCircular(indices[i] - j);
} else {
// find nearest successor in realization if target edge
while (!realization[tour.GetCircular(indices[i] + j)]) {
j++;
}
aPosteriori[i] = tour.GetCircular(indices[i] + j);
}
}
}
// compute cost difference between the two a posteriori solutions
if (!(aPosteriori[0] == aPosteriori[2] && aPosteriori[1] == aPosteriori[3])) {
moveQuality = moveQuality + distance(aPosteriori[0], aPosteriori[2]) + distance(aPosteriori[1], aPosteriori[3])
- distance(aPosteriori[0], aPosteriori[1]) - distance(aPosteriori[2], aPosteriori[3]);
}
Array.Clear(aPosteriori, 0, aPosteriori.Length);
}
// return average of cost differences
return moveQuality / realizations.Count;
}
示例5: EvaluateByDistanceMatrix
public static double EvaluateByDistanceMatrix(Permutation permutation, TranslocationMove move, DistanceMatrix distanceMatrix) {
if (move.Index1 == move.Index3
|| move.Index2 == permutation.Length - 1 && move.Index3 == 0
|| move.Index1 == 0 && move.Index3 == permutation.Length - 1 - move.Index2) return 0;
int edge1source = permutation.GetCircular(move.Index1 - 1);
int edge1target = permutation[move.Index1];
int edge2source = permutation[move.Index2];
int edge2target = permutation.GetCircular(move.Index2 + 1);
int edge3source, edge3target;
if (move.Index3 > move.Index1) {
edge3source = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1);
edge3target = permutation.GetCircular(move.Index3 + move.Index2 - move.Index1 + 1);
} else {
edge3source = permutation.GetCircular(move.Index3 - 1);
edge3target = permutation[move.Index3];
}
double moveQuality = 0;
// remove three edges
moveQuality -= distanceMatrix[edge1source, edge1target];
moveQuality -= distanceMatrix[edge2source, edge2target];
moveQuality -= distanceMatrix[edge3source, edge3target];
// add three edges
moveQuality += distanceMatrix[edge3source, edge1target];
moveQuality += distanceMatrix[edge2source, edge3target];
moveQuality += distanceMatrix[edge1source, edge2target];
return moveQuality;
}
示例6: EvaluateRelativeTabuState
private static bool EvaluateRelativeTabuState(ItemList<IItem> tabuList, Swap2Move move, Permutation permutation, double moveQuality, bool maximization, bool useAspiration) {
bool isTabu = false;
StandardEdgeEqualityComparer eq = new StandardEdgeEqualityComparer();
bool bidirectional = permutation.PermutationType == PermutationTypes.RelativeUndirected;
List<Edge> added = new List<Edge>();
added.Add(new Edge(permutation.GetCircular(move.Index1 - 1), permutation[move.Index2], bidirectional));
added.Add(new Edge(permutation[move.Index2], permutation.GetCircular(move.Index1 + 1), bidirectional));
added.Add(new Edge(permutation.GetCircular(move.Index2 - 1), permutation[move.Index1], bidirectional));
added.Add(new Edge(permutation[move.Index1], permutation.GetCircular(move.Index2 + 1), bidirectional));
foreach (IItem tabuMove in tabuList) {
Swap2MoveRelativeAttribute relAttrib = (tabuMove as Swap2MoveRelativeAttribute);
if (relAttrib != null
&& (!useAspiration
|| maximization && moveQuality <= relAttrib.MoveQuality
|| !maximization && moveQuality >= relAttrib.MoveQuality)) {
for (int i = 0; i < relAttrib.DeletedEdges.Count; i++) {
isTabu = eq.Equals(relAttrib.DeletedEdges[i], added[0])
|| eq.Equals(relAttrib.DeletedEdges[i], added[1])
|| eq.Equals(relAttrib.DeletedEdges[i], added[2])
|| eq.Equals(relAttrib.DeletedEdges[i], added[3]);
if (isTabu) break;
}
}
if (isTabu) break;
}
return isTabu;
}
示例7: EvaluateMove
public static double EvaluateMove(Permutation tour, TranslocationMove move, Func<int, int, double> distance, ItemList<BoolArray> realizations) {
var afterMove = (Permutation)tour.Clone();
TranslocationManipulator.Apply(afterMove, move.Index1, move.Index1, move.Index3);
double moveQuality = 0;
var edges = new int[12];
var indices = new int[12];
edges[0] = tour.GetCircular(move.Index1 - 1);
indices[0] = DecreaseCircularIndex(tour.Length, move.Index1);
edges[1] = tour[move.Index1];
indices[1] = move.Index1;
edges[2] = tour[move.Index1];
indices[2] = move.Index1;
edges[3] = tour.GetCircular(move.Index1 + 1);
indices[3] = IncreaseCircularIndex(tour.Length, move.Index1);
edges[6] = afterMove.GetCircular(move.Index3 - 1);
indices[6] = DecreaseCircularIndex(afterMove.Length, move.Index3);
edges[7] = afterMove[move.Index3];
indices[7] = move.Index3;
edges[8] = afterMove[move.Index3];
indices[8] = move.Index3;
edges[9] = afterMove.GetCircular(move.Index3 + 1);
indices[9] = IncreaseCircularIndex(afterMove.Length, move.Index3);
if (move.Index3 > move.Index1) {
edges[4] = tour[move.Index3];
indices[4] = move.Index3;
edges[5] = tour.GetCircular(move.Index3 + 1);
indices[5] = indices[9];
edges[10] = afterMove.GetCircular(move.Index1 - 1);
indices[10] = indices[0];
edges[11] = afterMove[move.Index1];
indices[11] = move.Index1;
} else {
edges[4] = tour.GetCircular(move.Index3 - 1);
indices[4] = indices[6];
edges[5] = tour[move.Index3];
indices[5] = move.Index3;
edges[10] = afterMove[move.Index1];
indices[10] = move.Index1;
edges[11] = afterMove.GetCircular(move.Index1 + 1);
indices[11] = indices[3];
}
int[] aPosteriori = new int[12];
foreach (var realization in realizations) {
for (int i = 0; i < edges.Length; i++) {
Permutation tempPermutation;
if (i < 6) {
tempPermutation = tour;
} else {
tempPermutation = afterMove;
}
if (realization[edges[i]]) {
aPosteriori[i] = edges[i];
} else {
int j = 1;
if (i % 2 == 0) {
// find nearest predecessor in realization if source edge
while (!realization[tempPermutation.GetCircular(indices[i] - j)]) {
j++;
}
aPosteriori[i] = tempPermutation.GetCircular(indices[i] - j);
} else {
// find nearest successor in realization if target edge
while (!realization[tempPermutation.GetCircular(indices[i] + j)]) {
j++;
}
aPosteriori[i] = tempPermutation.GetCircular(indices[i] + j);
}
}
}
if (!(aPosteriori[0] == aPosteriori[2] && aPosteriori[1] == aPosteriori[3]) &&
!(aPosteriori[0] == aPosteriori[4] && aPosteriori[1] == aPosteriori[5]) &&
!(aPosteriori[2] == aPosteriori[4] && aPosteriori[3] == aPosteriori[5])) {
// compute cost difference between the two a posteriori solutions
moveQuality = moveQuality + distance(aPosteriori[6], aPosteriori[7]) + distance(aPosteriori[8], aPosteriori[9]) + distance(aPosteriori[10], aPosteriori[11]);
moveQuality = moveQuality - distance(aPosteriori[0], aPosteriori[1]) - distance(aPosteriori[2], aPosteriori[3]) - distance(aPosteriori[4], aPosteriori[5]);
}
Array.Clear(aPosteriori, 0, aPosteriori.Length);
}
// return average of cost differences
return moveQuality / realizations.Count;
}