Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOPopulationDiversityAnalyzer.cs @ 16574

Last change on this file since 16574 was 16574, checked in by gkronber, 5 years ago

#2520: changed HeuristicLab.MetaOptimization addon to compile with new HL.Persistence

File size: 1.8 KB
Line 
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;
9using HEAL.Attic;
10
11namespace HeuristicLab.Problems.MetaOptimization {
12  /// <summary>
13  /// An operator for analyzing the diversity of solutions of Traveling Salesman Problems given in path representation.
14  /// </summary>
15  [Item("PMOPopulationDiversityAnalyzer", "An operator for analyzing the diversity of solutions of Parameter Meta-Optimization.")]
16  [StorableType("6B841AFF-BEE0-484D-AC84-26368854852A")]
17  public sealed class PMOPopulationDiversityAnalyzer : PopulationDiversityAnalyzer<ParameterConfigurationTree> {
18    [StorableConstructor]
19    private PMOPopulationDiversityAnalyzer(StorableConstructorFlag _) : base(_) { }
20    private PMOPopulationDiversityAnalyzer(PMOPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { }
21    public PMOPopulationDiversityAnalyzer() : base() { }
22
23    public override IDeepCloneable Clone(Cloner cloner) {
24      return new PMOPopulationDiversityAnalyzer(this, cloner);
25    }
26
27    protected override double[,] CalculateSimilarities(ParameterConfigurationTree[] solutions) {
28      int count = solutions.Length;
29      double[,] similarities = new double[count, count];
30
31      for (int i = 0; i < count; i++) {
32        similarities[i, i] = 1;
33        for (int j = i + 1; j < count; j++) {
34          similarities[i, j] = CalculateSimilarity(solutions[i], solutions[j]);
35          similarities[j, i] = similarities[i, j];
36        }
37      }
38      return similarities;
39    }
40
41    private double CalculateSimilarity(ParameterConfigurationTree pca, ParameterConfigurationTree pcb) {
42      return pca.CalculateSimilarity(pcb);
43    }
44  }
45}
Note: See TracBrowser for help on using the repository browser.