Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GP.Grammar.Editor/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Grammars/Poly10Grammar.cs @ 6409

Last change on this file since 6409 was 6284, checked in by mkommend, 13 years ago

#1479: Created branch for grammar editing.

File size: 6.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2011 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
22using System.Collections.Generic;
23using System.Linq;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
29  [StorableClass]
30  [Item("Poly10Grammar", "Represents a grammar for modeling with fixed structures for the voest B1 MwDru target variable.")]
31  public class Poly10Grammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar {
32
33    [StorableConstructor]
34    protected Poly10Grammar(bool deserializing) : base(deserializing) { }
35    protected Poly10Grammar(Poly10Grammar original, Cloner cloner) : base(original, cloner) { }
36    public Poly10Grammar()
37      : base(ItemAttribute.GetName(typeof(Poly10Grammar)), ItemAttribute.GetDescription(typeof(TypeCoherentExpressionGrammar))) {
38      Initialize();
39    }
40    public override IDeepCloneable Clone(Cloner cloner) {
41      return new Poly10Grammar(this, cloner);
42    }
43
44    private void Initialize() {
45      var add = new Addition();
46      var sub = new Subtraction();
47      var mul = new Multiplication();
48      var div = new Division();
49
50      var constant = new Constant();
51      var variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
52
53      var fixedAdd1 = new Addition();
54      fixedAdd1.Name = "fixed Addition1";
55      fixedAdd1.Fixed = true;
56
57      var fixedAdd2 = new Addition();
58      fixedAdd2.Name = "fixed Addition2";
59      fixedAdd2.Fixed = true;
60
61      var fixedAdd3 = new Addition();
62      fixedAdd3.Name = "fixed Addition3";
63      fixedAdd3.Fixed = true;
64
65      var fixedMul1 = new Multiplication();
66      fixedMul1.Name = "fixed Multiplication1";
67      fixedMul1.Fixed = true;
68
69      var fixedMul2 = new Multiplication();
70      fixedMul2.Name = "fixed Multiplication2";
71      fixedMul2.Fixed = true;
72
73
74      #region fixed variables
75      var x1 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
76      x1.Name = "fixed X1";
77      x1.VariableNames = new List<string>() { "x1" };
78      x1.Fixed = true;
79
80
81      var x2 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
82      x2.Name = "fixed X2";
83      x2.VariableNames = new List<string>() { "x2" };
84      x2.Fixed = true;
85
86      var x3 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
87      x3.Name = "fixed X3";
88      x3.VariableNames = new List<string>() { "x3" };
89      x3.Fixed = true;
90
91      var x4 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
92      x4.Name = "fixed X4";
93      x4.VariableNames = new List<string>() { "x4" };
94      x4.Fixed = true;
95
96      var x5 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
97      x5.Name = "fixed X5";
98      x5.VariableNames = new List<string>() { "x5" };
99      x5.Fixed = true;
100
101      var x6 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
102      x6.Name = "fixed X6";
103      x6.VariableNames = new List<string>() { "x6" };
104      x6.Fixed = true;
105
106      var x7 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
107      x7.Name = "fixed X7";
108      x7.VariableNames = new List<string>() { "x7" };
109      x7.Fixed = true;
110
111      var x8 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
112      x8.Name = "fixed X8";
113      x8.VariableNames = new List<string>() { "x8" };
114      x8.Fixed = true;
115
116      var x9 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
117      x9.Name = "fixed X9";
118      x9.VariableNames = new List<string>() { "x9" };
119      x9.Fixed = true;
120
121      var x10 = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable();
122      x10.Name = "fixed X10";
123      x10.VariableNames = new List<string>() { "x10" };
124      x10.Fixed = true;
125      #endregion
126
127      var fixedTerminalSymbols = new List<HeuristicLab.Problems.DataAnalysis.Symbolic.Variable>() { x1, x2, x3, x4, x5, x6, x7, x8, x9, x10 };
128      var allSymbols = new List<Symbol>()
129        { add, sub, mul, div, constant, variableSymbol,
130          fixedAdd1,fixedMul1,fixedMul2}.Union(fixedTerminalSymbols);
131
132      var binaryFunctionSymbols = new List<Symbol>() { add, sub, mul, div };
133      var terminalSymbols = new List<Symbol>() { variableSymbol, constant };
134      var realValuedSymbols = binaryFunctionSymbols.Concat(terminalSymbols);
135
136      foreach (var symb in allSymbols)
137        AddSymbol(symb);
138      foreach (var terminalSymbol in terminalSymbols.Union(fixedTerminalSymbols)) {
139        SetSubtreeCount(terminalSymbol, 0, 0);
140      }
141      foreach (var binaryFun in binaryFunctionSymbols) {
142        SetSubtreeCount(binaryFun, 2, 2);
143      }
144      SetSubtreeCount(fixedAdd1, 3, 3);
145      SetSubtreeCount(fixedMul1, 3, 3);
146      SetSubtreeCount(fixedMul2, 3, 3);
147
148      AddAllowedChildSymbol(StartSymbol, fixedAdd1);
149      foreach (var symb in realValuedSymbols) {
150        AddAllowedChildSymbol(fixedAdd1, symb, 0);
151      }
152
153      AddAllowedChildSymbol(fixedAdd1, fixedMul1, 1);
154      AddAllowedChildSymbol(fixedAdd1, fixedMul2, 2);
155
156
157      AddAllowedChildSymbol(fixedMul1, x1, 0);
158      AddAllowedChildSymbol(fixedMul1, x7, 1);
159      AddAllowedChildSymbol(fixedMul1, x9, 2);
160
161      AddAllowedChildSymbol(fixedMul2, x3, 0);
162      AddAllowedChildSymbol(fixedMul2, x6, 1);
163      AddAllowedChildSymbol(fixedMul2, x10, 2);
164
165      foreach (var symb in binaryFunctionSymbols) {
166        foreach (var childSymb in realValuedSymbols) {
167          AddAllowedChildSymbol(symb, childSymb);
168        }
169      }
170    }
171  }
172}
Note: See TracBrowser for help on using the repository browser.