Changeset 13482 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Timestamp:
- 12/17/15 20:43:07 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 8 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r12891 r13482 74 74 } 75 75 76 public static ISymbolicExpressionTree CreateExpressionTree(IRandom random, ISymbolicExpressionGrammar grammar, int targetLength, 77 int maxTreeDepth) { 78 SymbolicExpressionTree tree = new SymbolicExpressionTree(); 79 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode(); 80 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random); 81 rootNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 82 83 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode(); 84 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random); 85 startNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 86 87 rootNode.AddSubtree(startNode); 88 bool success = TryCreateFullTreeFromSeed(random, startNode, targetLength - 2, maxTreeDepth - 1); 89 if (!success) throw new InvalidOperationException(string.Format("Could not create a tree with target length {0} and max depth {1}", targetLength, maxTreeDepth)); 90 91 tree.Root = rootNode; 92 return tree; 93 94 } 95 76 96 private class TreeExtensionPoint { 77 97 public ISymbolicExpressionTreeNode Parent { get; set; } … … 107 127 } else { 108 128 // clean seedNode 109 while (seedNode.Subtrees. Count() > 0) seedNode.RemoveSubtree(0);129 while (seedNode.Subtrees.Any()) seedNode.RemoveSubtree(0); 110 130 } 111 131 // try a different length MAX_TRIES times -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Formatters/SymbolicExpressionTreeStringFormatter.cs
r12155 r13482 20 20 #endregion 21 21 22 using System.Collections.Generic; 22 23 using System.Text; 23 24 using HeuristicLab.Common; … … 32 33 33 34 public bool Indent { get; set; } 35 public bool AppendNewLines { get; set; } 36 37 private static readonly Dictionary<string, string> PrettyNames = new Dictionary<string, string> { 38 { "Addition", "+"}, {"Subtraction", "-" }, {"Multiplication", "*" }, {"Division", "/" }, {"Logarithm", "log" }, {"Exponential", "exp" } 39 }; 34 40 35 41 [StorableConstructor] … … 60 66 if (node.SubtreeCount > 0) { 61 67 // symbol on same line as '(' 62 strBuilder.AppendLine(node.ToString()); 68 string name; 69 PrettyNames.TryGetValue(node.ToString(), out name); 70 if (name == null) name = node.ToString(); 71 strBuilder.Append(name); 72 if (AppendNewLines) 73 strBuilder.AppendLine(); 63 74 // each subtree expression on a new line 64 75 // and closing ')' also on new line 65 76 foreach (var subtree in node.Subtrees) { 66 strBuilder.AppendLine(FormatRecursively(subtree, indentLength + 2)); 77 strBuilder.Append(FormatRecursively(subtree, indentLength + 2)); 78 if (AppendNewLines) 79 strBuilder.AppendLine(); 67 80 } 68 81 if (Indent) strBuilder.Append(' ', indentLength); 69 strBuilder.Append(") ");82 strBuilder.Append(") "); 70 83 } else { 71 84 // symbol in the same line with as '(' and ')' 72 strBuilder.Append(node .ToString());73 strBuilder.Append(") ");85 strBuilder.Append(node); 86 strBuilder.Append(") "); 74 87 } 75 88 return strBuilder.ToString(); -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Grammars/SimpleSymbolicExpressionGrammar.cs
r12891 r13482 25 25 26 26 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 27 [StorableClass] 27 28 public sealed class SimpleSymbolicExpressionGrammar : SymbolicExpressionGrammar { 28 29 [StorableConstructor] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r12891 r13482 181 181 <Compile Include="ArchitectureManipulators\SubroutineDuplicater.cs" /> 182 182 <Compile Include="ArchitectureManipulators\SymbolicExpressionTreeArchitectureManipulator.cs" /> 183 <Compile Include="SymbolicExpressionTreeProblem.cs" /> 183 184 <Compile Include="Compiler\Instruction.cs" /> 184 185 <Compile Include="Compiler\LinearInstruction.cs" /> -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Plugin.cs.frame
r12891 r13482 26 26 27 27 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 28 [Plugin("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","Provides operators and related classes for the symbolic expression tree encoding.", "3.4. 8.$WCREV$")]28 [Plugin("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding","Provides operators and related classes for the symbolic expression tree encoding.", "3.4.9.$WCREV$")] 29 29 [PluginFile("HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.dll", PluginFileType.Assembly)] 30 30 [PluginDependency("HeuristicLab.Analysis", "3.3")] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Properties/AssemblyInfo.cs.frame
r12891 r13482 45 45 46 46 [assembly: AssemblyVersion("3.4.0.0")] 47 [assembly: AssemblyFileVersion("3.4. 8.$WCREV$")]47 [assembly: AssemblyFileVersion("3.4.9.$WCREV$")] -
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeEncoding.cs
r12891 r13482 159 159 [StorableConstructor] 160 160 private SymbolicExpressionTreeEncoding(bool deserializing) : base(deserializing) { } 161 public SymbolicExpressionTreeEncoding() : this(new SimpleSymbolicExpressionGrammar()) { } 161 162 public SymbolicExpressionTreeEncoding(ISymbolicExpressionGrammar grammar) : this("SymbolicExpressionTree", grammar, 50, 50) { } 162 163 public SymbolicExpressionTreeEncoding(ISymbolicExpressionGrammar grammar, int maximumLength, int maximumDepth) : this("SymbolicExpressionTree", grammar, maximumLength, maximumDepth) { }
Note: See TracChangeset
for help on using the changeset viewer.