1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 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 HeuristicLab.Common;
|
---|
23 | using HeuristicLab.Core;
|
---|
24 | using HEAL.Attic;
|
---|
25 | using System.Collections.Generic;
|
---|
26 | using System;
|
---|
27 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
28 | using HeuristicLab.Problems.DataAnalysis.Symbolic;
|
---|
29 |
|
---|
30 | namespace HeuristicLab.Problems.VarProMRGP {
|
---|
31 | [Item("VarProGrammar", "")]
|
---|
32 | [StorableType("E2FFA4F4-2301-4A28-BC6E-670A0D233262")]
|
---|
33 | public sealed class VarProGrammar : DataAnalysisGrammar {
|
---|
34 | [StorableConstructor]
|
---|
35 | private VarProGrammar(StorableConstructorFlag _) : base(_) { }
|
---|
36 |
|
---|
37 | private VarProGrammar(VarProGrammar orig, Cloner cloner) : base(orig, cloner) { }
|
---|
38 | public VarProGrammar() : base("VarProGrammar", "") {
|
---|
39 | Initialize();
|
---|
40 | }
|
---|
41 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
42 | return new VarProGrammar(this, cloner);
|
---|
43 | }
|
---|
44 |
|
---|
45 | private void Initialize() {
|
---|
46 | Symbol sumForLogSy = new Addition();
|
---|
47 | sumForLogSy.Name = "SimpleAdd";
|
---|
48 | Symbol mulSy = new Multiplication();
|
---|
49 | Symbol simpleMulSy = new Multiplication();
|
---|
50 | simpleMulSy.Name = "SimpleMul";
|
---|
51 | Symbol aqSy = new AnalyticQuotient();
|
---|
52 | Symbol logSy = new Logarithm();
|
---|
53 | Symbol expSy = new Exponential();
|
---|
54 |
|
---|
55 | var constSy = new Constant();
|
---|
56 | constSy.MinValue = -1;
|
---|
57 | constSy.MaxValue = 1;
|
---|
58 |
|
---|
59 | var constOneSy = new Constant();
|
---|
60 | constOneSy.Name = "<1.0>";
|
---|
61 | constOneSy.MinValue = 1;
|
---|
62 | constOneSy.MaxValue = 1;
|
---|
63 | constOneSy.ManipulatorMu = 0.0;
|
---|
64 | constOneSy.ManipulatorSigma = 0.0;
|
---|
65 | constOneSy.MultiplicativeManipulatorSigma = 0.0;
|
---|
66 |
|
---|
67 | var varSy = new DataAnalysis.Symbolic.Variable();
|
---|
68 | varSy.WeightMu = 1.0;
|
---|
69 | varSy.WeightSigma = 0.0;
|
---|
70 |
|
---|
71 | var allSymbols = new List<Symbol>() { sumForLogSy, mulSy, simpleMulSy, aqSy, logSy, expSy, constSy, constOneSy, varSy };
|
---|
72 |
|
---|
73 | foreach (var symb in allSymbols)
|
---|
74 | AddSymbol(symb);
|
---|
75 |
|
---|
76 | SetSubtreeCount(sumForLogSy, 2, 5);
|
---|
77 | SetSubtreeCount(simpleMulSy, 2, 5);
|
---|
78 | SetSubtreeCount(mulSy, 2, 4);
|
---|
79 |
|
---|
80 |
|
---|
81 | foreach (var funSymb in new[] { logSy, expSy }) {
|
---|
82 | SetSubtreeCount(funSymb, 1, 1);
|
---|
83 | }
|
---|
84 |
|
---|
85 | SetSubtreeCount(aqSy, 2, 2);
|
---|
86 | SetSubtreeCount(constSy, 0, 0);
|
---|
87 | SetSubtreeCount(constOneSy, 0, 0);
|
---|
88 | SetSubtreeCount(varSy, 0, 0);
|
---|
89 |
|
---|
90 | // allowed root symbols
|
---|
91 | foreach (var childSy in new[] { mulSy, varSy, logSy, expSy, aqSy }) {
|
---|
92 | AddAllowedChildSymbol(StartSymbol, childSy);
|
---|
93 | AddAllowedChildSymbol(DefunSymbol, childSy);
|
---|
94 | }
|
---|
95 |
|
---|
96 | // allowed under mul
|
---|
97 | foreach (var childSy in new[] { varSy, logSy, expSy }) {
|
---|
98 | AddAllowedChildSymbol(mulSy, childSy);
|
---|
99 | }
|
---|
100 |
|
---|
101 | // allowed for log:
|
---|
102 | AddAllowedChildSymbol(logSy, sumForLogSy);
|
---|
103 |
|
---|
104 | // allowed for exp:
|
---|
105 | AddAllowedChildSymbol(expSy, simpleMulSy);
|
---|
106 |
|
---|
107 | // allowed for simpleAdd arg 0:
|
---|
108 | AddAllowedChildSymbol(sumForLogSy, constOneSy, 0); // enforce log ( 1 + ...)
|
---|
109 |
|
---|
110 | // allowed for simpleAdd ars 1 - n:
|
---|
111 | for (int arg = 1; arg < this.GetMaximumSubtreeCount(sumForLogSy); arg++)
|
---|
112 | AddAllowedChildSymbol(sumForLogSy, simpleMulSy, arg);
|
---|
113 |
|
---|
114 | // allowed for simpleMul arg 0:
|
---|
115 | AddAllowedChildSymbol(simpleMulSy, constSy, 0);
|
---|
116 |
|
---|
117 | // allowed for simpleMul ars 1 - n:
|
---|
118 | for (int arg = 1; arg < this.GetMaximumSubtreeCount(simpleMulSy); arg++)
|
---|
119 | AddAllowedChildSymbol(simpleMulSy, varSy, arg);
|
---|
120 |
|
---|
121 | // allowed numerators for AQ:
|
---|
122 | foreach (var child in new[] { constOneSy, varSy, mulSy })
|
---|
123 | AddAllowedChildSymbol(aqSy, child, 0);
|
---|
124 |
|
---|
125 | // allowed denominator for AQ:
|
---|
126 | foreach (var child in new[] { varSy, sumForLogSy })
|
---|
127 | AddAllowedChildSymbol(aqSy, child, 1);
|
---|
128 | }
|
---|
129 | }
|
---|
130 | }
|
---|