protected override double[,] CalculateSimilarities(Permutation[] solutions) { DoubleMatrix weights = WeightsParameter.ActualValue, distances = DistancesParameter.ActualValue; bool phenotypeSimilarity = UsePhenotypeSimilarityParameter.Value.Value; int count = solutions.Length; double[,] similarities = new double[count, count]; for (int i = 0; i < count; i++) { similarities[i, i] = 1; for (int j = i + 1; j < count; j++) { if (phenotypeSimilarity) { similarities[i, j] = QAPPermutationProximityCalculator.CalculatePhenotypeSimilarity(solutions[i], solutions[j], weights, distances); } else { similarities[i, j] = HammingSimilarityCalculator.CalculateSimilarity(solutions[i], solutions[j]); } similarities[j, i] = similarities[i, j]; } } return(similarities); }
public static double CalculateSimilarity(Permutation left, Permutation right, DoubleMatrix weights, DoubleMatrix distances) { if (left == null || right == null) { throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); } if (left.Length != right.Length) { throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths."); } if (left.Length == 0) { throw new ArgumentException("Cannot calculate similarity because solutions are of length 0."); } if (ReferenceEquals(left, right)) { return(1.0); } return(QAPPermutationProximityCalculator.CalculatePhenotypeSimilarity(left, right, weights, distances)); }