Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.Algorithms/3.2/StandardGP.cs @ 2491

Last change on this file since 2491 was 2341, checked in by gkronber, 15 years ago

Merged changeset r2330:2340 from #720 refactoring branch to the trunk. (r2331, r2335, r2337, r2340)

File size: 5.3 KB
RevLine 
[1050]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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.Core;
23using HeuristicLab.Operators;
24using HeuristicLab.Selection;
25using HeuristicLab.Logging;
26using HeuristicLab.Data;
[2222]27using HeuristicLab.GP.Operators;
[1050]28
[2331]29namespace HeuristicLab.GP.Algorithms {
[1287]30  public class StandardGP : AlgorithmBase, IEditable {
31
[1857]32    public override string Name { get { return "StandardGP"; } }
[1287]33    public virtual int TournamentSize {
34      get { return GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data; }
35      set { GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data = value; }
[1050]36    }
[1287]37
38    public double FullTreeShakingFactor {
39      get { return GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data; }
40      set { GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data = value; }
[1050]41    }
42
[1287]43    public double OnePointShakingFactor {
44      get { return GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data; }
45      set { GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data = value; }
[1051]46    }
47
[1287]48    public override int PopulationSize {
49      get {
50        return base.PopulationSize;
51      }
52      set {
53        base.PopulationSize = value;
54        Parents = 2 * value;
55      }
[1051]56    }
57
[1287]58    public StandardGP()
59      : base() {
60      PopulationSize = 10000;
[2130]61      MaxGenerations = 500;
[1050]62      TournamentSize = 7;
63      MutationRate = 0.15;
[1052]64      Elites = 1;
[1287]65      MaxTreeSize = 100;
66      MaxTreeHeight = 10;
67      FullTreeShakingFactor = 0.1;
68      OnePointShakingFactor = 1.0;
69      SetSeedRandomly = true;
[1050]70    }
71
[2335]72    protected override IOperator CreateSelectionOperator() {
[1050]73      TournamentSelector selector = new TournamentSelector();
74      selector.Name = "Selector";
75      selector.GetVariableInfo("Selected").ActualName = "Parents";
76      selector.GetVariableInfo("GroupSize").Local = false;
77      selector.RemoveVariable("GroupSize");
78      selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize";
[1287]79      return selector;
80    }
[1050]81
[2335]82    protected override VariableInjector CreateGlobalInjector() {
83      VariableInjector globalInjector = base.CreateGlobalInjector();
[1287]84      globalInjector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", new IntData()));
85      globalInjector.AddVariable(new HeuristicLab.Core.Variable("FullTreeShakingFactor", new DoubleData()));
86      globalInjector.AddVariable(new HeuristicLab.Core.Variable("OnePointShakingFactor", new DoubleData()));
87      return globalInjector;
88    }
[1050]89
[2335]90    protected override IOperator CreateManipulationOperator() {
[1050]91      CombinedOperator manipulator = new CombinedOperator();
[1287]92      manipulator.Name = "Manipulator";
[1050]93      StochasticMultiBranch multibranch = new StochasticMultiBranch();
94      FullTreeShaker fullTreeShaker = new FullTreeShaker();
[1287]95      fullTreeShaker.GetVariableInfo("ShakingFactor").ActualName = "FullTreeShakingFactor";
[1050]96
97      OnePointShaker onepointShaker = new OnePointShaker();
[1287]98      onepointShaker.GetVariableInfo("ShakingFactor").ActualName = "OnePointShakingFactor";
[1050]99      ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation();
100      CutOutNodeManipulation cutOutNodeManipulation = new CutOutNodeManipulation();
101      DeleteSubTreeManipulation deleteSubTreeManipulation = new DeleteSubTreeManipulation();
102      SubstituteSubTreeManipulation substituteSubTreeManipulation = new SubstituteSubTreeManipulation();
103
[1051]104      IOperator[] manipulators = new IOperator[] {
105        onepointShaker, fullTreeShaker,
106        changeNodeTypeManipulation,
107        cutOutNodeManipulation,
108        deleteSubTreeManipulation,
109        substituteSubTreeManipulation};
110
111      DoubleArrayData probabilities = new DoubleArrayData(new double[manipulators.Length]);
[1287]112      for (int i = 0; i < manipulators.Length; i++) {
[1051]113        probabilities.Data[i] = 1.0;
114        multibranch.AddSubOperator(manipulators[i]);
115      }
116      multibranch.GetVariableInfo("Probabilities").Local = true;
117      multibranch.AddVariable(new HeuristicLab.Core.Variable("Probabilities", probabilities));
118
[1050]119      manipulator.OperatorGraph.AddOperator(multibranch);
120      manipulator.OperatorGraph.InitialOperator = multibranch;
121      return manipulator;
122    }
123
[1287]124    public virtual IEditor CreateEditor() {
[1051]125      return new StandardGpEditor(this);
126    }
127
[1052]128    public override IView CreateView() {
[1051]129      return new StandardGpEditor(this);
130    }
[1050]131  }
132}
Note: See TracBrowser for help on using the repository browser.