Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/MutationPointcut.cs @ 10635

Last change on this file since 10635 was 10102, checked in by ascheibe, 11 years ago

#1886 added mutation pointcuts for realvector and permutation encodings

File size: 3.1 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.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28using HeuristicLab.PluginInfrastructure;
29
30namespace HeuristicLab.Analysis.SolutionCaching {
31  [StorableClass]
32  public abstract class MutationPointcut<TA, TM> : SingleSuccessorOperator, IManipulator, IStochasticOperator, IPointcut
33    where TA : class, IAdvice
34    where TM : class, IManipulator {
35    protected const string AdviceParameterName = "Advice";
36    protected const string MutatorsParameterName = "Mutators";
37
38    public ConstrainedValueParameter<TM> MutatorsParameter {
39      get { return (ConstrainedValueParameter<TM>)Parameters[MutatorsParameterName]; }
40    }
41    public ConstrainedValueParameter<TA> AdviceParameter {
42      get { return (ConstrainedValueParameter<TA>)Parameters[AdviceParameterName]; }
43    }
44    public ILookupParameter<IRandom> RandomParameter {
45      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
46    }
47
48    [StorableConstructor]
49    protected MutationPointcut(bool deserializing) : base(deserializing) { }
50    protected MutationPointcut(MutationPointcut<TA, TM> original, Cloner cloner) : base(original, cloner) { }
51
52    public MutationPointcut()
53      : base() {
54      var advices = new ConstrainedValueParameter<TA>(AdviceParameterName,
55        "Advice to introduce after crossover");
56      foreach (var a in ApplicationManager.Manager.GetInstances<TA>()) {
57        advices.ValidValues.Add(a);
58      }
59      Parameters.Add(advices);
60      Parameters.Add(new LookupParameter<IRandom>("Random", "The random number generator to use."));
61      Parameters.Add(new ConstrainedValueParameter<TM>(MutatorsParameterName, "The mutators."));
62    }
63
64    public override IOperation Apply() {
65      IOperation successor = base.Apply();
66      IOperation mutationOperation = ExecutionContext.CreateChildOperation(MutatorsParameter.Value);
67      IOperation adviceOperation = ExecutionContext.CreateChildOperation(AdviceParameter.Value);
68
69      var opCol = new OperationCollection();
70      opCol.Add(mutationOperation);
71      opCol.Add(adviceOperation);
72      if (successor != null)
73        opCol.Add(successor);
74
75      return opCol;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.