Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs @ 11568

Last change on this file since 11568 was 11568, checked in by pfleck, 10 years ago

#2269 Added Parameters for ALPS-GA.

File size: 9.9 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 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 HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27using HeuristicLab.Operators;
28using HeuristicLab.Optimization;
29using HeuristicLab.Parameters;
30using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
31
32namespace HeuristicLab.Algorithms.ALPS {
33  [Item("ALPS Genetic Algorithm", "A genetic algorithm with an age-layered population structure.")]
34  [Creatable("Algorithms")]
35  [StorableClass]
36  public class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
37    public string Filename { get; set; }
38
39    #region Problem Properties
40    public override Type ProblemType {
41      get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
42    }
43    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
44      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
45      set { base.Problem = value; }
46    }
47    #endregion
48
49    #region Parameter Properties
50    private IValueParameter<IntValue> SeedParameter {
51      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
52    }
53    private IValueParameter<BoolValue> SetSeedRandomlyParameter {
54      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
55    }
56    private IValueParameter<MultiAnalyzer> AnalyzerParameter {
57      get { return (IValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
58    }
59    private IValueParameter<MultiAnalyzer> LayerAnalyzerParameter {
60      get { return (IValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; }
61    }
62    private IValueParameter<IntValue> NumberOfLayersParameter {
63      get { return (IValueParameter<IntValue>)Parameters["NumberOfLayers"]; }
64    }
65    private IValueParameter<IntValue> PopulationSizeParameter {
66      get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
67    }
68    private IValueParameter<IntValue> MaximumGenerationsParameter {
69      get { return (IValueParameter<IntValue>)Parameters["MaximumGenerations"]; }
70    }
71    private IValueParameter<AgingScheme> AgingSchemeParameter {
72      get { return (IValueParameter<AgingScheme>)Parameters["AgingScheme"]; }
73    }
74    private IValueParameter<IntValue> AgeGapParameter {
75      get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; }
76    }
77    private IValueParameter<IntArray> AgeLimitsParameter {
78      get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; }
79    }
80    private IValueParameter<ReductionOperation> AgeInheritanceParameter {
81      get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritance"]; }
82    }
83    public IConstrainedValueParameter<ISelector> SelectorParameter {
84      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
85    }
86    public IConstrainedValueParameter<ICrossover> CrossoverParameter {
87      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
88    }
89    private IValueParameter<PercentValue> MutationProbabilityParameter {
90      get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
91    }
92    public IConstrainedValueParameter<IManipulator> MutatorParameter {
93      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
94    }
95    private IValueParameter<IntValue> ElitesParameter {
96      get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
97    }
98    private IFixedValueParameter<BoolValue> ReevaluateElitesParameter {
99      get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; }
100    }
101    #endregion
102
103    #region Properties
104    public IntValue Seed {
105      get { return SeedParameter.Value; }
106      set { SeedParameter.Value = value; }
107    }
108    public BoolValue SetSeedRandomly {
109      get { return SetSeedRandomlyParameter.Value; }
110      set { SetSeedRandomlyParameter.Value = value; }
111    }
112    public MultiAnalyzer Analyzer {
113      get { return AnalyzerParameter.Value; }
114      set { AnalyzerParameter.Value = value; }
115    }
116    public MultiAnalyzer LayerAnalyzer {
117      get { return LayerAnalyzerParameter.Value; }
118      set { LayerAnalyzerParameter.Value = value; }
119    }
120    public IntValue NumberOfLayers {
121      get { return NumberOfLayersParameter.Value; }
122      set { NumberOfLayersParameter.Value = value; }
123    }
124
125    public IntValue PopulationSize {
126      get { return PopulationSizeParameter.Value; }
127      set { PopulationSizeParameter.Value = value; }
128    }
129    public IntValue MaximumGenerations {
130      get { return MaximumGenerationsParameter.Value; }
131      set { MaximumGenerationsParameter.Value = value; }
132    }
133    public AgingScheme AgingScheme {
134      get { return AgingSchemeParameter.Value; }
135      set { AgingSchemeParameter.Value = value; }
136    }
137    public IntValue AgeGap {
138      get { return AgeGapParameter.Value; }
139      set { AgeGapParameter.Value = value; }
140    }
141    public IntArray AgeLimits {
142      get { return AgeLimitsParameter.Value; }
143      set { AgeLimitsParameter.Value = value; }
144    }
145    public ReductionOperation AgeInheritance {
146      get { return AgeInheritanceParameter.Value; }
147      set { AgeInheritanceParameter.Value = value; }
148    }
149    public ISelector Selector {
150      get { return SelectorParameter.Value; }
151      set { SelectorParameter.Value = value; }
152    }
153    public ICrossover Crossover {
154      get { return CrossoverParameter.Value; }
155      set { CrossoverParameter.Value = value; }
156    }
157    public PercentValue MutationProbability {
158      get { return MutationProbabilityParameter.Value; }
159      set { MutationProbabilityParameter.Value = value; }
160    }
161    public IManipulator Mutator {
162      get { return MutatorParameter.Value; }
163      set { MutatorParameter.Value = value; }
164    }
165    public IntValue Elites {
166      get { return ElitesParameter.Value; }
167      set { ElitesParameter.Value = value; }
168    }
169    public bool ReevaluteElites {
170      get { return ReevaluateElitesParameter.Value.Value; }
171      set { ReevaluateElitesParameter.Value.Value = value; }
172    }
173    #endregion
174
175    [StorableConstructor]
176    private AlpsGeneticAlgorithm(bool deserializing)
177      : base(deserializing) { }
178    private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner)
179      : base(original, cloner) {
180      // TODO
181    }
182    public override IDeepCloneable Clone(Cloner cloner) {
183      return new AlpsGeneticAlgorithm(this, cloner);
184    }
185    public AlpsGeneticAlgorithm()
186      : base() {
187      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
188      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
189      Parameters.Add(new ValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
190      Parameters.Add(new ValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
191      Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(5)));
192      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions each layer.", new IntValue(20)));
193      Parameters.Add(new ValueParameter<IntValue>("MaximumGenerations", "The maximum number of generations that should be processed.", new IntValue(1000)));
194      Parameters.Add(new ValueParameter<AgingScheme>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new AgingScheme(AgingSchemes.Polynomial)));
195      Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(5)));
196      Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 1, 20, 45, 80, 125 })) { Hidden = true });
197      Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritance", "The operator for determining the age of an offspring based the parents age.", new ReductionOperation(ReductionOperations.Max)) { Hidden = true });
198      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
199      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
200      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
201      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
202      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
203      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
204    }
205  }
206}
Note: See TracBrowser for help on using the repository browser.