[8711] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[9789] | 3 | * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[8711] | 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;
|
---|
[9431] | 24 | using HeuristicLab.Data;
|
---|
[8711] | 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("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 | }
|
---|
[9431] | 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 | }
|
---|
[8711] | 46 |
|
---|
[9042] | 47 | [Storable]
|
---|
| 48 | protected MutationPerformanceAnalyzer mAnalyzer;
|
---|
| 49 | [Storable]
|
---|
| 50 | protected VariableRemover varRemover;
|
---|
| 51 | [Storable]
|
---|
| 52 | protected IEvaluator evaluatorClone;
|
---|
[9054] | 53 | [Storable]
|
---|
| 54 | protected SolutionToPopulationAnalyzer solToPopAnalyzer;
|
---|
[9042] | 55 |
|
---|
[8711] | 56 | [StorableConstructor]
|
---|
| 57 | protected AfterMutationCombinedOperator(bool deserializing) : base(deserializing) { }
|
---|
| 58 | protected AfterMutationCombinedOperator(AfterMutationCombinedOperator original, Cloner cloner)
|
---|
| 59 | : base(original, cloner) {
|
---|
[9054] | 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;
|
---|
[8711] | 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"));
|
---|
[9431] | 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."));
|
---|
[8711] | 71 |
|
---|
| 72 | SimilarityCalculatorParameter.ValueChanged += new System.EventHandler(SimilarityCalculatorParameter_ValueChanged);
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[9042] | 75 | protected virtual void SimilarityCalculatorParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
[8711] | 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() {
|
---|
[9042] | 85 | evaluatorClone = (IEvaluator)EvaluatorParameter.ActualValue.Clone();
|
---|
[8711] | 86 | ((ILookupParameter)evaluatorClone.Parameters["Quality"]).ActualName = "TSPTourLengthM";
|
---|
[9042] | 87 | mAnalyzer = new MutationPerformanceAnalyzer();
|
---|
| 88 | varRemover = new VariableRemover();
|
---|
[8711] | 89 |
|
---|
[9054] | 90 | solToPopAnalyzer = new SolutionToPopulationAnalyzer();
|
---|
| 91 | solToPopAnalyzer.ChartPostfixParameter.Value = new Data.StringValue("after Mutation");
|
---|
| 92 |
|
---|
[8711] | 93 | Operators.Add(evaluatorClone);
|
---|
| 94 | Operators.Add(mAnalyzer);
|
---|
| 95 | Operators.Add(varRemover);
|
---|
[9054] | 96 | Operators.Add(solToPopAnalyzer);
|
---|
[8711] | 97 | }
|
---|
[9431] | 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 | }
|
---|
[8711] | 106 | }
|
---|
| 107 | }
|
---|