namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc { using System.Collections.Generic; using System.Linq; using Common; using Core; using Data; using Parameters; using Persistence.Default.CompositeSerializers.Storable; using Random; [StorableClass] public abstract class VectorConstantsErcValue : WeightedErcValueItem> where T : struct where TValue : ValueTypeArray { private const string ConstantsParameterName = "Constants"; private readonly TValue[] arrays; // perf opt: avoid using parameter getter protected VectorConstantsErcValue(params TValue[] arrays) : this(true, arrays) { } protected VectorConstantsErcValue(bool isEnabled, params TValue[] arrays) { this.arrays = arrays; IsEnabled = isEnabled; Parameters.Add(new ValueParameter>(ConstantsParameterName, new ItemArray(arrays))); } [StorableConstructor] private VectorConstantsErcValue(bool deserializing) : base(deserializing) { } protected VectorConstantsErcValue(VectorConstantsErcValue origin, Cloner cloner) : base(origin, cloner) { } public IValueParameter> ConstantsParameter { get { return (IValueParameter>)Parameters[ConstantsParameterName]; } } public IEnumerable Constants { get { return ConstantsParameter.Value; } } public override IReadOnlyList GetErcValue(IRandom random) { // TODO: remove ToList when ValueTypeArray implements IReadOnlyList return arrays.SampleRandom(random).ToList(); } } }