Free cookie consent management tool by TermsFeed Policy Generator

# Ticket #2377: SolutionSimilarityCalculator.cs.patch

File SolutionSimilarityCalculator.cs.patch, 2.1 KB (added by ascheibe, 9 years ago)
• ## sources/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs

 using System; using System.Linq; using System.Threading.Tasks; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are empty."); var similarityMatrix = new double[leftIndividuals.Count][]; for (int i = 0; i < leftIndividuals.Count; i++) { Parallel.For(0, leftIndividuals.Count, (i) => { similarityMatrix[i] = new double[rightIndividuals.Count]; for (int j = 0; j < rightIndividuals.Count; j++) { similarityMatrix[i][j] = CalculateSolutionSimilarity(leftIndividuals[i], rightIndividuals[j]); } } }); return similarityMatrix; } for (int i = 0; i < individuals.Count; i++) similarityMatrix[i] = new double[individuals.Count]; if (IsCommutative) { for (int i = 0; i < individuals.Count; i++) { Parallel.For(0, individuals.Count, (i) => { for (int j = i; j < individuals.Count; j++) { similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]); } } }); } else { for (int i = 0; i < individuals.Count; i++) { Parallel.For(0, individuals.Count, (i) => { for (int j = i; j < individuals.Count; j++) { similarityMatrix[i][j] = CalculateSolutionSimilarity(individuals[i], individuals[j]); if (i == j) continue; similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[j], individuals[i]); } } }); } return similarityMatrix;