Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/PermutationEncoding/PermutationMutationPointcut.cs @ 10102

Last change on this file since 10102 was 10102, checked in by ascheibe, 10 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 System;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.PermutationEncoding;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31using HeuristicLab.PluginInfrastructure;
32
33namespace HeuristicLab.Analysis.SolutionCaching.PermutationEncoding {
34  [Item("PermutationMutationPointcut", "Wraps a mutator and applies after-mutation actions.")]
35  [StorableClass]
36  public class PermutationMutationPointcut : MutationPointcut<IPermutationAdvice, IPermutationManipulator>, IPermutationManipulator, IPermutationPointcut {
37    public ILookupParameter<Permutation> PermutationParameter {
38      get { return (ILookupParameter<Permutation>)Parameters["Permutation"]; }
39    }
40
41    [StorableConstructor]
42    protected PermutationMutationPointcut(bool deserializing) : base(deserializing) { }
43    protected PermutationMutationPointcut(PermutationMutationPointcut original, Cloner cloner) : base(original, cloner) { }
44
45    public PermutationMutationPointcut()
46      : base() {
47      Parameters.Add(new LookupParameter<Permutation>("Permutation", "The permutation that is being manipulated."));
48
49      foreach (Type t in ApplicationManager.Manager.GetTypes(typeof(IPermutationManipulator))) {
50        if ((!typeof(PermutationMutationPointcut).IsAssignableFrom(t)) &&
51          (!typeof(MultiOperator<IPermutationManipulator>).IsAssignableFrom(t))) {
52          MutatorsParameter.ValidValues.Add((IPermutationManipulator)Activator.CreateInstance(t));
53        }
54      }
55
56      ParameterizeManipulators();
57    }
58
59    public override IDeepCloneable Clone(Cloner cloner) {
60      return new PermutationMutationPointcut(this, cloner);
61    }
62
63    private void ParameterizeManipulators() {
64      foreach (IPermutationManipulator manipulator in MutatorsParameter.ValidValues.OfType<IPermutationManipulator>()) {
65        manipulator.PermutationParameter.ActualName = PermutationParameter.Name;
66      }
67      foreach (IStochasticOperator op in MutatorsParameter.ValidValues.OfType<IStochasticOperator>()) {
68        op.RandomParameter.ActualName = RandomParameter.Name;
69      }
70    }
71  }
72}
Note: See TracBrowser for help on using the repository browser.