Changeset 7477 for branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Timestamp:
- 02/16/12 13:53:28 (12 years ago)
- Location:
- branches/HeuristicLab.Crossovers
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.Crossovers
- Property svn:ignore
-
old new 19 19 protoc.exe 20 20 *.user 21 _ReSharper.HeuristicLab.Crossovers
-
- Property svn:ignore
-
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Property svn:ignore
-
old new 5 5 *.vs10x 6 6 Plugin.cs 7 *.bak
-
- Property svn:ignore
-
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers
-
Property
svn:ignore
set to
*.bak
-
Property
svn:ignore
set to
-
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r7259 r7477 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.PluginInfrastructure; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 37 38 /// </summary> 38 39 [Item("SubtreeCrossover", "An operator which performs subtree swapping crossover.")] 40 [NonDiscoverableType] 39 41 [StorableClass] 40 public sealedclass SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator {42 public class SubtreeCrossover : SymbolicExpressionTreeCrossover, ISymbolicExpressionTreeSizeConstraintOperator { 41 43 private const string InternalCrossoverPointProbabilityParameterName = "InternalCrossoverPointProbability"; 42 44 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 43 45 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 46 private const string SymbolicDataAnalysisEvaluationPartitionParameterName = "EvaluationPartition"; 47 44 48 #region Parameter Properties 45 49 public IValueLookupParameter<PercentValue> InternalCrossoverPointProbabilityParameter { … … 51 55 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 52 56 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 57 } 58 public IValueLookupParameter<IntRange> SymbolicDataAnalysisEvaluationPartitionParameter { 59 get { return (IValueLookupParameter<IntRange>)Parameters[SymbolicDataAnalysisEvaluationPartitionParameterName]; } 53 60 } 54 61 #endregion … … 65 72 #endregion 66 73 [StorableConstructor] 67 pr ivateSubtreeCrossover(bool deserializing) : base(deserializing) { }68 pr ivateSubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { }74 protected SubtreeCrossover(bool deserializing) : base(deserializing) { } 75 protected SubtreeCrossover(SubtreeCrossover original, Cloner cloner) : base(original, cloner) { } 69 76 public SubtreeCrossover() 70 77 : base() { … … 72 79 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 73 80 Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 81 Parameters.Add(new ValueLookupParameter<IntRange>(SymbolicDataAnalysisEvaluationPartitionParameterName, "The start index of the dataset partition on which the symbolic data analysis solution should be evaluated.")); 74 82 } 75 83 … … 82 90 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value, 83 91 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 92 } 93 94 public ISymbolicExpressionTree Crossover(IRandom random, ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 95 return Cross(random, parent0, parent1); 84 96 } 85 97 … … 94 106 // calculate the max length and depth that the inserted branch can have 95 107 int maxInsertedBranchLength = maxTreeLength - (parent0.Length - childLength); 96 int maxInsertedBranchDepth = maxTreeDepth - GetBranchLevel(parent0.Root,crossoverPoint0.Parent);108 int maxInsertedBranchDepth = maxTreeDepth - parent0.Root.GetBranchLevel(crossoverPoint0.Parent); 97 109 98 110 List<ISymbolicExpressionTreeNode> allowedBranches = new List<ISymbolicExpressionTreeNode>(); 99 111 parent1.Root.ForEachNodePostfix((n) => { 100 112 if (n.GetLength() <= maxInsertedBranchLength && 101 n.GetDepth() <= maxInsertedBranchDepth && 102 IsMatchingPointType(crossoverPoint0, n)) 113 n.GetDepth() <= maxInsertedBranchDepth && crossoverPoint0.IsMatchingPointType(n)) 103 114 allowedBranches.Add(n); 104 115 }); 105 116 // empty branch 106 if ( IsMatchingPointType(crossoverPoint0,null)) allowedBranches.Add(null);117 if (crossoverPoint0.IsMatchingPointType(null)) allowedBranches.Add(null); 107 118 108 119 if (allowedBranches.Count == 0) { … … 125 136 } 126 137 return parent0; 127 }128 }129 130 private static bool IsMatchingPointType(CutPoint cutPoint, ISymbolicExpressionTreeNode newChild) {131 var parent = cutPoint.Parent;132 if (newChild == null) {133 // make sure that one subtree can be removed and that only the last subtree is removed134 return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount &&135 cutPoint.ChildIndex == parent.SubtreeCount - 1;136 } else {137 // check syntax constraints of direct parent - child relation138 if (!parent.Grammar.ContainsSymbol(newChild.Symbol) ||139 !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, cutPoint.ChildIndex)) return false;140 141 bool result = true;142 // check point type for the whole branch143 newChild.ForEachNodePostfix((n) => {144 result =145 result &&146 parent.Grammar.ContainsSymbol(n.Symbol) &&147 n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) &&148 n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol);149 });150 return result;151 138 } 152 139 } … … 226 213 } 227 214 } 228 229 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) {230 if (root == point) return 0;231 foreach (var subtree in root.Subtrees) {232 int branchLevel = GetBranchLevel(subtree, point);233 if (branchLevel < int.MaxValue) return 1 + branchLevel;234 }235 return int.MaxValue;236 }237 215 } 238 216 } -
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/CutPoint.cs
r7259 r7477 22 22 23 23 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 24 internalclass CutPoint {24 public class CutPoint { 25 25 public ISymbolicExpressionTreeNode Parent { get; set; } 26 26 public ISymbolicExpressionTreeNode Child { get; set; } … … 39 39 this.Child = null; 40 40 } 41 42 public bool IsMatchingPointType(ISymbolicExpressionTreeNode newChild) { 43 var parent = this.Parent; 44 if (newChild == null) { 45 // make sure that one subtree can be removed and that only the last subtree is removed 46 return parent.Grammar.GetMinimumSubtreeCount(parent.Symbol) < parent.SubtreeCount && 47 this.ChildIndex == parent.SubtreeCount - 1; 48 } else { 49 // check syntax constraints of direct parent - child relation 50 if (!parent.Grammar.ContainsSymbol(newChild.Symbol) || 51 !parent.Grammar.IsAllowedChildSymbol(parent.Symbol, newChild.Symbol, this.ChildIndex)) 52 return false; 53 54 bool result = true; 55 // check point type for the whole branch 56 newChild.ForEachNodePostfix((n) => { 57 result = 58 result && 59 parent.Grammar.ContainsSymbol(n.Symbol) && 60 n.SubtreeCount >= parent.Grammar.GetMinimumSubtreeCount(n.Symbol) && 61 n.SubtreeCount <= parent.Grammar.GetMaximumSubtreeCount(n.Symbol); 62 }); 63 return result; 64 } 65 } 41 66 } 42 67 } -
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding-3.4.csproj
r7475 r7477 41 41 <DebugType>full</DebugType> 42 42 <Optimize>false</Optimize> 43 <OutputPath> $(SolutionDir)\bin\</OutputPath>43 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> 45 45 <ErrorReport>prompt</ErrorReport> … … 51 51 <DebugType>pdbonly</DebugType> 52 52 <Optimize>true</Optimize> 53 <OutputPath> $(SolutionDir)\bin\</OutputPath>53 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 54 54 <DefineConstants>TRACE</DefineConstants> 55 55 <ErrorReport>prompt</ErrorReport> -
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces
-
Property
svn:ignore
set to
*.bak
-
Property
svn:ignore
set to
-
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Interfaces/ISymbolicExpressionTreeNode.cs
r7259 r7477 32 32 int GetDepth(); 33 33 int GetLength(); 34 int GetBranchLevel(ISymbolicExpressionTreeNode child); 34 35 35 36 IEnumerable<ISymbolicExpressionTreeNode> IterateNodesPostfix(); -
branches/HeuristicLab.Crossovers/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/SymbolicExpressionTreeNode.cs
r7259 r7477 125 125 } 126 126 127 public int GetBranchLevel(ISymbolicExpressionTreeNode child) { 128 return GetBranchLevel(this, child); 129 } 130 131 private static int GetBranchLevel(ISymbolicExpressionTreeNode root, ISymbolicExpressionTreeNode point) { 132 if (root == point) 133 return 0; 134 foreach (var subtree in root.Subtrees) { 135 int branchLevel = GetBranchLevel(subtree, point); 136 if (branchLevel < int.MaxValue) 137 return 1 + branchLevel; 138 } 139 return int.MaxValue; 140 } 141 127 142 public virtual void ResetLocalParameters(IRandom random) { } 128 143 public virtual void ShakeLocalParameters(IRandom random, double shakingFactor) { }
Note: See TracChangeset
for help on using the changeset viewer.