[8415] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
| 3 | * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
| 4 | *
|
---|
| 5 | * This file is part of HeuristicLab.
|
---|
| 6 | *
|
---|
| 7 | * HeuristicLab is free software: you can redistribute it and/or modify
|
---|
| 8 | * it under the terms of the GNU General Public License as published by
|
---|
| 9 | * the Free Software Foundation, either version 3 of the License, or
|
---|
| 10 | * (at your option) any later version.
|
---|
| 11 | *
|
---|
| 12 | * HeuristicLab is distributed in the hope that it will be useful,
|
---|
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 15 | * GNU General Public License for more details.
|
---|
| 16 | *
|
---|
| 17 | * You should have received a copy of the GNU General Public License
|
---|
| 18 | * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
|
---|
| 19 | */
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 |
|
---|
[8722] | 23 | using System.Linq;
|
---|
[8415] | 24 | using HeuristicLab.Common;
|
---|
| 25 | using HeuristicLab.Core;
|
---|
| 26 | using HeuristicLab.Operators;
|
---|
| 27 | using HeuristicLab.Optimization;
|
---|
| 28 | using HeuristicLab.Parameters;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 30 |
|
---|
| 31 | namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
|
---|
| 32 | [Item("DuplicateSolutionsAnalyzer", "An operator that analyzes duplicate solutions in the population.")]
|
---|
| 33 | [StorableClass]
|
---|
| 34 | public class DuplicateSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer {
|
---|
| 35 | private const string ResultsParameterName = "Results";
|
---|
| 36 |
|
---|
| 37 | #region IAnalyzer Members
|
---|
| 38 | public bool EnabledByDefault {
|
---|
| 39 | get { return false; }
|
---|
| 40 | }
|
---|
| 41 | #endregion
|
---|
| 42 |
|
---|
| 43 | #region Parameter properties
|
---|
| 44 | public ILookupParameter<ResultCollection> ResultsParameter {
|
---|
| 45 | get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
|
---|
| 46 | }
|
---|
[8722] | 47 | public IValueParameter<ISingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
| 48 | get { return (IValueParameter<ISingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
[8415] | 49 | }
|
---|
[8722] | 50 | public ILookupParameter<ItemCollection<IItem>> OperatorsParameter {
|
---|
| 51 | get { return (ILookupParameter<ItemCollection<IItem>>)Parameters["Operators"]; }
|
---|
| 52 | }
|
---|
[8415] | 53 | #endregion
|
---|
| 54 |
|
---|
| 55 | #region Properties
|
---|
| 56 | public ResultCollection Results {
|
---|
| 57 | get { return ResultsParameter.ActualValue; }
|
---|
| 58 | }
|
---|
| 59 |
|
---|
[8505] | 60 | [Storable]
|
---|
[8498] | 61 | private DataTableHelper chartingHelper;
|
---|
[8415] | 62 | #endregion
|
---|
| 63 |
|
---|
| 64 | [StorableConstructor]
|
---|
| 65 | private DuplicateSolutionsAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
[8722] | 66 |
|
---|
| 67 | private DuplicateSolutionsAnalyzer(DuplicateSolutionsAnalyzer original, Cloner cloner)
|
---|
| 68 | : base(original, cloner) {
|
---|
[8505] | 69 | chartingHelper = (DataTableHelper)original.chartingHelper.Clone(cloner);
|
---|
| 70 | }
|
---|
[8722] | 71 |
|
---|
[8415] | 72 | public DuplicateSolutionsAnalyzer()
|
---|
| 73 | : base() {
|
---|
| 74 | Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
|
---|
[8722] | 75 | Parameters.Add(new ValueParameter<ISingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator"));
|
---|
| 76 | Parameters.Add(new LookupParameter<ItemCollection<IItem>>("Operators", "The operators and items that the problem provides to the algorithms."));
|
---|
[8498] | 77 |
|
---|
| 78 | chartingHelper = new DataTableHelper();
|
---|
[8415] | 79 | }
|
---|
| 80 |
|
---|
| 81 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 82 | return new DuplicateSolutionsAnalyzer(this, cloner);
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | public override IOperation Apply() {
|
---|
[8722] | 86 | if (SimilarityCalculatorParameter.Value == null) {
|
---|
| 87 | SimilarityCalculatorParameter.Value = OperatorsParameter.ActualValue.OfType<ISingleObjectiveSolutionSimilarityCalculator>().FirstOrDefault();
|
---|
| 88 | }
|
---|
[8797] | 89 | chartingHelper.InitializeChart(Results, "Duplicate Solutions", new string[] { "Duplicate Solutions per Generation" });
|
---|
[8415] | 90 |
|
---|
| 91 | var similarities = SimilarityCalculatorParameter.Value.CalculateSolutionCrowdSimilarity(ExecutionContext.Scope);
|
---|
| 92 | int counter = 0;
|
---|
| 93 | for (int i = 0; i < similarities.Length; i++) {
|
---|
| 94 | for (int j = 0; j < similarities[i].Length; j++) {
|
---|
| 95 | if (similarities[i][j] == 1.0 && i != j) {
|
---|
| 96 | counter++;
|
---|
| 97 | break;
|
---|
| 98 | }
|
---|
| 99 | }
|
---|
| 100 | }
|
---|
| 101 |
|
---|
[8722] | 102 | chartingHelper.AddPoint(counter / (double)similarities.Length);
|
---|
[8415] | 103 | return base.Apply();
|
---|
| 104 | }
|
---|
| 105 | }
|
---|
| 106 | }
|
---|