[3223] | 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 |
|
---|
| 23 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 24 | using System.Collections.Generic;
|
---|
| 25 | using System;
|
---|
[3238] | 26 | using System.Linq;
|
---|
[3223] | 27 | using HeuristicLab.Core;
|
---|
[3251] | 28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[3257] | 29 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.GeneralSymbols;
|
---|
[3223] | 30 | namespace HeuristicLab.Problems.ArtificialAnt {
|
---|
[3251] | 31 | [StorableClass]
|
---|
[3294] | 32 | public class ArtificialAntExpressionGrammar : DefaultSymbolicExpressionGrammar {
|
---|
[3223] | 33 |
|
---|
| 34 | public ArtificialAntExpressionGrammar()
|
---|
[3294] | 35 | : base(0, 3, 0, 3) {
|
---|
| 36 | Initialize();
|
---|
[3223] | 37 | }
|
---|
| 38 |
|
---|
[3294] | 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);
|
---|
[3223] | 65 |
|
---|
[3294] | 66 | for (int i = 0; i < GetMaxSubTreeCount(invoke); i++) {
|
---|
| 67 | AddAllowedSymbols(invoke, i, sym);
|
---|
[3223] | 68 | }
|
---|
[3294] | 69 | }
|
---|
| 70 | foreach (var sym in nonTerminalSymbols) {
|
---|
| 71 | for (int argIndex = 0; argIndex < GetMaxSubTreeCount(sym); argIndex++) {
|
---|
| 72 | AddAllowedSymbols(sym, argIndex, invoke);
|
---|
[3223] | 73 | }
|
---|
[3294] | 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 | }
|
---|
[3223] | 80 | }
|
---|
[3294] | 81 | }
|
---|
[3223] | 82 |
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | }
|
---|