namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc { using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; [StorableClass] public abstract class ConstantsWeightedErcValue : WeightedErcValueItem where T : struct where TArray : ValueTypeArray, new() { private const string ConstantsParameterName = "Constants"; private readonly TArray array; // perf opt: reduce parameter getter usage protected ConstantsWeightedErcValue(TArray array) { this.array = array; Parameters.Add(new FixedValueParameter(ConstantsParameterName, array)); } [StorableConstructor] protected ConstantsWeightedErcValue(bool deserializing) : base(deserializing) { array = ConstantsParameter.Value; } protected ConstantsWeightedErcValue(ConstantsWeightedErcValue origin, Cloner cloner) : base(origin, cloner) { } public IValueParameter ConstantsParameter { get { return (IValueParameter)Parameters[ConstantsParameterName]; } } public TArray Constants { get { return ConstantsParameter.Value; } } public override T GetErcValue(IRandom random) { var x = random.Next(array.Length); return array[x]; } } }