- Timestamp:
- 10/06/21 16:13:37 (3 years ago)
- Location:
- trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/BalancedTreeCreator.cs
r18018 r18064 171 171 } 172 172 173 protected override ISymbolicExpressionTree Create(IRandom random) {174 var maxLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value;175 var maxDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value;176 var grammar = ClonedSymbolicExpressionTreeGrammarParameter.ActualValue;177 return Create(random, grammar, maxLength, maxDepth);178 }179 180 173 #region helpers 181 174 private class NodeInfo { -
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/FullTreeCreator.cs
r17180 r18064 45 45 } 46 46 47 48 protected override ISymbolicExpressionTree Create(IRandom random) {49 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,50 MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);51 }52 47 53 48 public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) { -
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/GrowTreeCreator.cs
r17180 r18064 40 40 public override IDeepCloneable Clone(Cloner cloner) { 41 41 return new GrowTreeCreator(this, cloner); 42 }43 44 45 protected override ISymbolicExpressionTree Create(IRandom random) {46 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,47 MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);48 42 } 49 43 -
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r17180 r18064 48 48 } 49 49 50 51 protected override ISymbolicExpressionTree Create(IRandom random) {52 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,53 MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);54 }55 56 50 public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) { 57 51 return Create(random, grammar, maxTreeLength, maxTreeDepth); -
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/RampedHalfAndHalfTreeCreator.cs
r17180 r18064 40 40 } 41 41 42 protected override ISymbolicExpressionTree Create(IRandom random) {43 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue,44 MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value);45 }46 47 42 public override ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth) { 48 43 return Create(random, grammar, maxTreeLength, maxTreeDepth); -
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs
r17180 r18064 37 37 38 38 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 39 private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";40 39 41 40 #region Parameter Properties … … 49 48 get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 50 49 } 51 52 public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {53 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }54 }55 50 #endregion 56 51 … … 63 58 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 64 59 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created.")); 65 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));66 }67 68 [StorableHook(HookType.AfterDeserialization)]69 private void AfterDeserialization() {70 if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName))71 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees."));72 60 } 73 61 74 62 public override IOperation InstrumentedApply() { 75 if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) { 76 SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true; 77 IScope globalScope = ExecutionContext.Scope; 78 while (globalScope.Parent != null) 79 globalScope = globalScope.Parent; 63 var rand = RandomParameter.ActualValue; 64 var grammar = SymbolicExpressionTreeGrammarParameter.ActualValue; 65 var maxTreeLength = MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value; 66 var maxTreeDepth = MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value; 80 67 81 globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName, 82 (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone())); 83 } 84 SymbolicExpressionTreeParameter.ActualValue = Create(RandomParameter.ActualValue); 68 SymbolicExpressionTreeParameter.ActualValue = CreateTree(rand, grammar, maxTreeLength, maxTreeDepth); 85 69 return base.InstrumentedApply(); 86 70 } 87 88 protected abstract ISymbolicExpressionTree Create(IRandom random);89 71 public abstract ISymbolicExpressionTree CreateTree(IRandom random, ISymbolicExpressionGrammar grammar, int maxTreeLength, int maxTreeDepth); 90 72 }
Note: See TracChangeset
for help on using the changeset viewer.