- Timestamp:
- 05/06/21 12:14:02 (4 years ago)
- Location:
- stable
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk merged: 17490-17492,17871-17872
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
/trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding merged: 17490-17491,17871-17872
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r17181 r17975 43 43 private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; 44 44 private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; 45 private const string CrossoverProbabilityParameterName = "CrossoverProbability"; 45 46 46 47 #region Parameter Properties … … 53 54 public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter { 54 55 get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; } 56 } 57 public IFixedValueParameter<PercentValue> CrossoverProbabilityParameter { 58 get { return (IFixedValueParameter<PercentValue>)Parameters[CrossoverProbabilityParameterName]; } 55 59 } 56 60 #endregion … … 64 68 public IntValue MaximumSymbolicExpressionTreeDepth { 65 69 get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; } 70 } 71 public double CrossoverProbability { 72 get { return CrossoverProbabilityParameter.Value.Value; } 73 set { CrossoverProbabilityParameter.Value.Value = value; } 66 74 } 67 75 #endregion … … 73 81 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree.")); 74 82 Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, "The maximal depth of the symbolic expression tree (a tree with one node has depth = 0).")); 75 Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 83 Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9, true))); 84 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(1, true))); 85 } 86 87 [StorableHook(HookType.AfterDeserialization)] 88 private void AfterDeserialization() { 89 // replace with PercentValue for files which had CrossoverProbability as DoubleValue 90 if (Parameters.ContainsKey(CrossoverProbabilityParameterName) && (Parameters[CrossoverProbabilityParameterName] is IFixedValueParameter<DoubleValue> oldParam)) { 91 var oldValue = oldParam.Value.Value; 92 Parameters.Remove(oldParam); 93 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(oldValue))); 94 } 95 if (!Parameters.ContainsKey(CrossoverProbabilityParameterName)) { 96 Parameters.Add(new FixedValueParameter<PercentValue>(CrossoverProbabilityParameterName, "The probability that a crossover is performed. Otherwise a copy of the first parent is returned.", new PercentValue(1, true))); 97 } 76 98 } 77 99 … … 82 104 public override ISymbolicExpressionTree Crossover(IRandom random, 83 105 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 84 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,106 return Cross(random, parent0, parent1, CrossoverProbability, InternalCrossoverPointProbability.Value, 85 107 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 86 108 } … … 88 110 public static ISymbolicExpressionTree Cross(IRandom random, 89 111 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1, 112 double probability, 90 113 double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) { 114 if ((probability < 1) && (random.NextDouble() >= probability)) return parent0; 91 115 // select a random crossover point in the first parent 92 116 CutPoint crossoverPoint0;
Note: See TracChangeset
for help on using the changeset viewer.