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 |
|
---|
23 | using HeuristicLab.Common;
|
---|
24 | using HeuristicLab.Core;
|
---|
25 | using HeuristicLab.Operators;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Optimization.Operators;
|
---|
28 | using HeuristicLab.Parameters;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Problems.TravelingSalesman;
|
---|
31 |
|
---|
32 | namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
|
---|
33 | [Item("DuplicateSolutionsAnalyzer", "An operator that analyzes duplicate solutions in the population.")]
|
---|
34 | [StorableClass]
|
---|
35 | public class DuplicateSolutionsAnalyzer : SingleSuccessorOperator, IAnalyzer {
|
---|
36 | private const string ResultsParameterName = "Results";
|
---|
37 |
|
---|
38 | #region IAnalyzer Members
|
---|
39 | public bool EnabledByDefault {
|
---|
40 | get { return false; }
|
---|
41 | }
|
---|
42 | #endregion
|
---|
43 |
|
---|
44 | #region Parameter properties
|
---|
45 | public ILookupParameter<ResultCollection> ResultsParameter {
|
---|
46 | get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
|
---|
47 | }
|
---|
48 | public IValueParameter<SingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
49 | get { return (IValueParameter<SingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
50 | }
|
---|
51 | #endregion
|
---|
52 |
|
---|
53 | #region Properties
|
---|
54 | public ResultCollection Results {
|
---|
55 | get { return ResultsParameter.ActualValue; }
|
---|
56 | }
|
---|
57 |
|
---|
58 | [Storable]
|
---|
59 | private DataTableHelper chartingHelper;
|
---|
60 | #endregion
|
---|
61 |
|
---|
62 | [StorableConstructor]
|
---|
63 | private DuplicateSolutionsAnalyzer(bool deserializing) : base(deserializing) { }
|
---|
64 |
|
---|
65 | private DuplicateSolutionsAnalyzer(DuplicateSolutionsAnalyzer original, Cloner cloner) : base(original, cloner) {
|
---|
66 | chartingHelper = (DataTableHelper)original.chartingHelper.Clone(cloner);
|
---|
67 | }
|
---|
68 |
|
---|
69 | public DuplicateSolutionsAnalyzer()
|
---|
70 | : base() {
|
---|
71 | Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
|
---|
72 | Parameters.Add(new ValueParameter<SingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator", new TSPSimilarityCalculator()));
|
---|
73 | SimilarityCalculatorParameter.Value.SolutionVariableName = "TSPTour";
|
---|
74 | SimilarityCalculatorParameter.Value.QualityVariableName = "TSPTourLength";
|
---|
75 |
|
---|
76 | chartingHelper = new DataTableHelper();
|
---|
77 | }
|
---|
78 |
|
---|
79 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
80 | return new DuplicateSolutionsAnalyzer(this, cloner);
|
---|
81 | }
|
---|
82 |
|
---|
83 | public override IOperation Apply() {
|
---|
84 | chartingHelper.InitializeChart(Results, "Duplicate Solutions", "Duplicate Solutions per Generation");
|
---|
85 |
|
---|
86 | var similarities = SimilarityCalculatorParameter.Value.CalculateSolutionCrowdSimilarity(ExecutionContext.Scope);
|
---|
87 | int counter = 0;
|
---|
88 | for (int i = 0; i < similarities.Length; i++) {
|
---|
89 | for (int j = 0; j < similarities[i].Length; j++) {
|
---|
90 | if (similarities[i][j] == 1.0 && i != j) {
|
---|
91 | counter++;
|
---|
92 | break;
|
---|
93 | }
|
---|
94 | }
|
---|
95 | }
|
---|
96 |
|
---|
97 | chartingHelper.AddPoint(counter);
|
---|
98 | return base.Apply();
|
---|
99 | }
|
---|
100 | }
|
---|
101 | }
|
---|