Changeset 12422 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
- Timestamp:
- 06/10/15 11:29:34 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
r12012 r12422 24 24 using HeuristicLab.Common; 25 25 using HeuristicLab.Core; 26 using HeuristicLab.Data;27 using HeuristicLab.Parameters;28 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 27 using HeuristicLab.PluginInfrastructure; … … 36 34 ISymbolicExpressionTreeSizeConstraintOperator, 37 35 ISymbolicExpressionTreeGrammarBasedOperator { 38 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";39 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";40 41 #region Parameter Properties42 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {43 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }44 }45 46 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {47 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }48 }49 #endregion50 #region Properties51 public IntValue MaximumSymbolicExpressionTreeDepth {52 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }53 }54 55 public IntValue MaximumSymbolicExpressionTreeLength {56 get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }57 }58 59 #endregion60 36 61 37 [StorableConstructor] … … 63 39 protected FullTreeCreator(FullTreeCreator original, Cloner cloner) : base(original, cloner) { } 64 40 65 public FullTreeCreator() 66 : base() { 67 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, 68 "The maximal length (number of nodes) of the symbolic expression tree (this parameter is ignored).")); 69 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, 70 "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 71 } 41 public FullTreeCreator() : base() { } 72 42 73 43 public override IDeepCloneable Clone(Cloner cloner) { … … 77 47 78 48 protected override ISymbolicExpressionTree Create(IRandom random) { 79 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 49 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, 50 MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value); 80 51 } 81 52 … … 131 102 .ToList(); 132 103 var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList(); 104 105 #pragma warning disable 612, 618 133 106 var selectedSymbol = possibleSymbols.SelectRandom(weights, random); 107 #pragma warning restore 612, 618 108 134 109 var tree = selectedSymbol.CreateTreeNode(); 135 110 if (tree.HasLocalParameters) tree.ResetLocalParameters(random); … … 163 138 throw new InvalidOperationException("No symbols are available for the tree."); 164 139 var weights = possibleSymbols.Select(s => s.InitialFrequency).ToList(); 140 141 #pragma warning disable 612, 618 165 142 var selectedSymbol = possibleSymbols.SelectRandom(weights, random); 143 #pragma warning restore 612, 618 144 166 145 var tree = selectedSymbol.CreateTreeNode(); 167 146 if (tree.HasLocalParameters) tree.ResetLocalParameters(random); … … 169 148 } 170 149 171 foreach (var subTree in root.Subtrees) 172 if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0) 173 RecursiveCreate(random, subTree, currentDepth + 1, maxDepth); 150 //additional levels should only be added if the maximum depth is not reached yet 151 if (maxDepth > currentDepth) { 152 foreach (var subTree in root.Subtrees) 153 if (subTree.Grammar.GetMaximumSubtreeCount(subTree.Symbol) > 0) 154 RecursiveCreate(random, subTree, currentDepth + 1, maxDepth); 155 } 174 156 } 175 157 }
Note: See TracChangeset
for help on using the changeset viewer.