Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 4077 was 4068, checked in by swagner, 14 years ago

Sorted usings and removed unused usings in entire solution (#1094)

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