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 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using System.Text;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using System.Xml;
|
---|
28 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding {
|
---|
31 | [StorableClass]
|
---|
32 | [Item("SymbolicExpressionGrammar", "Represents a grammar that defines the syntax of symbolic expression trees.")]
|
---|
33 | public class SymbolicExpressionGrammar : Item, ISymbolicExpressionGrammar {
|
---|
34 | //private List<Symbol> symbols = new List<Symbol>();
|
---|
35 | //public IEnumerable<Symbol> Symbols {
|
---|
36 | // get { return symbols; }
|
---|
37 | //}
|
---|
38 |
|
---|
39 | // internal implementation of a symbol for the start symbol
|
---|
40 | private class EmptySymbol : Symbol {
|
---|
41 | }
|
---|
42 |
|
---|
43 | private Dictionary<Symbol, Dictionary<int, IEnumerable<Symbol>>> allowedSymbols;
|
---|
44 |
|
---|
45 | public SymbolicExpressionGrammar()
|
---|
46 | : base() {
|
---|
47 | startSymbol = new EmptySymbol();
|
---|
48 | allowedSymbols = new Dictionary<Symbol, Dictionary<int, IEnumerable<Symbol>>>();
|
---|
49 | }
|
---|
50 |
|
---|
51 | //public void AddSymbol(Symbol symbol) {
|
---|
52 | // if (!symbols.Contains(symbol)) {
|
---|
53 | // symbols.Add(symbol);
|
---|
54 | // symbol.ToStringChanged += new EventHandler(symbol_ToStringChanged);
|
---|
55 |
|
---|
56 | // OnToStringChanged();
|
---|
57 | // }
|
---|
58 | //}
|
---|
59 |
|
---|
60 | //public void RemoveSymbol(Symbol symbol) {
|
---|
61 | // symbols.Remove(symbol);
|
---|
62 | // symbol.ToStringChanged -= new EventHandler(symbol_ToStringChanged);
|
---|
63 |
|
---|
64 | // // remove the operator from the allowed sub-functions of all functions
|
---|
65 | // foreach (Symbol f in Symbols) {
|
---|
66 | // for (int i = 0; i < f.MaxSubTrees; i++) {
|
---|
67 | // f.RemoveAllowedSubFunction(symbol, i);
|
---|
68 | // }
|
---|
69 | // }
|
---|
70 | // OnToStringChanged();
|
---|
71 | //}
|
---|
72 |
|
---|
73 | private void symbol_ToStringChanged(object sender, EventArgs e) {
|
---|
74 | OnToStringChanged();
|
---|
75 | }
|
---|
76 |
|
---|
77 | #region ISymbolicExpressionGrammar Members
|
---|
78 |
|
---|
79 | public Symbol startSymbol;
|
---|
80 | public Symbol StartSymbol {
|
---|
81 | get { return startSymbol; }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public IEnumerable<Symbol> AllowedSymbols(Symbol parent, int argumentIndex) {
|
---|
85 | return allowedSymbols[parent][argumentIndex];
|
---|
86 | }
|
---|
87 |
|
---|
88 | public int MinimalExpressionLength(Symbol start) {
|
---|
89 | throw new NotImplementedException();
|
---|
90 | }
|
---|
91 |
|
---|
92 | public int MaximalExpressionLength(Symbol start) {
|
---|
93 | throw new NotImplementedException();
|
---|
94 | }
|
---|
95 |
|
---|
96 | public int MinimalExpressionDepth(Symbol start) {
|
---|
97 | throw new NotImplementedException();
|
---|
98 | }
|
---|
99 |
|
---|
100 | public int MinSubTrees(Symbol start) {
|
---|
101 | throw new NotImplementedException();
|
---|
102 | }
|
---|
103 |
|
---|
104 | public int MaxSubTrees(Symbol start) {
|
---|
105 | throw new NotImplementedException();
|
---|
106 | }
|
---|
107 |
|
---|
108 | #endregion
|
---|
109 | }
|
---|
110 | }
|
---|