Changeset 17490
- Timestamp:
- 04/02/20 09:40:32 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r17180 r17490 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<DoubleValue> CrossoverProbabilityParameter { 58 get { return (IFixedValueParameter<DoubleValue>)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 … … 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 83 Parameters.Add(new ValueLookupParameter<PercentValue>(InternalCrossoverPointProbabilityParameterName, "The probability to select an internal crossover point (instead of a leaf node).", new PercentValue(0.9))); 84 Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverProbabilityParameterName, "", new DoubleValue(1))); 85 } 86 87 [StorableHook(HookType.AfterDeserialization)] 88 private void AfterDeserialization() { 89 if (!Parameters.ContainsKey(CrossoverProbabilityParameterName)) { 90 Parameters.Add(new FixedValueParameter<DoubleValue>(CrossoverProbabilityParameterName, "", new DoubleValue(1))); 91 } 76 92 } 77 93 … … 82 98 public override ISymbolicExpressionTree Crossover(IRandom random, 83 99 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) { 84 return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,100 return Cross(random, parent0, parent1, CrossoverProbability, InternalCrossoverPointProbability.Value, 85 101 MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value); 86 102 } … … 88 104 public static ISymbolicExpressionTree Cross(IRandom random, 89 105 ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1, 106 double probability, 90 107 double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) { 108 if (random.NextDouble() >= probability) return random.NextDouble() < 0.5 ? parent0 : parent1; 91 109 // select a random crossover point in the first parent 92 110 CutPoint crossoverPoint0;
Note: See TracChangeset
for help on using the changeset viewer.