Changeset 12969 for branches/gteufl/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
- Timestamp:
- 09/25/15 14:39:59 (9 years ago)
- Location:
- branches/gteufl
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/gteufl
- Property svn:ignore
-
old new 8 8 FxCopResults.txt 9 9 Google.ProtocolBuffers-0.9.1.dll 10 Google.ProtocolBuffers-2.4.1.473.dll 10 11 HeuristicLab 3.3.5.1.ReSharper.user 11 12 HeuristicLab 3.3.6.0.ReSharper.user 12 13 HeuristicLab.4.5.resharper.user 13 14 HeuristicLab.ExtLibs.6.0.ReSharper.user 15 HeuristicLab.Scripting.Development 14 16 HeuristicLab.resharper.user 15 17 ProtoGen.exe … … 17 19 _ReSharper.HeuristicLab 18 20 _ReSharper.HeuristicLab 3.3 21 _ReSharper.HeuristicLab 3.3 Tests 19 22 _ReSharper.HeuristicLab.ExtLibs 20 23 bin 21 24 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests 23 Google.ProtocolBuffers-2.4.1.473.dll 25 obj
-
- Property svn:mergeinfo changed
-
Property
svn:global-ignores
set to
*.nuget
packages
- Property svn:ignore
-
branches/gteufl/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
-
branches/gteufl/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Creators/ProbabilisticTreeCreator.cs
r9456 r12969 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 3Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2015 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data;28 using HeuristicLab.Parameters;29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 using HeuristicLab.PluginInfrastructure; … … 37 35 ISymbolicExpressionTreeSizeConstraintOperator, ISymbolicExpressionTreeGrammarBasedOperator { 38 36 private const int MAX_TRIES = 100; 39 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";40 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";41 private const string SymbolicExpressionTreeGrammarParameterName = "SymbolicExpressionTreeGrammar";42 private const string ClonedSymbolicExpressionTreeGrammarParameterName = "ClonedSymbolicExpressionTreeGrammar";43 #region Parameter Properties44 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter {45 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; }46 }47 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {48 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }49 }50 public IValueLookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionTreeGrammarParameter {51 get { return (IValueLookupParameter<ISymbolicExpressionGrammar>)Parameters[SymbolicExpressionTreeGrammarParameterName]; }52 }53 public ILookupParameter<ISymbolicExpressionGrammar> ClonedSymbolicExpressionTreeGrammarParameter {54 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters[ClonedSymbolicExpressionTreeGrammarParameterName]; }55 }56 #endregion57 #region Properties58 public IntValue MaximumSymbolicExpressionTreeLength {59 get { return MaximumSymbolicExpressionTreeLengthParameter.ActualValue; }60 }61 public IntValue MaximumSymbolicExpressionTreeDepth {62 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }63 }64 public ISymbolicExpressionGrammar SymbolicExpressionTreeGrammar {65 get { return ClonedSymbolicExpressionTreeGrammarParameter.ActualValue; }66 }67 #endregion68 37 69 38 [StorableConstructor] … … 72 41 public ProbabilisticTreeCreator() 73 42 : base() { 74 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 75 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 76 Parameters.Add(new ValueLookupParameter<ISymbolicExpressionGrammar>(SymbolicExpressionTreeGrammarParameterName, "The tree grammar that defines the correct syntax of symbolic expression trees that should be created.")); 77 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees.")); 43 78 44 } 79 45 … … 81 47 return new ProbabilisticTreeCreator(this, cloner); 82 48 } 83 [StorableHook(HookType.AfterDeserialization)] 84 private void AfterDeserialization() { 85 if (!Parameters.ContainsKey(ClonedSymbolicExpressionTreeGrammarParameterName)) 86 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>(ClonedSymbolicExpressionTreeGrammarParameterName, "An immutable clone of the concrete grammar that is actually used to create and manipulate trees.")); 87 } 88 89 public override IOperation Apply() { 90 if (ClonedSymbolicExpressionTreeGrammarParameter.ActualValue == null) { 91 SymbolicExpressionTreeGrammarParameter.ActualValue.ReadOnly = true; 92 IScope globalScope = ExecutionContext.Scope; 93 while (globalScope.Parent != null) 94 globalScope = globalScope.Parent; 95 96 globalScope.Variables.Add(new Variable(ClonedSymbolicExpressionTreeGrammarParameterName, (ISymbolicExpressionGrammar)SymbolicExpressionTreeGrammarParameter.ActualValue.Clone())); 97 } 98 return base.Apply(); 99 } 49 100 50 101 51 protected override ISymbolicExpressionTree Create(IRandom random) { 102 return Create(random, SymbolicExpressionTreeGrammar, MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 52 return Create(random, ClonedSymbolicExpressionTreeGrammarParameter.ActualValue, 53 MaximumSymbolicExpressionTreeLengthParameter.ActualValue.Value, MaximumSymbolicExpressionTreeDepthParameter.ActualValue.Value); 103 54 } 104 55 … … 111 62 var rootNode = (SymbolicExpressionTreeTopLevelNode)grammar.ProgramRootSymbol.CreateTreeNode(); 112 63 if (rootNode.HasLocalParameters) rootNode.ResetLocalParameters(random); 113 rootNode.SetGrammar(new SymbolicExpressionTreeGrammar(grammar)); 64 rootNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 65 114 66 var startNode = (SymbolicExpressionTreeTopLevelNode)grammar.StartSymbol.CreateTreeNode(); 115 startNode.SetGrammar(new SymbolicExpressionTreeGrammar(grammar));116 67 if (startNode.HasLocalParameters) startNode.ResetLocalParameters(random); 68 startNode.SetGrammar(grammar.CreateExpressionTreeGrammar()); 69 117 70 rootNode.AddSubtree(startNode); 118 71 PTC2(random, startNode, maxTreeLength, maxTreeDepth); … … 213 166 if (allowedSymbols.Count == 0) return false; 214 167 var weights = allowedSymbols.Select(x => x.InitialFrequency).ToList(); 168 169 #pragma warning disable 612, 618 215 170 var selectedSymbol = allowedSymbols.SelectRandom(weights, random); 171 #pragma warning restore 612, 618 172 216 173 ISymbolicExpressionTreeNode newTree = selectedSymbol.CreateTreeNode(); 217 174 if (newTree.HasLocalParameters) newTree.ResetLocalParameters(random); … … 259 216 select g).First().ToList(); 260 217 var weights = possibleSymbols.Select(x => x.InitialFrequency).ToList(); 218 219 #pragma warning disable 612, 618 261 220 var selectedSymbol = possibleSymbols.SelectRandom(weights, random); 221 #pragma warning restore 612, 618 222 262 223 var tree = selectedSymbol.CreateTreeNode(); 263 224 if (tree.HasLocalParameters) tree.ResetLocalParameters(random);
Note: See TracChangeset
for help on using the changeset viewer.