Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/AfterMutationCombinedOperator.cs @ 10007

Last change on this file since 10007 was 9789, checked in by ascheibe, 11 years ago

#1886 fixed alglib reference and updated year and version information

File size: 4.8 KB
Line 
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
22using HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Optimization.Operators;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
31  [Item("AfterMutationCombinedOperator", "An operator that contains all operators that need to be executed after mutation.")]
32  [StorableClass]
33  public class AfterMutationCombinedOperator : CombinedOperator {
34    public ILookupParameter<IEvaluator> EvaluatorParameter {
35      get { return ((LookupParameter<IEvaluator>)Parameters["Evaluator"]); }
36    }
37    public IValueParameter<SingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
38      get { return (IValueParameter<SingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
39    }
40    public ValueParameter<IntValue> UpdateIntervalParameter {
41      get { return (ValueParameter<IntValue>)Parameters["UpdateInterval"]; }
42    }
43    public ILookupParameter<IntValue> GenerationsParameter {
44      get { return (ILookupParameter<IntValue>)Parameters["Generations"]; }
45    }
46
47    [Storable]
48    protected MutationPerformanceAnalyzer mAnalyzer;
49    [Storable]
50    protected VariableRemover varRemover;
51    [Storable]
52    protected IEvaluator evaluatorClone;
53    [Storable]
54    protected SolutionToPopulationAnalyzer solToPopAnalyzer;
55
56    [StorableConstructor]
57    protected AfterMutationCombinedOperator(bool deserializing) : base(deserializing) { }
58    protected AfterMutationCombinedOperator(AfterMutationCombinedOperator original, Cloner cloner)
59      : base(original, cloner) {
60      mAnalyzer = original.mAnalyzer != null ? (MutationPerformanceAnalyzer)original.mAnalyzer.Clone(cloner) : null;
61      varRemover = original.varRemover != null ? (VariableRemover)original.varRemover.Clone(cloner) : null;
62      solToPopAnalyzer = original.solToPopAnalyzer != null ? (SolutionToPopulationAnalyzer)original.solToPopAnalyzer.Clone(cloner) : null;
63    }
64
65    public AfterMutationCombinedOperator()
66      : base() {
67      Parameters.Add(new LookupParameter<IEvaluator>("Evaluator", "The operator which is used to evaluate new solutions."));
68      Parameters.Add(new ValueParameter<SingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator"));
69      Parameters.Add(new ValueParameter<IntValue>("UpdateInterval", "The interval in which the operator should be applied.", new IntValue(2)));
70      Parameters.Add(new LookupParameter<IntValue>("Generations", "Nr of generations."));
71
72      SimilarityCalculatorParameter.ValueChanged += new System.EventHandler(SimilarityCalculatorParameter_ValueChanged);
73    }
74
75    protected virtual void SimilarityCalculatorParameter_ValueChanged(object sender, System.EventArgs e) {
76      SimilarityCalculatorParameter.Value.QualityVariableName = "TSPTourLength";
77      SimilarityCalculatorParameter.Value.SolutionVariableName = "TSPTour";
78    }
79
80    public override IDeepCloneable Clone(Cloner cloner) {
81      return new AfterMutationCombinedOperator(this, cloner);
82    }
83
84    public override void InitializeOperators() {
85      evaluatorClone = (IEvaluator)EvaluatorParameter.ActualValue.Clone();
86      ((ILookupParameter)evaluatorClone.Parameters["Quality"]).ActualName = "TSPTourLengthM";
87      mAnalyzer = new MutationPerformanceAnalyzer();
88      varRemover = new VariableRemover();
89
90      solToPopAnalyzer = new SolutionToPopulationAnalyzer();
91      solToPopAnalyzer.ChartPostfixParameter.Value = new Data.StringValue("after Mutation");
92
93      Operators.Add(evaluatorClone);
94      Operators.Add(mAnalyzer);
95      Operators.Add(varRemover);
96      Operators.Add(solToPopAnalyzer);
97    }
98
99    public override IOperation Apply() {
100      if (GenerationsParameter.ActualValue.Value % UpdateIntervalParameter.Value.Value == 0) {
101        return base.Apply();
102      } else {
103        return base.BaseApply();
104      }
105    }
106  }
107}
Note: See TracBrowser for help on using the repository browser.