Changeset 14905 for branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/String
- Timestamp:
- 05/02/17 20:42:40 (8 years ago)
- 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 1 1 namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String { 2 using System.Collections.Generic;3 2 4 3 using HeuristicLab.Common; … … 12 11 13 12 private const string ConstantsParameterName = "Constants"; 14 private readonly StringArray array; // perf opt: reduce parameter getter usage15 13 16 public StringConstantErcValue() : this( new string[0]) { }14 public StringConstantErcValue() : this(false, 1d) { } 17 15 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) { 19 19 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))); 22 21 } 23 22 … … 34 33 } 35 34 36 public IEnumerable<string>Constants35 public StringArray Constants 37 36 { 38 37 get { return ConstantsParameter.Value; } … … 44 43 45 44 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]; 48 49 } 49 50 } -
branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/String/StringRandomErcValue.cs
r14898 r14905 27 27 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)."; 28 28 29 public StringRandomErcValue() { 29 public StringRandomErcValue() : base(false, 1d) { } 30 31 public StringRandomErcValue(bool isEnabled, double weight = 1d) : base(isEnabled, weight) { 30 32 Name = "String random"; 31 33 Parameters.Add(new FixedValueParameter<BoolValue>(AllowLowercaseLettersParameterName, new BoolValue(true)));
Note: See TracChangeset
for help on using the changeset viewer.