Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.cs @ 6093

Last change on this file since 6093 was 5445, checked in by swagner, 14 years ago

Updated year of copyrights (#1406)

File size: 3.2 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;
[3223]25using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
[4068]26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;
[3251]27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
[3462]28using HeuristicLab.Problems.ArtificialAnt.Symbols;
[3223]29namespace HeuristicLab.Problems.ArtificialAnt {
[3251]30  [StorableClass]
[3294]31  public class ArtificialAntExpressionGrammar : DefaultSymbolicExpressionGrammar {
[3223]32
33    public ArtificialAntExpressionGrammar()
[3338]34      : base() {
[3294]35      Initialize();
[3223]36    }
[3993]37    [StorableConstructor]
38    protected ArtificialAntExpressionGrammar(bool deserializing) : base(deserializing) { }
[4722]39    protected ArtificialAntExpressionGrammar(ArtificialAntExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new ArtificialAntExpressionGrammar(this, cloner);
42    }
[3223]43
[3294]44    private void Initialize() {
45      var ifFoodAhead = new IfFoodAhead();
46      var prog2 = new Prog2();
47      var prog3 = new Prog3();
48      var move = new Move();
49      var left = new Left();
50      var right = new Right();
51      var defun = new Defun();
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));
56      SetMinSubtreeCount(ifFoodAhead, 2);
57      SetMaxSubtreeCount(ifFoodAhead, 2);
58      SetMinSubtreeCount(prog2, 2);
59      SetMaxSubtreeCount(prog2, 2);
60      SetMinSubtreeCount(prog3, 3);
61      SetMaxSubtreeCount(prog3, 3);
62      SetMinSubtreeCount(move, 0);
63      SetMaxSubtreeCount(move, 0);
64      SetMinSubtreeCount(left, 0);
65      SetMaxSubtreeCount(left, 0);
66      SetMinSubtreeCount(right, 0);
67      SetMaxSubtreeCount(right, 0);
68
69      // each symbols is allowed as child of the start symbol
70      allSymbols.ForEach(s => SetAllowedChild(StartSymbol, s, 0));
71
72      // each symbol is allowed as child of all other symbols (except for terminals that have MaxSubtreeCount == 0
73      foreach (var parent in allSymbols) {
74        for (int argIndex = 0; argIndex < GetMaxSubtreeCount(parent); argIndex++) {
75          foreach (var child in allSymbols) {
76            SetAllowedChild(parent, child, argIndex);
[3294]77          }
[3223]78        }
[3294]79      }
[3223]80    }
81  }
82}
Note: See TracBrowser for help on using the repository browser.