#region License Information /* HeuristicLab * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using HeuristicLab.Analysis; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Encodings.ParameterConfigurationEncoding; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Problems.MetaOptimization { /// /// An operator for analyzing the diversity of solutions of parameter meta-optimization. /// [Item("PMOPopulationDiversityAnalyzer", "An operator for analyzing the diversity of solutions of parameter meta-optimization.")] [StorableClass] public sealed class PMOPopulationDiversityAnalyzer : PopulationDiversityAnalyzer { #region Constructors and Cloning public PMOPopulationDiversityAnalyzer() : base() { } [StorableConstructor] private PMOPopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { } private PMOPopulationDiversityAnalyzer(PMOPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { } public override IDeepCloneable Clone(Cloner cloner) { return new PMOPopulationDiversityAnalyzer(this, cloner); } #endregion protected override double[,] CalculateSimilarities(ParameterConfigurationTree[] solutions) { // TODO: consider implementing a similarity calculator 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 left, ParameterConfigurationTree right) { return left.CalculateSimilarity(right); } } }