Changeset 3237
- Timestamp:
- 03/30/10 19:38:22 (15 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3
- Files:
-
- 4 added
- 1 deleted
- 7 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Creators/ProbabilisticTreeCreator.cs
r3223 r3237 51 51 do { 52 52 try { 53 // determine possible root symbols to create a tree of the target size 54 var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 55 where treeSize <= grammar.MaximalExpressionLength(symbol) 56 where treeSize >= grammar.MinimalExpressionLength(symbol) 57 select symbol; 58 Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 59 tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 53 tree.Root = PTC2(random, grammar, grammar.StartSymbol, treeSize+1, maxTreeHeight+1); 54 //// determine possible root symbols to create a tree of the target size 55 //var possibleRootSymbols = from symbol in grammar.AllowedSymbols(grammar.StartSymbol, 0) 56 // where treeSize <= grammar.MaximalExpressionLength(symbol) 57 // where treeSize >= grammar.MinimalExpressionLength(symbol) 58 // select symbol; 59 //Symbol rootSymbol = SelectRandomSymbol(random, possibleRootSymbols); 60 //tree.Root = PTC2(random, grammar, rootSymbol, treeSize, maxTreeHeight); 60 61 } 61 62 catch (ArgumentException) { … … 149 150 int minArity = grammar.MinSubTrees(symbol); 150 151 int maxArity = grammar.MaxSubTrees(symbol); 151 if (maxArity > =targetSize) {152 if (maxArity > targetSize) { 152 153 maxArity = targetSize; 153 154 } 154 155 // the min number of sub-trees has to be set to a value that is large enough so that the largest possible tree is at least tree size 155 156 // if 1..3 trees are possible and the largest possible first sub-tree is smaller larger than the target size then minArity should be at least 2 156 int aggregatedLongestExpressionLength = 1;157 long aggregatedLongestExpressionLength = 0; 157 158 for (int i = 0; i < maxArity; i++) { 158 159 aggregatedLongestExpressionLength += (from s in grammar.AllowedSymbols(symbol, i) 159 select grammar.MaximalExpressionLength(s ymbol)).Max();160 select grammar.MaximalExpressionLength(s)).Max(); 160 161 if (aggregatedLongestExpressionLength < targetSize) minArity = i; 161 162 else break; … … 164 165 // the max number of sub-trees has to be set to a value that is small enough so that the smallest possible tree is at most tree size 165 166 // if 1..3 trees are possible and the smallest possible first sub-tree is already larger than the target size then maxArity should be at most 0 166 int aggregatedShortestExpressionLength = 1;167 long aggregatedShortestExpressionLength = 0; 167 168 for (int i = 0; i < maxArity; i++) { 168 169 aggregatedShortestExpressionLength += (from s in grammar.AllowedSymbols(symbol, i) 169 select grammar.MinimalExpressionLength(s ymbol)).Min();170 select grammar.MinimalExpressionLength(s)).Min(); 170 171 if (aggregatedShortestExpressionLength > targetSize) { 171 172 maxArity = i; -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Crossovers/SubtreeCrossover.cs
r3232 r3237 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-20 08Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. … … 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.GP.Interfaces; 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using HeuristicLab.Data; 26 using System.Linq; 27 using System; 28 using HeuristicLab.Parameters; 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 25 30 26 namespace HeuristicLab.Encodings.SymbolicExpressionTree {27 public class StandardCrossOver : SizeConstrictedGPCrossoverBase {28 private int MaxRecombinationTries { get { return 20; } }29 31 30 public override string Description { 31 get { 32 return @"Takes two parent individuals P0 and P1 each. Selects a random node N0 of P0 and a random node N1 of P1. 33 And replaces the branch with root0 N0 in P0 with N1 from P1 if the tree-size limits are not violated. 34 When recombination with N0 and N1 would create a tree that is too large or invalid the operator randomly selects new N0 and N1 35 until a valid configuration is found."; 32 /// <summary> 33 /// Takes two parent individuals P0 and P1 each. Selects a random node N0 of P0 and a random node N1 of P1. 34 /// And replaces the branch with root0 N0 in P0 with N1 from P1 if the tree-size limits are not violated. 35 /// When recombination with N0 and N1 would create a tree that is too large or invalid the operator randomly selects new N0 and N1 36 /// until a valid configuration is found. 37 /// </summary> 38 [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")] 39 [StorableClass] 40 public class SubtreeCrossover : SymbolicExpressionTreeCrossover { 41 private const int MAX_TRIES = 100; 42 43 public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter { 44 get { return (IValueLookupParameter<PercentValue>)Parameters["InternalCrossoverPointProbability"]; } 45 } 46 47 public SubtreeCrossover() 48 : base() { 49 Parameters.Add(new ValueLookupParameter<PercentValue>("InternalCrossoverPointProbability", "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 50 } 51 52 protected override SymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionGrammar grammar, 53 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1, 54 IntValue maxTreeSize, IntValue maxTreeHeight) { 55 return Apply(random, grammar, parent0, parent1, InternalCrossoverPointProbabilityParameter.ActualValue.Value, maxTreeSize.Value, maxTreeHeight.Value); 56 } 57 58 public static SymbolicExpressionTree Apply(IRandom random, ISymbolicExpressionGrammar grammar, 59 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1, 60 double internalCrossoverPointProbability, int maxTreeSize, int maxTreeHeight) { 61 int tries = 0; 62 while (tries++ < MAX_TRIES) { 63 // select a random crossover point in the first parent 64 SymbolicExpressionTreeNode crossoverPoint0; 65 int replacedSubtreeIndex; 66 SelectCrossoverPoint(random, parent0, internalCrossoverPointProbability, out crossoverPoint0, out replacedSubtreeIndex); 67 68 // calculate the max size and height that the inserted branch can have 69 int maxInsertedBranchSize = maxTreeSize - (parent0.Size - crossoverPoint0.SubTrees[replacedSubtreeIndex].GetSize()); 70 int maxInsertedBranchHeight = maxTreeHeight - GetBranchLevel(parent0.Root, crossoverPoint0); 71 72 var allowedBranches = from branch in IterateNodes(parent1.Root) 73 where branch.GetSize() < maxInsertedBranchSize 74 where branch.GetHeight() < maxInsertedBranchHeight 75 where grammar.AllowedSymbols(crossoverPoint0.Symbol, replacedSubtreeIndex).Contains(branch.Symbol) 76 select branch; 77 78 if (allowedBranches.Count() > 0) { 79 var selectedBranch = SelectRandomBranch(random, allowedBranches, internalCrossoverPointProbability); 80 81 // manipulate the tree of parent0 in place 82 // replace the branch in tree0 with the selected branch from tree1 83 crossoverPoint0.RemoveSubTree(replacedSubtreeIndex); 84 crossoverPoint0.InsertSubTree(replacedSubtreeIndex, selectedBranch); 85 return parent0; 86 } 87 } 88 89 // TODO: we should have a way to track the number of failed crossover attempts 90 // for now just return the first parent unchanged 91 return parent0; 92 } 93 94 private static void SelectCrossoverPoint(IRandom random, SymbolicExpressionTree parent0, double internalNodeProbability, out SymbolicExpressionTreeNode crossoverPoint, out int subtreeIndex) { 95 var crossoverPoints = from branch in IterateNodes(parent0.Root) 96 where branch.SubTrees.Count > 0 97 from index in Enumerable.Range(0, branch.SubTrees.Count) 98 let p = new { CrossoverPoint = branch, SubtreeIndex = index, IsLeaf = branch.SubTrees[index].SubTrees.Count == 0 } 99 select p; 100 var internalCrossoverPoints = (from p in crossoverPoints 101 where !p.IsLeaf 102 select p).ToList(); 103 // select internal crossover point or leaf 104 if (random.NextDouble() < internalNodeProbability && internalCrossoverPoints.Count > 0) { 105 var selectedCrossoverPoint = internalCrossoverPoints[random.Next(internalCrossoverPoints.Count)]; 106 crossoverPoint = selectedCrossoverPoint.CrossoverPoint; 107 subtreeIndex = selectedCrossoverPoint.SubtreeIndex; 108 } else { 109 var leafCrossoverPoints = (from p in crossoverPoints 110 where p.IsLeaf 111 select p).ToList(); 112 var selectedCrossoverPoint = leafCrossoverPoints[random.Next(leafCrossoverPoints.Count)]; 113 crossoverPoint = selectedCrossoverPoint.CrossoverPoint; 114 subtreeIndex = selectedCrossoverPoint.SubtreeIndex; 36 115 } 37 116 } 38 117 39 internal override IFunctionTree Cross(TreeGardener gardener, IRandom random, IFunctionTree tree0, IFunctionTree tree1, int maxTreeSize, int maxTreeHeight) { 40 int tries = 0; 41 List<IFunctionTree> allowedCrossoverPoints = null; 42 IFunctionTree parent0; 43 int replacedChildIndex; 44 do { 45 // select a random crossover point in the first parent tree0 46 parent0 = null; 47 while (parent0 == null) parent0 = gardener.GetRandomParentNode(tree0); 48 // select a random branch to replace 49 replacedChildIndex = random.Next(parent0.SubTrees.Count); 50 51 // calculate the max size and height that the inserted branch can have 52 int maxInsertedBranchSize = maxTreeSize - (tree0.GetSize() - parent0.SubTrees[replacedChildIndex].GetSize()); 53 int maxInsertedBranchHeight = maxTreeHeight - gardener.GetBranchLevel(tree0, parent0); // branchlevel is 1 if tree0==parent0 54 55 IList<IFunction> allowedFunctions = new List<IFunction>(gardener.GetAllowedSubFunctions(parent0.Function, replacedChildIndex)); 56 allowedCrossoverPoints = GetPossibleCrossoverPoints(tree1, maxInsertedBranchSize, maxInsertedBranchHeight, allowedFunctions); 57 } while (allowedCrossoverPoints.Count == 0 && tries++ < MaxRecombinationTries); 58 59 if (allowedCrossoverPoints.Count > 0) { 60 IFunctionTree branch1 = allowedCrossoverPoints[random.Next(allowedCrossoverPoints.Count)]; 61 62 // replace the branch in tree0 with the selected branch from tree1 63 parent0.RemoveSubTree(replacedChildIndex); 64 parent0.InsertSubTree(replacedChildIndex, branch1); 118 private static SymbolicExpressionTreeNode SelectRandomBranch(IRandom random, IEnumerable<SymbolicExpressionTreeNode> branches, double internalNodeProbability) { 119 if (internalNodeProbability < 0.0 || internalNodeProbability > 1.0) throw new ArgumentException("internalNodeProbability"); 120 var groupedBranches = from branch in branches 121 group branch by branch.SubTrees.Count into g 122 select g; 123 var allowedInternalBranches = (from g in groupedBranches 124 where g.Key > 0 125 from branch in g 126 select branch).ToList(); 127 if (random.NextDouble() < internalNodeProbability && allowedInternalBranches.Count > 0) { 128 return allowedInternalBranches[random.Next(allowedInternalBranches.Count)]; 129 } else { 130 var allowedLeafBranches = (from g in groupedBranches 131 where g.Key == 0 132 from leaf in g 133 select leaf).ToList(); 134 return allowedLeafBranches[random.Next(allowedLeafBranches.Count)]; 65 135 } 66 return tree0;67 136 } 68 137 69 private List<IFunctionTree> GetPossibleCrossoverPoints(IFunctionTree tree, int maxInsertedBranchSize, int maxInsertedBranchHeight, IList<IFunction> allowedFunctions) {70 List<IFunctionTree> crossoverPoints = new List<IFunctionTree>();71 foreach (IFunctionTree possiblePoint in TreeGardener.GetAllSubTrees(tree)) {72 if (allowedFunctions.Contains(possiblePoint.Function) && possiblePoint.GetSize() <= maxInsertedBranchSize && possiblePoint.GetHeight() <= maxInsertedBranchHeight)73 crossoverPoints.Add(possiblePoint);138 private static IEnumerable<SymbolicExpressionTreeNode> IterateNodes(SymbolicExpressionTreeNode root) { 139 foreach (var subTree in root.SubTrees) { 140 foreach (var branch in IterateNodes(subTree)) { 141 yield return branch; 142 } 74 143 } 75 return crossoverPoints; 144 yield return root; 145 } 146 147 private static int GetBranchLevel(SymbolicExpressionTreeNode root, SymbolicExpressionTreeNode point) { 148 if (root == point) return 0; 149 foreach (var subtree in root.SubTrees) { 150 int branchLevel = GetBranchLevel(subtree, point); 151 if (branchLevel < int.MaxValue) return 1 + branchLevel; 152 } 153 return int.MaxValue; 76 154 } 77 155 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.3.csproj
r3223 r3237 24 24 <ErrorReport>prompt</ErrorReport> 25 25 <WarningLevel>4</WarningLevel> 26 <CheckForOverflowUnderflow>true</CheckForOverflowUnderflow> 26 27 </PropertyGroup> 27 28 <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> … … 70 71 <RequiredTargetFramework>3.5</RequiredTargetFramework> 71 72 </Reference> 73 <Reference Include="System.Drawing" /> 74 <Reference Include="System.Windows.Forms" /> 72 75 <Reference Include="System.Xml.Linq"> 73 76 <RequiredTargetFramework>3.5</RequiredTargetFramework> … … 80 83 </ItemGroup> 81 84 <ItemGroup> 85 <Compile Include="Crossovers\SubtreeCrossover.cs" /> 82 86 <Compile Include="Interfaces\ISymbolicExpressionGrammar.cs" /> 83 87 <Compile Include="Creators\ProbabilisticTreeCreator.cs" /> … … 88 92 <Compile Include="Properties\AssemblyInfo.cs" /> 89 93 <Compile Include="Symbol.cs" /> 94 <Compile Include="SymbolicExpressionTreeCrossover.cs" /> 90 95 <Compile Include="SymbolicExpressionTreeNode.cs" /> 96 <Compile Include="Views\SymbolicExpressionTreeView.cs"> 97 <SubType>UserControl</SubType> 98 </Compile> 99 <Compile Include="Views\SymbolicExpressionTreeView.Designer.cs"> 100 <DependentUpon>SymbolicExpressionTreeView.cs</DependentUpon> 101 </Compile> 91 102 </ItemGroup> 92 103 <ItemGroup> … … 100 111 <Name>HeuristicLab.Collections-3.3</Name> 101 112 </ProjectReference> 113 <ProjectReference Include="..\..\HeuristicLab.Core.Views\3.3\HeuristicLab.Core.Views-3.3.csproj"> 114 <Project>{E226881D-315F-423D-B419-A766FE0D8685}</Project> 115 <Name>HeuristicLab.Core.Views-3.3</Name> 116 </ProjectReference> 102 117 <ProjectReference Include="..\..\HeuristicLab.Core\3.3\HeuristicLab.Core-3.3.csproj"> 103 118 <Project>{C36BD924-A541-4A00-AFA8-41701378DDC5}</Project> … … 107 122 <Project>{BBAB9DF5-5EF3-4BA8-ADE9-B36E82114937}</Project> 108 123 <Name>HeuristicLab.Data-3.3</Name> 124 </ProjectReference> 125 <ProjectReference Include="..\..\HeuristicLab.MainForm.WindowsForms\3.2\HeuristicLab.MainForm.WindowsForms-3.2.csproj"> 126 <Project>{AB687BBE-1BFE-476B-906D-44237135431D}</Project> 127 <Name>HeuristicLab.MainForm.WindowsForms-3.2</Name> 128 </ProjectReference> 129 <ProjectReference Include="..\..\HeuristicLab.MainForm\3.2\HeuristicLab.MainForm-3.2.csproj"> 130 <Project>{3BD61258-31DA-4B09-89C0-4F71FEF5F05A}</Project> 131 <Name>HeuristicLab.MainForm-3.2</Name> 109 132 </ProjectReference> 110 133 <ProjectReference Include="..\..\HeuristicLab.Operators\3.3\HeuristicLab.Operators-3.3.csproj"> … … 134 157 </ItemGroup> 135 158 <ItemGroup> 136 <Folder Include="Crossovers\" /> 159 <EmbeddedResource Include="Views\SymbolicExpressionTreeView.resx"> 160 <DependentUpon>SymbolicExpressionTreeView.cs</DependentUpon> 161 </EmbeddedResource> 162 </ItemGroup> 163 <ItemGroup> 137 164 <Folder Include="Manipulators\" /> 138 165 </ItemGroup> -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/Interfaces/ISymbolicExpressionGrammar.cs
r3223 r3237 42 42 int MinSubTrees(Symbol start); 43 43 int MaxSubTrees(Symbol start); 44 45 bool IsValidExpression(SymbolicExpressionTree expression); 44 46 } 45 47 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionGrammar.cs
r3223 r3237 81 81 get { return startSymbol; } 82 82 } 83 83 84 84 public IEnumerable<Symbol> AllowedSymbols(Symbol parent, int argumentIndex) { 85 85 return allowedSymbols[parent][argumentIndex]; … … 106 106 } 107 107 108 public bool IsValidExpression(SymbolicExpressionTree expression) { 109 throw new NotImplementedException(); 110 } 111 108 112 #endregion 109 113 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTree.cs
r3223 r3237 26 26 using System.Xml; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Data; 28 29 29 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeCrossover.cs
r3223 r3237 26 26 using HeuristicLab.Parameters; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using System; 29 using System.Diagnostics; 28 30 29 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 30 32 /// <summary> 31 /// A base class for operators that perform a crossover of real-valued vectors.33 /// A base class for operators that perform a crossover of symbolic expression trees. 32 34 /// </summary> 33 [Item(" RealVectorCrossover", "A base class for operators that perform a crossover of real-valued vectors.")]35 [Item("SymbolicExpressionTreeCrossover", "A base class for operators that perform a crossover of symbolic expression trees.")] 34 36 [StorableClass] 35 public abstract class RealVectorCrossover : SingleSuccessorOperator, IRealVectorCrossover, IStochasticOperator {37 public abstract class SymbolicExpressionTreeCrossover : SingleSuccessorOperator, ICrossover, IStochasticOperator { 36 38 public override bool CanChangeName { 37 39 get { return false; } … … 41 43 get { return (LookupParameter<IRandom>)Parameters["Random"]; } 42 44 } 43 public ILookupParameter<ItemArray< RealVector>> ParentsParameter {44 get { return (SubScopesLookupParameter< RealVector>)Parameters["Parents"]; }45 public ILookupParameter<ItemArray<SymbolicExpressionTree>> ParentsParameter { 46 get { return (SubScopesLookupParameter<SymbolicExpressionTree>)Parameters["Parents"]; } 45 47 } 46 public ILookupParameter< RealVector> ChildParameter {47 get { return (ILookupParameter< RealVector>)Parameters["Child"]; }48 public ILookupParameter<SymbolicExpressionTree> ChildParameter { 49 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters["Child"]; } 48 50 } 49 public IValueLookupParameter<DoubleMatrix> BoundsParameter { 50 get { return (IValueLookupParameter<DoubleMatrix>)Parameters["Bounds"]; } 51 public IValueLookupParameter<IntValue> MaxTreeSizeParameter { 52 get { return (IValueLookupParameter<IntValue>)Parameters["MaxTreeSize"]; } 53 } 54 public IValueLookupParameter<IntValue> MaxTreeHeightParameter { 55 get { return (IValueLookupParameter<IntValue>)Parameters["MaxTreeHeight"]; } 56 } 57 public ILookupParameter<ISymbolicExpressionGrammar> SymbolicExpressionGrammarParameter { 58 get { return (ILookupParameter<ISymbolicExpressionGrammar>)Parameters["SymbolicExpressionGrammar"]; } 51 59 } 52 60 53 protected RealVectorCrossover()61 protected SymbolicExpressionTreeCrossover() 54 62 : base() { 55 63 Parameters.Add(new LookupParameter<IRandom>("Random", "The pseudo random number generator which should be used for stochastic crossover operators.")); 56 Parameters.Add(new SubScopesLookupParameter<RealVector>("Parents", "The parent vectors which should be crossed.")); 57 Parameters.Add(new LookupParameter<RealVector>("Child", "The child vector resulting from the crossover.")); 58 Parameters.Add(new ValueLookupParameter<DoubleMatrix>("Bounds", "The lower and upper bounds of the real vector.")); 64 Parameters.Add(new SubScopesLookupParameter<SymbolicExpressionTree>("Parents", "The parent symbolic expression trees which should be crossed.")); 65 Parameters.Add(new ValueLookupParameter<IntValue>("MaxTreeSize", "The maximal size (number of nodes) of the symbolic expression tree that should be initialized.")); 66 Parameters.Add(new ValueLookupParameter<IntValue>("MaxTreeHeight", "The maximal height of the symbolic expression tree that should be initialized (a tree with one node has height = 0).")); 67 Parameters.Add(new LookupParameter<ISymbolicExpressionGrammar>("SymbolicExpressionGrammar", "The grammar that defines the allowed symbols and syntax of the symbolic expression trees.")); 68 Parameters.Add(new LookupParameter<SymbolicExpressionTree>("Child", "The child symbolic expression tree resulting from the crossover.")); 59 69 } 60 70 61 71 public sealed override IOperation Apply() { 62 RealVector result = Cross(RandomParameter.ActualValue, ParentsParameter.ActualValue); 63 DoubleMatrix bounds = BoundsParameter.ActualValue; 64 if (bounds != null) BoundsChecker.Apply(result, bounds); 72 if (ParentsParameter.ActualValue.Length != 2) 73 throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators."); 74 75 SymbolicExpressionTree parent0 = ParentsParameter.ActualValue[0]; 76 SymbolicExpressionTree parent1 = ParentsParameter.ActualValue[1]; 77 78 IRandom random = RandomParameter.ActualValue; 79 ISymbolicExpressionGrammar grammar = SymbolicExpressionGrammarParameter.ActualValue; 80 81 // randomly swap parents to remove a possible bias from selection (e.g. when using gender-specific selection) 82 if (random.NextDouble() < 0.5) { 83 var tmp = parent0; 84 parent0 = parent1; 85 parent1 = tmp; 86 } 87 88 SymbolicExpressionTree result = Cross(random, grammar, parent0, parent1, 89 MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue); 90 Debug.Assert(result.Size <= MaxTreeSizeParameter.ActualValue.Value); 91 Debug.Assert(result.Height <= MaxTreeHeightParameter.ActualValue.Value); 92 Debug.Assert(grammar.IsValidExpression(result)); 65 93 ChildParameter.ActualValue = result; 66 94 return base.Apply(); 67 95 } 68 96 69 protected abstract RealVector Cross(IRandom random, ItemArray<RealVector> parents); 97 protected abstract SymbolicExpressionTree Cross(IRandom random, ISymbolicExpressionGrammar grammar, 98 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1, 99 IntValue maxTreeSize, IntValue maxTreeHeight); 70 100 } 71 101 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.3/SymbolicExpressionTreeNode.cs
r3223 r3237 93 93 SubTrees.RemoveAt(index); 94 94 } 95 96 public override IDeepCloneable Clone(Cloner cloner) { 97 SymbolicExpressionTreeNode clone = new SymbolicExpressionTreeNode(symbol); 98 cloner.RegisterClonedObject(this, clone); 99 foreach (var subtree in SubTrees) { 100 clone.AddSubTree((SymbolicExpressionTreeNode)subtree.Clone(cloner)); 101 } 102 return clone; 103 } 95 104 } 96 105 }
Note: See TracChangeset
for help on using the changeset viewer.