Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/ArchitectureAlteringOperators/RandomArchitectureAlteringOperator.cs @ 3294

Last change on this file since 3294 was 3294, checked in by gkronber, 14 years ago

Added first version of architecture altering operators for ADFs. #290 (Implement ADFs)

File size: 3.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 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 System.Linq;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Operators;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
31using System.Collections.Generic;
32using System.Text;
33
34namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.ArchitectureAlteringOperators {
35  /// <summary>
36  /// Manipulates a symbolic expression by applying one architecture altering operator randomly.
37  /// </summary>
38  [Item("RandomArchitectureAlteringOperator", "Manipulates a symbolic expression by applying one architecture altering operator randomly.")]
39  [StorableClass]
40  public class RandomArchitectureAlteringOperator : SymbolicExpressionTreeArchitectureAlteringOperator {
41    #region Parameter Properties
42    public IValueParameter<ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>> OperatorsParameter {
43      get { return (IValueParameter<ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>>)Parameters["Operators"]; }
44    }
45    #endregion
46    #region Properties
47    public ItemList<SymbolicExpressionTreeArchitectureAlteringOperator> Operators {
48      get { return OperatorsParameter.Value; }
49    }
50    #endregion
51
52    public RandomArchitectureAlteringOperator()
53      : base() {
54      var operators = new ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>();
55      operators.Add(new ArgumentCreater());
56      operators.Add(new ArgumentDeleter());
57      operators.Add(new ArgumentDuplicater());
58      operators.Add(new SubroutineCreater());
59      operators.Add(new SubroutineDeleter());
60      operators.Add(new SubroutineDuplicater());
61      Parameters.Add(new ValueParameter<ItemList<SymbolicExpressionTreeArchitectureAlteringOperator>>("Operators",
62        "The list of architecture altering operators from which a random operator should be called.",
63        operators));
64    }
65
66    public override void ModifyArchitecture(IRandom random, SymbolicExpressionTree tree, ISymbolicExpressionGrammar grammar, IntValue maxTreeSize, IntValue maxTreeHeight, IntValue maxFunctionDefiningBranches, IntValue maxFunctionArguments, out bool success) {
67      var selectedOperator = Operators[random.Next(Operators.Count)];
68      selectedOperator.ModifyArchitecture(random, tree, grammar, maxTreeSize, maxTreeHeight, maxFunctionDefiningBranches, maxFunctionArguments, out success);
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.