Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.4/ArtificialAntExpressionGrammar.cs @ 7030

Last change on this file since 7030 was 6813, checked in by gkronber, 13 years ago

#1479 corrected number of allowed subtrees of IfFoodAhead symbol

File size: 3.1 KB
RevLine 
[3223]1#region License Information
2/* HeuristicLab
[5445]3 * Copyright (C) 2002-2011 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
22
[4068]23using System.Collections.Generic;
[4722]24using HeuristicLab.Common;
[5688]25using HeuristicLab.Core;
[3223]26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
[3251]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3462]28using HeuristicLab.Problems.ArtificialAnt.Symbols;
[3223]29namespace HeuristicLab.Problems.ArtificialAnt {
[3251]30  [StorableClass]
[5688]31  [Item(Name = "ArtificialAntExpressionGrammar", Description = "The default grammar for an artificial ant problem.")]
[5686]32  public class ArtificialAntExpressionGrammar : SymbolicExpressionGrammar {
[3223]33
34    public ArtificialAntExpressionGrammar()
[5688]35      : base(ItemAttribute.GetName(typeof(ArtificialAntExpressionGrammar)), ItemAttribute.GetDescription(typeof(ArtificialAntExpressionGrammar))) {
[3294]36      Initialize();
[3223]37    }
[3993]38    [StorableConstructor]
39    protected ArtificialAntExpressionGrammar(bool deserializing) : base(deserializing) { }
[4722]40    protected ArtificialAntExpressionGrammar(ArtificialAntExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new ArtificialAntExpressionGrammar(this, cloner);
43    }
[3223]44
[3294]45    private void Initialize() {
46      var ifFoodAhead = new IfFoodAhead();
47      var prog2 = new Prog2();
48      var prog3 = new Prog3();
49      var move = new Move();
50      var left = new Left();
51      var right = new Right();
52      var allSymbols = new List<Symbol>() { ifFoodAhead, prog2, prog3, move, left, right };
53      var nonTerminalSymbols = new List<Symbol>() { ifFoodAhead, prog2, prog3 };
[3223]54
[3338]55      allSymbols.ForEach(s => AddSymbol(s));
[6813]56      SetSubtreeCount(ifFoodAhead, 2, 2);
[5686]57      SetSubtreeCount(prog2, 2, 2);
58      SetSubtreeCount(prog3, 3, 3);
59      SetSubtreeCount(move, 0, 0);
60      SetSubtreeCount(left, 0, 0);
61      SetSubtreeCount(right, 0, 0);
[3338]62
63      // each symbols is allowed as child of the start symbol
[5686]64      allSymbols.ForEach(s => AddAllowedChildSymbol(StartSymbol, s));
65      allSymbols.ForEach(s => AddAllowedChildSymbol(DefunSymbol, s));
[3338]66
67      // each symbol is allowed as child of all other symbols (except for terminals that have MaxSubtreeCount == 0
[5686]68      foreach (var parent in nonTerminalSymbols) {
69        foreach (var child in allSymbols) {
70          AddAllowedChildSymbol(parent, child);
[3223]71        }
[3294]72      }
[3223]73    }
74  }
75}
Note: See TracBrowser for help on using the repository browser.