Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs @ 7355

Last change on this file since 7355 was 7259, checked in by swagner, 13 years ago

Updated year of copyrights to 2012 (#1716)

File size: 3.4 KB
RevLine 
[3223]1#region License Information
2/* HeuristicLab
[7259]3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[3223]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
[4068]22using System;
[4722]23using HeuristicLab.Common;
[3223]24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
[5499]29namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
[3223]30  /// <summary>
[3237]31  /// A base class for operators that perform a crossover of symbolic expression trees.
[3223]32  /// </summary>
[3237]33  [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")]
[3223]34  [StorableClass]
[3534]35  public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCrossover {
[3294]36    private const string ParentsParameterName = "Parents";
37    private const string ChildParameterName = "Child";
[5499]38    #region Parameter Properties
[5510]39    public ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter {
40      get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; }
[3223]41    }
[5510]42    public ILookupParameter<ISymbolicExpressionTree> ChildParameter {
43      get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ChildParameterName]; }
[3223]44    }
[5499]45    #endregion
46    #region Properties
[5510]47    public ItemArray<ISymbolicExpressionTree> Parents {
[5499]48      get { return ParentsParameter.ActualValue; }
[3223]49    }
[5510]50    public ISymbolicExpressionTree Child {
[5499]51      get { return ChildParameter.ActualValue; }
52      set { ChildParameter.ActualValue = value; }
[3237]53    }
[5499]54    #endregion
[4722]55    [StorableConstructor]
56    protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { }
57    protected SymbolicExpressionTreeCrossover(SymbolicExpressionTreeCrossover original, Cloner cloner) : base(original, cloner) { }
[3237]58    protected SymbolicExpressionTreeCrossover()
[3223]59      : base() {
[5510]60      Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed."));
61      Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));
[3223]62    }
63
64    public sealed override IOperation Apply() {
[5499]65      if (Parents.Length != 2)
[3237]66        throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators.");
67
[5510]68      ISymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]);
[3237]69
[5499]70      Child = result;
[3223]71      return base.Apply();
72    }
73
[5510]74    protected abstract ISymbolicExpressionTree Cross(IRandom random,
75      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1);
[3223]76  }
[3294]77}
Note: See TracBrowser for help on using the repository browser.