Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Problems.ArtificialAnt/3.3/ArtificialAntExpressionGrammar.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.1 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 HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
24using System.Collections.Generic;
25using System;
26using System.Linq;
27using HeuristicLab.Core;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
30namespace HeuristicLab.Problems.ArtificialAnt {
31  [StorableClass]
32  public class ArtificialAntExpressionGrammar : DefaultSymbolicExpressionGrammar {
33
34    public ArtificialAntExpressionGrammar()
35      : base(0, 3, 0, 3) {
36      Initialize();
37    }
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 invoke = new InvokeFunction();
48      var allSymbols = new List<Symbol>() { ifFoodAhead, prog2, prog3, move, left, right };
49      var nonTerminalSymbols = new List<Symbol>() { ifFoodAhead, prog2, prog3 };
50      SetMinSubTreeCount(ifFoodAhead, 2);
51      SetMaxSubTreeCount(ifFoodAhead, 2);
52      SetMinSubTreeCount(prog2, 2);
53      SetMaxSubTreeCount(prog2, 2);
54      SetMinSubTreeCount(prog3, 3);
55      SetMaxSubTreeCount(prog3, 3);
56      SetMinSubTreeCount(move, 0);
57      SetMaxSubTreeCount(move, 0);
58      SetMinSubTreeCount(left, 0);
59      SetMaxSubTreeCount(left, 0);
60      SetMinSubTreeCount(right, 0);
61      SetMaxSubTreeCount(right, 0);
62      foreach (var sym in allSymbols) {
63        AddAllowedSymbols(StartSymbol, 0, sym);
64        AddAllowedSymbols(defun, 0, sym);
65
66        for (int i = 0; i < GetMaxSubTreeCount(invoke); i++) {
67          AddAllowedSymbols(invoke, i, sym);
68        }
69      }
70      foreach (var sym in nonTerminalSymbols) {
71        for (int argIndex = 0; argIndex < GetMaxSubTreeCount(sym); argIndex++) {
72          AddAllowedSymbols(sym, argIndex, invoke);
73        }
74      }
75      foreach (var nonTerminal in nonTerminalSymbols) {
76        foreach (var child in allSymbols) {
77          for (int argIndex = 0; argIndex < GetMaxSubTreeCount(nonTerminal); argIndex++) {
78            AddAllowedSymbols(nonTerminal, argIndex, child);
79          }
80        }
81      }
82
83    }
84  }
85}
Note: See TracBrowser for help on using the repository browser.