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

Location:
branches/ScatterSearch (trunk integration)
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs

    r8086 r8304  
    8080        double similarity = 0;
    8181        foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) {
    82           similarity += SimilarityCalculator.ExecuteCalculation(pScope, rScope);
     82          similarity += SimilarityCalculator.CalculateIndividualSimilarity(pScope, rScope);
    8383        }
    8484        population[pScope] = similarity;
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs

    r8086 r8304  
    130130      if (orderedOffspring.Any(hasBetterQuality)) {
    131131        // produce the set union
    132         var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.ExecuteCalculation));
     132        var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.CalculateIndividualSimilarity));
    133133        if (union.Count() > orderedParents.Count()) {
    134134          var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) :
  • 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}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityCalculator.cs

    r8086 r8304  
    2929    string Target { get; set; }
    3030
    31     double ExecuteCalculation(IScope left, IScope right);
     31    double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual);
     32    double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd);
    3233  }
    3334}
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs

    r8303 r8304  
    4242    public static double CalculateSimilarity(BinaryVector left, BinaryVector right) {
    4343      if (left == null || right == null)
    44         throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
     44        throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes is null.");
     45      if (left == right) return 1.0;
    4546
    4647      double similarity = 0.0;
     
    5051    }
    5152
    52     protected override double CalculateSimilarity(IScope left, IScope right) {
    53       BinaryVector sol1 = left.Variables[Target].Value as BinaryVector;
    54       BinaryVector sol2 = right.Variables[Target].Value as BinaryVector;
     53    public override double CalculateIndividualSimilarity(IScope left, IScope right) {
     54      var sol1 = left.Variables[Target].Value as BinaryVector;
     55      var sol2 = right.Variables[Target].Value as BinaryVector;
    5556
    5657      return CalculateSimilarity(sol1, sol2);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs

    r8303 r8304  
    5757      if (bounds == null)
    5858        throw new ArgumentException("Cannot calculate similarity because no bounds were provided.");
     59      if (left == right) return 1.0;
    5960
    6061      double maxSum = 0.0;
     
    7172    }
    7273
    73     protected override double CalculateSimilarity(IScope left, IScope right) {
    74       RealVector sol1 = left.Variables[Target].Value as RealVector;
    75       RealVector sol2 = right.Variables[Target].Value as RealVector;
     74    public override double CalculateIndividualSimilarity(IScope left, IScope right) {
     75      var sol1 = left.Variables[Target].Value as RealVector;
     76      var sol2 = right.Variables[Target].Value as RealVector;
    7677
    7778      return CalculateSimilarity(sol1, sol2, Bounds);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs

    r8303 r8304  
    4343      if (left == null || right == null)
    4444        throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
     45      if (left == right) return 1.0;
    4546
    4647      int[,] edges = new int[right.Length, 2];
     
    6061    }
    6162
    62     protected override double CalculateSimilarity(IScope left, IScope right) {
    63       Permutation sol1 = left.Variables[Target].Value as Permutation;
    64       Permutation sol2 = right.Variables[Target].Value as Permutation;
     63    public override double CalculateIndividualSimilarity(IScope left, IScope right) {
     64      var sol1 = left.Variables[Target].Value as Permutation;
     65      var sol2 = right.Variables[Target].Value as Permutation;
    6566
    6667      return CalculateSimilarity(sol1, sol2);
  • branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/SimilarityCalculators/VRPSimilarityCalculator.cs

    r8303 r8304  
    4646      if (left == null || right == null)
    4747        throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
     48      if (left == right) return 1.0;
    4849
    4950      // extract edges from first solution
     
    7778    }
    7879
    79     protected override double CalculateSimilarity(IScope left, IScope right) {
    80       PotvinEncoding sol1 = left.Variables[Target].Value as PotvinEncoding;
    81       PotvinEncoding sol2 = right.Variables[Target].Value as PotvinEncoding;
     80    public override double CalculateIndividualSimilarity(IScope left, IScope right) {
     81      var sol1 = left.Variables[Target].Value as PotvinEncoding;
     82      var sol2 = right.Variables[Target].Value as PotvinEncoding;
    8283
    8384      return CalculateSimilarity(sol1, sol2);
Note: See TracChangeset for help on using the changeset viewer.