Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOPopulationDiversityAnalyzer.cs @ 9584

Last change on this file since 9584 was 5522, checked in by cneumuel, 14 years ago

#1215

  • implemented population diversity analysis
File size: 1.8 KB
RevLine 
[5522]1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Common;
6using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
7using HeuristicLab.Core;
8using HeuristicLab.Analysis;
9
10namespace HeuristicLab.Problems.MetaOptimization {
11  /// <summary>
12  /// An operator for analyzing the diversity of solutions of Traveling Salesman Problems given in path representation.
13  /// </summary>
14  [Item("PMOPopulationDiversityAnalyzer", "An operator for analyzing the diversity of solutions of Parameter Meta-Optimization.")]
15  [StorableClass]
16  public sealed class PMOPopulationDiversityAnalyzer : PopulationDiversityAnalyzer<ParameterConfigurationTree> {
17    [StorableConstructor]
18    private PMOPopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { }
19    private PMOPopulationDiversityAnalyzer(PMOPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { }
20    public PMOPopulationDiversityAnalyzer() : base() { }
21
22    public override IDeepCloneable Clone(Cloner cloner) {
23      return new PMOPopulationDiversityAnalyzer(this, cloner);
24    }
25
26    protected override double[,] CalculateSimilarities(ParameterConfigurationTree[] solutions) {
27      int count = solutions.Length;
28      double[,] similarities = new double[count, count];
29
30      for (int i = 0; i < count; i++) {
31        similarities[i, i] = 1;
32        for (int j = i + 1; j < count; j++) {
33          similarities[i, j] = CalculateSimilarity(solutions[i], solutions[j]);
34          similarities[j, i] = similarities[i, j];
35        }
36      }
37      return similarities;
38    }
39
40    private double CalculateSimilarity(ParameterConfigurationTree pca, ParameterConfigurationTree pcb) {
41      return pca.CalculateSimilarity(pcb);
42    }
43  }
44}
Note: See TracBrowser for help on using the repository browser.