Free cookie consent management tool by TermsFeed Policy Generator

source: addons/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/StringVector/StringVectorConstantsErc.cs @ 17507

Last change on this file since 17507 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: 2.0 KB
Line 
1using System.Linq;
2
3namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.StringVector {
4  using System.Collections.Generic;
5
6  using HeuristicLab.Common;
7  using HeuristicLab.Core;
8  using HeuristicLab.Data;
9  using HeuristicLab.Parameters;
10  using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11  using HeuristicLab.Random;
12
13  [StorableClass]
14  public class StringVectorConstantsErc : WeightedErcItem<IReadOnlyList<string>> {
15    private const string ConstantsParameterName = "Constants";
16
17    public StringVectorConstantsErc() : this(true, 1d) { }
18    public StringVectorConstantsErc(params string[][] arrays) : this(true, 1d, arrays.Select(x => new StringArray(x)).ToArray()) { }
19    public StringVectorConstantsErc(params StringArray[] arrays) : this(true, 1d, arrays) { }
20
21    public StringVectorConstantsErc(bool isEnabled, double weight = 1d, params StringArray[] arrays) : base(isEnabled, weight) {
22      Name = "String vector constants";
23      IsEnabled = isEnabled;
24      Parameters.Add(new ValueParameter<ItemCollection<StringArray>>(ConstantsParameterName, new ItemCollection<StringArray>(arrays)));
25    }
26
27    [StorableConstructor]
28    protected StringVectorConstantsErc(bool deserializing) : base(deserializing) { }
29
30    public StringVectorConstantsErc(StringVectorConstantsErc origin, Cloner cloner) : base(origin, cloner) { }
31
32    public IValueParameter<ItemCollection<StringArray>> ConstantsParameter
33    {
34      get { return (IValueParameter<ItemCollection<StringArray>>)Parameters[ConstantsParameterName]; }
35    }
36
37    public IEnumerable<StringArray> Constants
38    {
39      get { return ConstantsParameter.Value; }
40    }
41
42    public override IReadOnlyList<string> GetErcValue(IRandom random) {
43      // TODO: remove ToArray when ValueTypeArray implements IReadOnlyList
44      return Constants.SampleRandom(random).ToArray();
45    }
46
47    public override IDeepCloneable Clone(Cloner cloner) {
48      return new StringVectorConstantsErc(this, cloner);
49    }
50  }
51}
Note: See TracBrowser for help on using the repository browser.