using System; using System.Collections.Generic; using System.Linq; using System.Text; using HeuristicLab.Common; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; using HeuristicLab.Core; using HeuristicLab.Analysis; namespace HeuristicLab.Problems.MetaOptimization { /// /// An operator for analyzing the diversity of solutions of Traveling Salesman Problems given in path representation. /// [Item("PMOPopulationDiversityAnalyzer", "An operator for analyzing the diversity of solutions of Parameter Meta-Optimization.")] [StorableClass] public sealed class PMOPopulationDiversityAnalyzer : PopulationDiversityAnalyzer { [StorableConstructor] private PMOPopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { } private PMOPopulationDiversityAnalyzer(PMOPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { } public PMOPopulationDiversityAnalyzer() : base() { } public override IDeepCloneable Clone(Cloner cloner) { return new PMOPopulationDiversityAnalyzer(this, cloner); } protected override double[,] CalculateSimilarities(ParameterConfigurationTree[] solutions) { int count = solutions.Length; double[,] similarities = new double[count, count]; for (int i = 0; i < count; i++) { similarities[i, i] = 1; for (int j = i + 1; j < count; j++) { similarities[i, j] = CalculateSimilarity(solutions[i], solutions[j]); similarities[j, i] = similarities[i, j]; } } return similarities; } private double CalculateSimilarity(ParameterConfigurationTree pca, ParameterConfigurationTree pcb) { return pca.CalculateSimilarity(pcb); } } }