Changeset 8304 for branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3
- Timestamp:
- 07/19/12 13:19:12 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/SimilarityCalculator.cs
r8303 r8304 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 50 51 protected SimilarityCalculator() : base() { } 51 52 52 public double ExecuteCalculation(IScope left, IScope right) {53 if (left == null || right== null)54 throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes isnull.");53 public double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd) { 54 if (leftCrowd == null || rightCrowd == null) 55 throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are null."); 55 56 56 if (left == right) return 1.0; 57 else return CalculateSimilarity(left, right); 57 var leftIndividuals = leftCrowd.SubScopes; 58 var rightIndividuals = rightCrowd.SubScopes; 59 60 if (!leftIndividuals.Any() || !rightIndividuals.Any()) 61 throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are empty."); 62 63 var similarityMatrix = new double[leftIndividuals.Count][]; 64 for (int i = 0; i < leftIndividuals.Count; i++) { 65 similarityMatrix[i] = new double[rightIndividuals.Count]; 66 for (int j = 0; j < rightIndividuals.Count; j++) { 67 similarityMatrix[i][j] = CalculateIndividualSimilarity(leftIndividuals[i], rightIndividuals[j]); 68 } 69 } 70 71 return similarityMatrix; 58 72 } 59 73 60 p rotected abstract double CalculateSimilarity(IScope left, IScope right);74 public abstract double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual); 61 75 } 62 76 }
Note: See TracChangeset
for help on using the changeset viewer.