Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/String/StringConstantErc.cs @ 17714

Last change on this file since 17714 was 15032, checked in by pkimmesw, 8 years ago

#2665 Fixed bias 0 issue, PushExpressionFrequencyAnalyzer, Fixed probability for ERC settings, Fixed enable/disable instructions, Added expression descriptions

File size: 1.7 KB
Line 
1namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String {
2
3  using HeuristicLab.Common;
4  using HeuristicLab.Core;
5  using HeuristicLab.Data;
6  using HeuristicLab.Parameters;
7  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
8
9  [StorableClass]
10  public class StringConstantErc : WeightedErcItem<string> {
11
12    private const string ConstantsParameterName = "Constants";
13
14    public StringConstantErc() : this(true, 1d) { }
15
16    public StringConstantErc(params string[] constants) : this(true, 1d, constants) { }
17
18    public StringConstantErc(bool isEnabled, double weight = 1d, params string[] constants) : base(isEnabled, weight) {
19      Parameters.Add(new FixedValueParameter<StringArray>(ConstantsParameterName, new StringArray(constants)));
20      Constants.ToStringChanged += (sender, args) => UpdateName();
21      UpdateName();
22    }
23    private void UpdateName() {
24      Name = Constants.ToString();
25    }
26
27    [StorableConstructor]
28    public StringConstantErc(bool deserializing) : base(deserializing) {
29    }
30
31    public StringConstantErc(StringConstantErc origin, Cloner cloner) : base(origin, cloner) {
32    }
33
34    public IValueParameter<StringArray> ConstantsParameter
35    {
36      get { return (IValueParameter<StringArray>)Parameters[ConstantsParameterName]; }
37    }
38
39    public StringArray Constants
40    {
41      get { return ConstantsParameter.Value; }
42    }
43
44    public override IDeepCloneable Clone(Cloner cloner) {
45      return new StringConstantErc(this, cloner);
46    }
47
48    public override string GetErcValue(IRandom random) {
49      if (Constants.Length == 0) return string.Empty;
50
51      var x = random.Next(Constants.Length);
52      return Constants[x];
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.