Free cookie consent management tool by TermsFeed Policy Generator

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

#2665 Made ErcOptions checkable

File:
1 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  }
Note: See TracChangeset for help on using the changeset viewer.