Changeset 6760 for branches/PersistenceSpeedUp/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators
- Timestamp:
- 09/14/11 13:59:25 (13 years ago)
- Location:
- branches/PersistenceSpeedUp
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PersistenceSpeedUp
- Property svn:ignore
-
old new 12 12 *.psess 13 13 *.vsp 14 *.docstates
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/PersistenceSpeedUp/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r6009 r6760 38 38 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 39 39 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar"; 40 private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar"; 40 41 #region Parameter Properties 41 42 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter { … … 47 48 public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter { 48 49 get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; } 50 } 51 public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter { 52 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; } 49 53 } 50 54 #endregion … … 57 61 } 58 62 public ISymbolicExpressionGrammar SymbolicExpressionTreeGrammar { 59 get { return SymbolicExpressionTreeGrammarParameter.ActualValue; }63 get { return ClonedSymbolicExpressionTreeGrammarParameter.ActualValue; } 60 64 } 61 65 #endregion … … 69 73 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 70 74 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created.")); 75 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees.")); 71 76 } 72 77 … … 74 79 return new ProbabilisticTreeCreator(this, cloner); 75 80 } 81 [StorableHook(HookType.AfterDeserialization)] 82 private void AfterDeserialization() { 83 if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName)) 84 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees.")); 85 } 86 87 public override IOperation Apply() { 88 if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) { 89 SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true; 90 IScope globalScope = ExecutionContext.Scope; 91 while (globalScope.Parent != null) 92 globalScope = globalScope.Parent; 93 94 globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone())); 95 } 96 return base.Apply(); 97 } 76 98 77 99 protected override ISymbolicExpressionTree Create(IRandom random) { 78 100 return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 79 80 101 } 81 102 … … 165 186 select s) 166 187 .ToList(); 188 if (allowedSymbols.Count == 0) return false; 167 189 var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList(); 168 190 var selectedSymbol = allowedSymbols.SelectRandom(weights, random); -
branches/PersistenceSpeedUp/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/SymbolicExpressionTreeCreator.cs
r5809 r6760 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data;25 24 using HeuristicLab.Parameters; 26 25 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 55 54 } 56 55 57 public sealedoverride IOperation Apply() {56 public override IOperation Apply() { 58 57 SymbolicExpressionTree = Create(Random); 59 58 return base.Apply();
Note: See TracChangeset
for help on using the changeset viewer.