[7439] | 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 |
|
---|
| 22 | using System;
|
---|
| 23 | using HeuristicLab.Common;
|
---|
| 24 | using HeuristicLab.Core;
|
---|
| 25 | using HeuristicLab.Parameters;
|
---|
| 26 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 27 |
|
---|
| 28 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
| 29 | /// <summary>
|
---|
| 30 | /// A base class for operators that perform a crossover of symbolic expression trees.
|
---|
| 31 | /// </summary>
|
---|
| 32 | [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")]
|
---|
| 33 | [StorableClass]
|
---|
[9083] | 34 | public abstract class SymbolicExpressionTreeCrossover : TracingSymbolicExpressionTreeOperator, ISymbolicExpressionTreeCrossover {
|
---|
[7439] | 35 | private const string ParentsParameterName = "Parents";
|
---|
| 36 | private const string ChildParameterName = "Child";
|
---|
| 37 | #region Parameter Properties
|
---|
| 38 | public ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter {
|
---|
| 39 | get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; }
|
---|
| 40 | }
|
---|
| 41 | public ILookupParameter<ISymbolicExpressionTree> ChildParameter {
|
---|
| 42 | get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ChildParameterName]; }
|
---|
| 43 | }
|
---|
| 44 | #endregion
|
---|
| 45 | #region Properties
|
---|
| 46 | public ItemArray<ISymbolicExpressionTree> Parents {
|
---|
| 47 | get { return ParentsParameter.ActualValue; }
|
---|
| 48 | }
|
---|
| 49 | public ISymbolicExpressionTree Child {
|
---|
| 50 | get { return ChildParameter.ActualValue; }
|
---|
| 51 | set { ChildParameter.ActualValue = value; }
|
---|
| 52 | }
|
---|
| 53 | #endregion
|
---|
| 54 | [StorableConstructor]
|
---|
| 55 | protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { }
|
---|
| 56 | protected SymbolicExpressionTreeCrossover(SymbolicExpressionTreeCrossover original, Cloner cloner) : base(original, cloner) { }
|
---|
| 57 | protected SymbolicExpressionTreeCrossover()
|
---|
| 58 | : base() {
|
---|
| 59 | Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
|
---|
| 60 | Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
|
---|
[9083] | 61 | ParentsParameter.ActualName = "SymbolicExpressionTree";
|
---|
| 62 | ChildParameter.ActualName = "SymbolicExpressionTree";
|
---|
[7439] | 63 | }
|
---|
| 64 |
|
---|
| 65 | public sealed override IOperation Apply() {
|
---|
| 66 | if (Parents.Length != 2)
|
---|
| 67 | throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators.");
|
---|
| 68 |
|
---|
[7522] | 69 | ISymbolicExpressionTree result = Crossover(Random, Parents[0], Parents[1]);
|
---|
[7439] | 70 |
|
---|
| 71 | Child = result;
|
---|
| 72 | return base.Apply();
|
---|
| 73 | }
|
---|
| 74 |
|
---|
[7522] | 75 | public abstract ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
|
---|
[7439] | 76 | }
|
---|
[7792] | 77 | }
|
---|