Changeset 5750 for branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4
- Timestamp:
- 03/18/11 12:50:28 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4
- Files:
-
- 1 edited
- 3 copied
- 3 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationExpressionGrammar.cs
r5745 r5750 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 26 using HeuristicLab.Problems.DataAnalysis.Symbolic; 25 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Symbols;27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 28 29 29 namespace HeuristicLab.Problems.ExternalEvaluation.GP { 30 30 [StorableClass] 31 [Item(" FullFunctionalExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")]32 public class FullFunctionalExpressionGrammar : DefaultSymbolicExpressionGrammar {31 [Item("ExternalEvaluationExpressionGrammar", "Represents a grammar for functional expressions using all available functions.")] 32 public class ExternalEvaluationExpressionGrammar : SymbolicExpressionGrammar, ISymbolicDataAnalysisGrammar { 33 33 [Storable] 34 private HeuristicLab.Problems. ExternalEvaluation.GP.Variable variableSymbol;34 private HeuristicLab.Problems.DataAnalysis.Symbolic.Variable variableSymbol; 35 35 [StorableConstructor] 36 protected FullFunctionalExpressionGrammar(bool deserializing) : base(deserializing) { }37 protected FullFunctionalExpressionGrammar(FullFunctionalExpressionGrammar original, Cloner cloner) : base(original, cloner) { }36 protected ExternalEvaluationExpressionGrammar(bool deserializing) : base(deserializing) { } 37 protected ExternalEvaluationExpressionGrammar(ExternalEvaluationExpressionGrammar original, Cloner cloner) : base(original, cloner) { } 38 38 public override IDeepCloneable Clone(Cloner cloner) { 39 return new FullFunctionalExpressionGrammar(this, cloner);39 return new ExternalEvaluationExpressionGrammar(this, cloner); 40 40 } 41 41 42 public FullFunctionalExpressionGrammar()43 : base( ) {42 public ExternalEvaluationExpressionGrammar() 43 : base("ExternalEvaluationExpressionGrammar", "Represents a grammar for functional expressions using all available functions.") { 44 44 Initialize(); 45 45 } 46 46 47 private void Initialize() { 48 var originalStart = StartSymbol; 49 if (!(originalStart is ProgramRootSymbol)) { 50 var root = new ProgramRootSymbol(); 51 AddSymbol(root); 52 SetMinSubtreeCount(root, 1); 53 SetMaxSubtreeCount(root, 1); 54 SetAllowedChild(root, originalStart, 0); 55 56 StartSymbol = root; 57 } 58 47 private void Initialize() { 59 48 var add = new Addition(); 60 49 var sub = new Subtraction(); … … 76 65 constant.MinValue = -20; 77 66 constant.MaxValue = 20; 78 variableSymbol = new Variable();67 variableSymbol = new HeuristicLab.Problems.DataAnalysis.Symbolic.Variable(); 79 68 80 69 var allSymbols = new List<Symbol>() { add, sub, mul, div, mean, sin, cos, tan, log, exp, @if, gt, lt, and, or, not, constant, variableSymbol }; … … 87 76 88 77 foreach (var funSymb in functionSymbols) { 89 SetMinSubtreeCount(funSymb, 1); 90 SetMaxSubtreeCount(funSymb, 3); 78 SetSubtreeCount(funSymb, 1, 3); 91 79 } 92 80 foreach (var funSymb in unaryFunctionSymbols) { 93 SetMinSubtreeCount(funSymb, 1); 94 SetMaxSubtreeCount(funSymb, 1); 81 SetSubtreeCount(funSymb, 1, 1); 95 82 } 96 83 foreach (var funSymb in binaryFunctionSymbols) { 97 SetMinSubtreeCount(funSymb, 2); 98 SetMaxSubtreeCount(funSymb, 2); 84 SetSubtreeCount(funSymb, 2, 2); 99 85 } 100 86 101 SetMinSubtreeCount(@if, 3); 102 SetMaxSubtreeCount(@if, 3); 103 SetMinSubtreeCount(constant, 0); 104 SetMaxSubtreeCount(constant, 0); 105 SetMinSubtreeCount(variableSymbol, 0); 106 SetMaxSubtreeCount(variableSymbol, 0); 87 SetSubtreeCount(@if, 3, 3); 88 SetSubtreeCount(constant, 0, 0); 89 SetSubtreeCount(variableSymbol, 0, 0); 107 90 108 91 // allow each symbol as child of the start symbol 109 92 foreach (var symb in allSymbols) { 110 SetAllowedChild(originalStart, symb, 0);93 AddAllowedChildSymbol(StartSymbol, symb, 0); 111 94 } 112 95 113 96 // allow each symbol as child of every other symbol (except for terminals that have maxSubtreeCount == 0) 114 97 foreach (var parent in allSymbols) { 115 for (int i = 0; i < GetMax SubtreeCount(parent); i++)98 for (int i = 0; i < GetMaximumSubtreeCount(parent); i++) 116 99 foreach (var child in allSymbols) { 117 SetAllowedChild(parent, child, i);100 AddAllowedChildSymbol(parent, child, i); 118 101 } 119 102 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationSymbolicExpressionTreeStringConverter.cs
r5745 r5750 30 30 [StorableClass] 31 31 public class SymbolicExpressionTreeStringConverter : SymbolicExpressionTreeConverter { 32 private SymbolicExpressionTreeStringFormatter formatter;32 private ExternalEvaluationSymbolicExpressionTreeStringFormatter formatter; 33 33 34 34 [StorableConstructor] … … 36 36 protected SymbolicExpressionTreeStringConverter(SymbolicExpressionTreeStringConverter original, Cloner cloner) 37 37 : base(original, cloner) { 38 formatter = new SymbolicExpressionTreeStringFormatter();38 formatter = new ExternalEvaluationSymbolicExpressionTreeStringFormatter(); 39 39 formatter.Indent = original.formatter.Indent; 40 40 } … … 54 54 55 55 private void Initialize() { 56 formatter = new SymbolicExpressionTreeStringFormatter();56 formatter = new ExternalEvaluationSymbolicExpressionTreeStringFormatter(); 57 57 formatter.Indent = false; 58 58 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs
r5745 r5750 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; 28 using HeuristicLab.Problems.DataAnalysis.Symbolic; 29 using System; 27 30 28 namespace HeuristicLab. Encodings.SymbolicExpressionTreeEncoding{31 namespace HeuristicLab.Problems.ExternalEvaluation.GP { 29 32 30 [Item(" SymbolicExpressionTreeStringFormatter", "The default string formatter for symbolic expression trees.")]33 [Item("ExternalEvaluationSymbolicExpressionTreeStringFormatter", "A string formatter for symbolic expression trees for external evaluation.")] 31 34 [StorableClass] 32 public class SymbolicExpressionTreeStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter {35 public class ExternalEvaluationSymbolicExpressionTreeStringFormatter : NamedItem, ISymbolicExpressionTreeStringFormatter { 33 36 34 37 public bool Indent { get; set; } 35 38 36 39 [StorableConstructor] 37 protected SymbolicExpressionTreeStringFormatter(bool deserializing) : base(deserializing) { }38 protected SymbolicExpressionTreeStringFormatter(SymbolicExpressionTreeStringFormatter original, Cloner cloner)40 protected ExternalEvaluationSymbolicExpressionTreeStringFormatter(bool deserializing) : base(deserializing) { } 41 protected ExternalEvaluationSymbolicExpressionTreeStringFormatter(ExternalEvaluationSymbolicExpressionTreeStringFormatter original, Cloner cloner) 39 42 : base(original, cloner) { 40 43 Indent = original.Indent; 41 44 } 42 public SymbolicExpressionTreeStringFormatter()45 public ExternalEvaluationSymbolicExpressionTreeStringFormatter() 43 46 : base() { 44 Name = " Default StringFormatter";47 Name = "External Evaluation Symbolic Expression Tree Formatter"; 45 48 Indent = true; 46 49 } 47 50 48 51 public string Format(ISymbolicExpressionTree symbolicExpressionTree) { 49 return FormatRecursively(symbolicExpressionTree.Root, 0); 52 // skip root and start symbols 53 return FormatRecursively(symbolicExpressionTree.Root.GetSubtree(0).GetSubtree(0), 0); 50 54 } 51 55 … … 57 61 if (node.Subtrees.Count() > 0) { 58 62 // symbol on same line as '(' 59 strBuilder.AppendLine(node.ToString()); 63 if (node.Symbol is Addition) { 64 strBuilder.AppendLine("+"); 65 } else if (node.Symbol is And) { 66 strBuilder.AppendLine("&&"); 67 } else if (node.Symbol is Average) { 68 strBuilder.AppendLine("avg"); 69 } else if (node.Symbol is Cosine) { 70 strBuilder.AppendLine("cos"); 71 } else if (node.Symbol is Division) { 72 strBuilder.AppendLine("/"); 73 } else if (node.Symbol is Exponential) { 74 strBuilder.AppendLine("exp"); 75 } else if (node.Symbol is GreaterThan) { 76 strBuilder.AppendLine(">"); 77 } else if (node.Symbol is IfThenElse) { 78 strBuilder.AppendLine("if"); 79 } else if (node.Symbol is LessThan) { 80 strBuilder.AppendLine("<"); 81 } else if (node.Symbol is Logarithm) { 82 strBuilder.AppendLine("ln"); 83 } else if (node.Symbol is Multiplication) { 84 strBuilder.AppendLine("*"); 85 } else if (node.Symbol is Not) { 86 strBuilder.AppendLine("!"); 87 } else if (node.Symbol is Or) { 88 strBuilder.AppendLine("||"); 89 } else if (node.Symbol is Sine) { 90 strBuilder.AppendLine("sin"); 91 } else if (node.Symbol is Subtraction) { 92 strBuilder.AppendLine("-"); 93 } else if (node.Symbol is Tangent) { 94 strBuilder.AppendLine("tan"); 95 } else { 96 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation."); 97 } 60 98 // each subtree expression on a new line 61 99 // and closing ')' also on new line 100 62 101 foreach (var subtree in node.Subtrees) { 63 102 strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2)); … … 66 105 strBuilder.Append(")"); 67 106 } else { 68 // symbol in the same line with as '(' and ')' 69 strBuilder.Append(node.ToString()); 70 strBuilder.Append(")"); 107 if (node is VariableTreeNode) { 108 var varNode = node as VariableTreeNode; 109 // symbol in the same line with as '(' and ')' 110 strBuilder.Append(";" + varNode.VariableName + ";" + varNode.Weight.ToString("E4")); 111 strBuilder.Append(")"); 112 } else if (node is ConstantTreeNode) { 113 var constNode = node as ConstantTreeNode; 114 // symbol in the same line with as '(' and ')' 115 strBuilder.Append(";" + constNode.Value.ToString("E4")); 116 strBuilder.Append(")"); 117 } else { 118 throw new NotSupportedException("Formatting of symbol: " + node.Symbol + " not supported for external evaluation."); 119 } 71 120 } 72 121 return strBuilder.ToString(); … … 74 123 75 124 public override IDeepCloneable Clone(Cloner cloner) { 76 return new SymbolicExpressionTreeStringFormatter(this, cloner);125 return new ExternalEvaluationSymbolicExpressionTreeStringFormatter(this, cloner); 77 126 } 78 127 } -
branches/DataAnalysis Refactoring/HeuristicLab.Problems.ExternalEvaluation.GP/3.4/HeuristicLab.Problems.ExternalEvaluation.GP-3.4.csproj
r5572 r5750 108 108 <ItemGroup> 109 109 <None Include="HeuristicLabProblemsExternalEvaluationGPPlugin.cs.frame" /> 110 <Compile Include="ExternalEvaluationExpressionGrammar.cs" /> 111 <Compile Include="ExternalEvaluationSymbolicExpressionTreeBinaryConverter.cs" /> 112 <Compile Include="ExternalEvaluationSymbolicExpressionTreeConverter.cs" /> 113 <Compile Include="ExternalEvaluationSymbolicExpressionTreeStringConverter.cs" /> 114 <Compile Include="ExternalEvaluationSymbolicExpressionTreeStringFormatter.cs" /> 110 115 <Compile Include="HeuristicLabProblemsExternalEvaluationGPPlugin.cs" /> 111 116 <Compile Include="Properties\AssemblyInfo.cs" /> 112 117 <None Include="Properties\AssemblyInfo.frame" /> 113 <Compile Include="SymbolicExpressionTreeBinaryConverter.cs" />114 <Compile Include="SymbolicExpressionTreeConverter.cs" />115 <Compile Include="SymbolicExpressionTreeStringConverter.cs" />116 118 </ItemGroup> 117 119 <ItemGroup> … … 147 149 <Project>{94186A6A-5176-4402-AE83-886557B53CCA}</Project> 148 150 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 151 </ProjectReference> 152 <ProjectReference Include="..\..\HeuristicLab.Problems.DataAnalysis.Symbolic\3.4\HeuristicLab.Problems.DataAnalysis.Symbolic-3.4.csproj"> 153 <Project>{3D28463F-EC96-4D82-AFEE-38BE91A0CA00}</Project> 154 <Name>HeuristicLab.Problems.DataAnalysis.Symbolic-3.4</Name> 149 155 </ProjectReference> 150 156 <ProjectReference Include="..\..\HeuristicLab.Problems.ExternalEvaluation\3.3\HeuristicLab.Problems.ExternalEvaluation-3.3.csproj"> … … 176 182 <Install>true</Install> 177 183 </BootstrapperPackage> 184 </ItemGroup> 185 <ItemGroup> 186 <Content Include="ExternalEvaluationGrammar.txt" /> 178 187 </ItemGroup> 179 188 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
Note: See TracChangeset
for help on using the changeset viewer.