[8709] | 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 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
| 24 | using HeuristicLab.Operators;
|
---|
| 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 : MultiOperator<IOperator> {
|
---|
| 34 |
|
---|
| 35 | private CrossoverPerformanceAnalyzer cxAnalyzer;
|
---|
| 36 |
|
---|
| 37 | private ScopeParameter CurrentScopeParameter {
|
---|
| 38 | get { return (ScopeParameter)Parameters["CurrentScope"]; }
|
---|
| 39 | }
|
---|
| 40 | public IScope CurrentScope {
|
---|
| 41 | get { return CurrentScopeParameter.ActualValue; }
|
---|
| 42 | }
|
---|
| 43 | public ILookupParameter<IEvaluator> EvaluatorParameter {
|
---|
| 44 | get { return ((LookupParameter<IEvaluator>)Parameters["Evaluator"]); }
|
---|
| 45 | }
|
---|
| 46 | public IValueParameter<SingleObjectiveSolutionSimilarityCalculator> SimilarityCalculatorParameter {
|
---|
| 47 | get { return (IValueParameter<SingleObjectiveSolutionSimilarityCalculator>)Parameters["SimilarityCalculator"]; }
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | [StorableConstructor]
|
---|
| 51 | private AfterCrossoverCombinedOperator(bool deserializing) : base(deserializing) { }
|
---|
| 52 | private AfterCrossoverCombinedOperator(AfterCrossoverCombinedOperator original, Cloner cloner)
|
---|
| 53 | : base(original, cloner) {
|
---|
| 54 | }
|
---|
| 55 |
|
---|
| 56 | public AfterCrossoverCombinedOperator()
|
---|
| 57 | : base() {
|
---|
| 58 | Parameters.Add(new ScopeParameter("CurrentScope", "The current scope whose variables and sub-scopes should be removed."));
|
---|
| 59 | Parameters.Add(new LookupParameter<IEvaluator>("Evaluator", "The operator which is used to evaluate new solutions."));
|
---|
| 60 | Parameters.Add(new ValueParameter<SingleObjectiveSolutionSimilarityCalculator>("SimilarityCalculator"));
|
---|
| 61 |
|
---|
| 62 | SimilarityCalculatorParameter.ValueChanged += new System.EventHandler(SimilarityCalculatorParameter_ValueChanged);
|
---|
| 63 |
|
---|
| 64 | cxAnalyzer = new CrossoverPerformanceAnalyzer();
|
---|
| 65 | var varDuplicator = new VariableDuplicator();
|
---|
| 66 |
|
---|
| 67 | Operators.Add(cxAnalyzer);
|
---|
| 68 | Operators.Add(varDuplicator);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | void SimilarityCalculatorParameter_ValueChanged(object sender, System.EventArgs e) {
|
---|
| 72 | SimilarityCalculatorParameter.Value.QualityVariableName = "TSPTourLength";
|
---|
| 73 | SimilarityCalculatorParameter.Value.SolutionVariableName = "TSPTour";
|
---|
| 74 | cxAnalyzer.SimilarityCalculatorParameter.Value = SimilarityCalculatorParameter.Value;
|
---|
| 75 | }
|
---|
| 76 |
|
---|
| 77 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 78 | return new AfterCrossoverCombinedOperator(this, cloner);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | public override IOperation Apply() {
|
---|
| 82 | if (!Operators.Contains(EvaluatorParameter.ActualValue)) {
|
---|
| 83 | Operators.Insert(0, EvaluatorParameter.ActualValue);
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | OperationCollection next = new OperationCollection(base.Apply());
|
---|
| 87 | OperationCollection inner = new OperationCollection();
|
---|
| 88 | inner.Parallel = false;
|
---|
| 89 |
|
---|
| 90 | for (int i = 0; i < Operators.Count; i++) {
|
---|
| 91 | inner.Add(ExecutionContext.CreateOperation(Operators[i], CurrentScope));
|
---|
| 92 | }
|
---|
| 93 | next.Insert(0, inner);
|
---|
| 94 | return next;
|
---|
| 95 | }
|
---|
| 96 | }
|
---|
| 97 | }
|
---|