Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.SolutionCaching/3.3/PermutationEncoding/PermutationCrossoverPointcut.cs @ 10217

Last change on this file since 10217 was 10101, checked in by ascheibe, 11 years ago

#1886 added PermutationPointcut and refactored pointcut code

File size: 3.5 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("PermutationCrossoverPointcut", "Wraps a crossover and applies after-crossover actions.")]
35  [StorableClass]
36  public class PermutationCrossoverPointcut : CrossoverPointcut<IPermutationAdvice, IPermutationCrossover>, IPermutationCrossover, IPermutationPointcut {
37    public ILookupParameter<ItemArray<Permutation>> ParentsParameter {
38      get { return (ILookupParameter<ItemArray<Permutation>>)Parameters["Parents"]; }
39    }
40    public ILookupParameter<Permutation> ChildParameter {
41      get { return (ILookupParameter<Permutation>)Parameters["Child"]; }
42    }
43
44    [StorableConstructor]
45    protected PermutationCrossoverPointcut(bool deserializing) : base(deserializing) { }
46    protected PermutationCrossoverPointcut(PermutationCrossoverPointcut original, Cloner cloner) : base(original, cloner) { }
47
48    public PermutationCrossoverPointcut()
49      : base() {
50      Parameters.Add(new ScopeTreeLookupParameter<Permutation>("Parents", "The parent permutations which should be crossed."));
51      ParentsParameter.ActualName = "Permutation";
52      Parameters.Add(new LookupParameter<Permutation>("Child", "The child permutation resulting from the crossover."));
53      ChildParameter.ActualName = "Permutation";
54
55      foreach (Type t in ApplicationManager.Manager.GetTypes(typeof(IPermutationCrossover))) {
56        if ((!typeof(PermutationCrossoverPointcut).IsAssignableFrom(t)) &&
57          (!typeof(MultiOperator<IPermutationCrossover>).IsAssignableFrom(t))) {
58          CrossoversParameter.ValidValues.Add((IPermutationCrossover)Activator.CreateInstance(t));
59        }
60      }
61
62      ParameterizeCrossovers();
63    }
64
65    public override IDeepCloneable Clone(Cloner cloner) {
66      return new PermutationCrossoverPointcut(this, cloner);
67    }
68
69    private void ParameterizeCrossovers() {
70      foreach (IPermutationCrossover crossover in CrossoversParameter.ValidValues.OfType<IPermutationCrossover>()) {
71        crossover.ChildParameter.ActualName = ChildParameter.Name;
72        crossover.ParentsParameter.ActualName = ParentsParameter.Name;
73      }
74      foreach (IStochasticOperator crossover in CrossoversParameter.ValidValues.OfType<IStochasticOperator>()) {
75        crossover.RandomParameter.ActualName = RandomParameter.Name;
76      }
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.