[12319] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[12319] | 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 | using System.Collections.Generic;
|
---|
[17837] | 23 | using HEAL.Attic;
|
---|
[12319] | 24 | using HeuristicLab.Common;
|
---|
| 25 |
|
---|
| 26 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
[17097] | 27 | [StorableType("70D190B2-22F4-41E5-9938-EFD1B14ECF43")]
|
---|
[12319] | 28 | public sealed class SimpleSymbolicExpressionGrammar : SymbolicExpressionGrammar {
|
---|
| 29 | [StorableConstructor]
|
---|
[17097] | 30 | private SimpleSymbolicExpressionGrammar(StorableConstructorFlag _) : base(_) { }
|
---|
[12319] | 31 | private SimpleSymbolicExpressionGrammar(SimpleSymbolicExpressionGrammar original, Cloner cloner) : base(original, cloner) { }
|
---|
| 32 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 33 | return new SimpleSymbolicExpressionGrammar(this, cloner);
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | public SimpleSymbolicExpressionGrammar()
|
---|
| 37 | : base("Simple Grammar", "A simple grammar containing symbols that differ only in their name.") {
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public void AddSymbol(string symbolName, int minimumArity, int maximumArity) {
|
---|
| 41 | AddSymbol(symbolName, string.Empty, minimumArity, maximumArity);
|
---|
| 42 | }
|
---|
| 43 | public void AddSymbol(string symbolName, string description, int minimumArity, int maximumArity) {
|
---|
| 44 | var symbol = new SimpleSymbol(symbolName, description, minimumArity, maximumArity);
|
---|
| 45 | AddSymbol(symbol);
|
---|
| 46 | SetSubtreeCount(symbol, symbol.MinimumArity, symbol.MaximumArity);
|
---|
| 47 |
|
---|
| 48 | foreach (var s in Symbols) {
|
---|
| 49 | if (s == ProgramRootSymbol) continue;
|
---|
| 50 | if (s.MaximumArity > 0) AddAllowedChildSymbol(s, symbol);
|
---|
| 51 |
|
---|
| 52 | if (s == DefunSymbol) continue;
|
---|
| 53 | if (s == StartSymbol) continue;
|
---|
| 54 | if (symbol.MaximumArity > 0) AddAllowedChildSymbol(symbol, s);
|
---|
| 55 | }
|
---|
| 56 | }
|
---|
[17837] | 57 | public void AddSymbols(IEnumerable<string> symbolNames, int minimumArity, int maximumArity) {
|
---|
| 58 | foreach (var symbolName in symbolNames) AddSymbol(symbolName, minimumArity, maximumArity);
|
---|
[12319] | 59 | }
|
---|
| 60 |
|
---|
| 61 | public void AddTerminalSymbol(string symbolName) {
|
---|
| 62 | AddTerminalSymbol(symbolName, string.Empty);
|
---|
| 63 | }
|
---|
| 64 | public void AddTerminalSymbol(string symbolName, string description) {
|
---|
| 65 | AddSymbol(symbolName, description, 0, 0);
|
---|
| 66 | }
|
---|
| 67 | public void AddTerminalSymbols(IEnumerable<string> symbolNames) {
|
---|
| 68 | foreach (var symbolName in symbolNames) AddTerminalSymbol(symbolName);
|
---|
| 69 | }
|
---|
| 70 |
|
---|
| 71 | }
|
---|
| 72 | }
|
---|