1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Common;
|
---|
6 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
7 | using HeuristicLab.Core;
|
---|
8 | using HeuristicLab.Analysis;
|
---|
9 | using HEAL.Attic;
|
---|
10 |
|
---|
11 | namespace 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 | }
|
---|