Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis.Base/Erc/StringVector/StringVectorConstantsErc.cs @ 14952

Last change on this file since 14952 was 14952, checked in by pkimmesw, 7 years ago

#2665 Added IsNoop to Expression, Made Expressions storable, Fixed Debugger, Fixed and improved problem data and result visualisation, Added custom ErcOption view, Added problem difficulty to problem data name

File size: 1.9 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(false, 1d) { }
18    public StringVectorConstantsErc(params StringArray[] arrays) : this(true, 1d, arrays) { }
19
20    public StringVectorConstantsErc(bool isEnabled, double weight = 1d, params StringArray[] arrays) : base(isEnabled, weight) {
21      Name = "String vector constants";
22      IsEnabled = isEnabled;
23      Parameters.Add(new ValueParameter<ItemCollection<StringArray>>(ConstantsParameterName, new ItemCollection<StringArray>(arrays)));
24    }
25
26    [StorableConstructor]
27    protected StringVectorConstantsErc(bool deserializing) : base(deserializing) { }
28
29    public StringVectorConstantsErc(StringVectorConstantsErc origin, Cloner cloner) : base(origin, cloner) { }
30
31    public IValueParameter<ItemCollection<StringArray>> ConstantsParameter
32    {
33      get { return (IValueParameter<ItemCollection<StringArray>>)Parameters[ConstantsParameterName]; }
34    }
35
36    public IEnumerable<StringArray> Constants
37    {
38      get { return ConstantsParameter.Value; }
39    }
40
41    public override IReadOnlyList<string> GetErcValue(IRandom random) {
42      // TODO: remove ToArray when ValueTypeArray implements IReadOnlyList
43      return Constants.SampleRandom(random).ToArray();
44    }
45
46    public override IDeepCloneable Clone(Cloner cloner) {
47      return new StringVectorConstantsErc(this, cloner);
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.