Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/06/21 12:14:02 (4 years ago)
Author:
gkronber
Message:

#3067: merged r17490:17492 and r17871:17872 from trunk to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding

  • stable/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs

    r17181 r17975  
    4343    private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
    4444    private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
     45    private const string CrossoverProbabilityParameterName = "CrossoverProbability";
    4546
    4647    #region Parameter Properties
     
    5354    public IValueLookupParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter {
    5455      get { return (IValueLookupParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; }
     56    }
     57    public IFixedValueParameter<PercentValue> CrossoverProbabilityParameter {
     58      get { return (IFixedValueParameter<PercentValue>)Parameters[CrossoverProbabilityParameterName]; }
    5559    }
    5660    #endregion
     
    6468    public IntValue MaximumSymbolicExpressionTreeDepth {
    6569      get { return MaximumSymbolicExpressionTreeDepthParameter.ActualValue; }
     70    }
     71    public double CrossoverProbability {
     72      get { return CrossoverProbabilityParameter.Value.Value; }
     73      set { CrossoverProbabilityParameter.Value.Value = value; }
    6674    }
    6775    #endregion
     
    7381      Parameters.Add(new ValueLookupParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, "The maximal length (number of nodes) of the symbolic expression tree."));
    7482      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      }
    7698    }
    7799
     
    82104    public override ISymbolicExpressionTree Crossover(IRandom random,
    83105      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1) {
    84       return Cross(random, parent0, parent1, InternalCrossoverPointProbability.Value,
     106      return Cross(random, parent0, parent1, CrossoverProbability, InternalCrossoverPointProbability.Value,
    85107        MaximumSymbolicExpressionTreeLength.Value, MaximumSymbolicExpressionTreeDepth.Value);
    86108    }
     
    88110    public static ISymbolicExpressionTree Cross(IRandom random,
    89111      ISymbolicExpressionTree parent0, ISymbolicExpressionTree parent1,
     112      double probability,
    90113      double internalCrossoverPointProbability, int maxTreeLength, int maxTreeDepth) {
     114      if ((probability < 1) && (random.NextDouble() >= probability)) return parent0;
    91115      // select a random crossover point in the first parent
    92116      CutPoint crossoverPoint0;
Note: See TracChangeset for help on using the changeset viewer.