1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2013 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 | using HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HeuristicLab.Data;
|
---|
25 | using HeuristicLab.Optimization;
|
---|
26 | using HeuristicLab.Optimization.Operators;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
|
---|
31 | [Item("AfterCrossoverCombinedOperator", "An operator that contains all operators that need to be executed after crossover.")]
|
---|
32 | [StorableClass]
|
---|
33 | public class AfterCrossoverCombinedOperator : CombinedOperator {
|
---|
34 | [Storable]
|
---|
35 | protected CrossoverPerformanceAnalyzer cxAnalyzer;
|
---|
36 |
|
---|
37 | [Storable]
|
---|
38 | protected SolutionToPopulationAnalyzer solToPopAnalyzer;
|
---|
39 |
|
---|
40 | [Storable]
|
---|
41 | protected VariableDuplicator varDuplicator;
|
---|
42 |
|
---|
43 | [Storable]
|
---|
44 | protected WorstQualityAnalyzer wqAnalyzer;
|
---|
45 |
|
---|
46 | [Storable]
|
---|
47 | protected SelectionPressureAnalyzer selPressureAnalyzer;
|
---|
48 |
|
---|
49 | public ILookupParameter<IEvaluator> EvaluatorParameter {
|
---|
50 | get { return ((LookupParameter<IEvaluator>)Parameters["Evaluator"]); }
|
---|
51 | }
|
---|
52 | public IValueParameter<SingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
53 | get { return (IValueParameter<SingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
54 | }
|
---|
55 | public ValueParameter<IntValue> UpdateIntervalParameter {
|
---|
56 | get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; }
|
---|
57 | }
|
---|
58 | public ILookupParameter<IntValue> GenerationsParameter {
|
---|
59 | get { return (ILookupParameter<IntValue>)Parameters["Generations"]; }
|
---|
60 | }
|
---|
61 |
|
---|
62 | [StorableConstructor]
|
---|
63 | protected AfterCrossoverCombinedOperator(bool deserializing) : base(deserializing) { }
|
---|
64 | protected AfterCrossoverCombinedOperator(AfterCrossoverCombinedOperator original, Cloner cloner)
|
---|
65 | : base(original, cloner) {
|
---|
66 | cxAnalyzer = original.cxAnalyzer != null ? (CrossoverPerformanceAnalyzer)original.cxAnalyzer.Clone(cloner) : null;
|
---|
67 | varDuplicator = original.varDuplicator != null ? (VariableDuplicator)original.cxAnalyzer.Clone(cloner) : null;
|
---|
68 | solToPopAnalyzer = original.solToPopAnalyzer != null ? (SolutionToPopulationAnalyzer)original.solToPopAnalyzer.Clone(cloner) : null;
|
---|
69 | selPressureAnalyzer = original.selPressureAnalyzer != null ? (SelectionPressureAnalyzer)original.selPressureAnalyzer.Clone(cloner) : null;
|
---|
70 | }
|
---|
71 |
|
---|
72 | public AfterCrossoverCombinedOperator()
|
---|
73 | : base() {
|
---|
74 | Parameters.Add(new LookupParameter<IEvaluator>("Evaluator", "The operator which is used to evaluate new solutions."));
|
---|
75 | Parameters.Add(new ValueParameter<SingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator"));
|
---|
76 | Parameters.Add(new ValueParameter<IntValue>("UpdateInterval", "The interval in which the operator should be applied.", new IntValue(2)));
|
---|
77 | Parameters.Add(new LookupParameter<IntValue>("Generations", "Nr of generations."));
|
---|
78 |
|
---|
79 | SimilarityCalculatorParameter.ValueChanged += new System.EventHandler(SimilarityCalculatorParameter_ValueChanged);
|
---|
80 | }
|
---|
81 |
|
---|
82 | protected virtual void SimilarityCalculatorParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
83 | SimilarityCalculatorParameter.Value.QualityVariableName = "TSPTourLength";
|
---|
84 | SimilarityCalculatorParameter.Value.SolutionVariableName = "TSPTour";
|
---|
85 | }
|
---|
86 |
|
---|
87 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
88 | return new AfterCrossoverCombinedOperator(this, cloner);
|
---|
89 | }
|
---|
90 |
|
---|
91 | public override void InitializeOperators() {
|
---|
92 | cxAnalyzer = new CrossoverPerformanceAnalyzer();
|
---|
93 | cxAnalyzer.SimilarityCalculatorParameter.Value = SimilarityCalculatorParameter.Value;
|
---|
94 | varDuplicator = new VariableDuplicator();
|
---|
95 | solToPopAnalyzer = new SolutionToPopulationAnalyzer();
|
---|
96 | solToPopAnalyzer.ChartPostfixParameter.Value = new Data.StringValue("after Crossover");
|
---|
97 | wqAnalyzer = new WorstQualityAnalyzer();
|
---|
98 | selPressureAnalyzer = new SelectionPressureAnalyzer();
|
---|
99 |
|
---|
100 | Operators.Add(wqAnalyzer);
|
---|
101 | Operators.Add(EvaluatorParameter.ActualValue);
|
---|
102 | Operators.Add(cxAnalyzer);
|
---|
103 | Operators.Add(varDuplicator);
|
---|
104 | Operators.Add(solToPopAnalyzer);
|
---|
105 | Operators.Add(selPressureAnalyzer);
|
---|
106 | }
|
---|
107 |
|
---|
108 | public override IOperation InstrumentedApply() {
|
---|
109 | if (GenerationsParameter.ActualValue.Value % UpdateIntervalParameter.Value.Value == 0) {
|
---|
110 | return base.InstrumentedApply();
|
---|
111 | } else {
|
---|
112 | return base.BaseApply();
|
---|
113 | }
|
---|
114 | }
|
---|
115 | }
|
---|
116 | }
|
---|