Free cookie consent management tool by TermsFeed Policy Generator

source: branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/CombinedIntegerVectorCrossover.cs @ 9372

Last change on this file since 9372 was 9089, checked in by sforsten, 12 years ago

#1980:

  • added ConditionActionClassificationProblem
  • added ConditionActionEncoding
  • added Manipulators, Crossovers and an LCSAdaptedGeneticAlgorithm
  • changed LearningClassifierSystemMainLoop
File size: 3.5 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Encodings.IntegerVectorEncoding;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30
31namespace HeuristicLab.Encodings.CombinedIntegerVectorEncoding {
32  /// <summary>
33  /// A base class for operators that perform a crossover of combined int-valued vectors.
34  /// </summary>
35  [Item("CombinedIntegerVectorCrossover", "A base class for operators that perform a crossover of combined int-valued vectors.")]
36  [StorableClass]
37  public abstract class CombinedIntegerVectorCrossover : SingleSuccessorOperator, IIntegerVectorOperator, ICombinedIntegerVectorCrossover, ICombinedIntegerVectorOperator, ICrossover, IStochasticOperator, IOperator, IParameterizedNamedItem, INamedItem, IParameterizedItem, IItem, IContent, IDeepCloneable, ICloneable {
38    public override bool CanChangeName {
39      get { return false; }
40    }
41    public ILookupParameter<IRandom> RandomParameter {
42      get { return (LookupParameter<IRandom>)Parameters["Random"]; }
43    }
44    public ILookupParameter<ItemArray<CombinedIntegerVector>> ParentsParameter {
45      get { return (ScopeTreeLookupParameter<CombinedIntegerVector>)Parameters["Parents"]; }
46    }
47    public ILookupParameter<CombinedIntegerVector> ChildParameter {
48      get { return (ILookupParameter<CombinedIntegerVector>)Parameters["Child"]; }
49    }
50
51    [StorableConstructor]
52    protected CombinedIntegerVectorCrossover(bool deserializing) : base(deserializing) { }
53    protected CombinedIntegerVectorCrossover(CombinedIntegerVectorCrossover original, Cloner cloner) : base(original, cloner) { }
54    protected CombinedIntegerVectorCrossover()
55      : base() {
56      Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators."));
57      Parameters.Add(new ScopeTreeLookupParameter<CombinedIntegerVector>("Parents", "The parent vectors which should be crossed."));
58      ParentsParameter.ActualName = "CombinedIntegerVector";
59      Parameters.Add(new LookupParameter<CombinedIntegerVector>("Child", "The child vector resulting from the crossover."));
60      ChildParameter.ActualName = "CombinedIntegerVector";
61    }
62
63    public sealed override IOperation Apply() {
64      ChildParameter.ActualValue = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue);
65      return base.Apply();
66    }
67
68    protected abstract CombinedIntegerVector Cross(IRandom random, ItemArray<CombinedIntegerVector> parents);
69  }
70}
Note: See TracBrowser for help on using the repository browser.