Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/02/17 20:42:40 (8 years ago)
Author:
pkimmesw
Message:

#2665 Made ErcOptions checkable

Location:
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/String
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/String/StringConstantErcValue.cs

    r14898 r14905  
    11namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String {
    2   using System.Collections.Generic;
    32
    43  using HeuristicLab.Common;
     
    1211
    1312    private const string ConstantsParameterName = "Constants";
    14     private readonly StringArray array; // perf opt: reduce parameter getter usage
    1513
    16     public StringConstantErcValue() : this(new string[0]) { }
     14    public StringConstantErcValue() : this(false, 1d) { }
    1715
    18     public StringConstantErcValue(params string[] constants) {
     16    public StringConstantErcValue(params string[] constants) : this(true, 1d, constants) { }
     17
     18    public StringConstantErcValue(bool isEnabled, double weight = 1d, params string[] constants) : base(isEnabled, weight) {
    1919      Name = "String constants";
    20       array = new StringArray(constants);
    21       Parameters.Add(new FixedValueParameter<StringArray>(ConstantsParameterName, array));
     20      Parameters.Add(new FixedValueParameter<StringArray>(ConstantsParameterName, new StringArray(constants)));
    2221    }
    2322
     
    3433    }
    3534
    36     public IEnumerable<string> Constants
     35    public StringArray Constants
    3736    {
    3837      get { return ConstantsParameter.Value; }
     
    4443
    4544    public override string GetErcValue(IRandom random) {
    46       var x = random.Next(array.Length);
    47       return array[x];
     45      if (Constants.Length == 0) return string.Empty;
     46
     47      var x = random.Next(Constants.Length);
     48      return Constants[x];
    4849    }
    4950  }
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/String/StringRandomErcValue.cs

    r14898 r14905  
    2727    private const string NewStringProbabilityParameterDescription = "The probability that the selection of the ephemeral random string constant for inclusion in randomly generated code will produce a new string (rather than a string that was previously generated).";
    2828
    29     public StringRandomErcValue() {
     29    public StringRandomErcValue() : base(false, 1d) { }
     30
     31    public StringRandomErcValue(bool isEnabled, double weight = 1d) : base(isEnabled, weight) {
    3032      Name = "String random";
    3133      Parameters.Add(new FixedValueParameter<BoolValue>(AllowLowercaseLettersParameterName, new BoolValue(true)));
Note: See TracChangeset for help on using the changeset viewer.