Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/19/12 13:19:12 (12 years ago)
Author:
jkarder
Message:

#1331: added support for similarity calculation between multiple individuals

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/SimilarityCalculator.cs

    r8303 r8304  
    2121
    2222using System;
     23using System.Linq;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
     
    5051    protected SimilarityCalculator() : base() { }
    5152
    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 is null.");
     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.");
    5556
    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;
    5872    }
    5973
    60     protected abstract double CalculateSimilarity(IScope left, IScope right);
     74    public abstract double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual);
    6175  }
    6276}
Note: See TracChangeset for help on using the changeset viewer.