[5522] | 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 |
|
---|
| 10 | namespace 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 | }
|
---|