namespace HeuristicLab.Problems.ProgramSynthesis { using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; [StorableClass] public abstract class ConstantsWeightedErc : WeightedErcItem where T : struct where TArray : ValueTypeArray, new() { private const string ConstantsParameterName = "Constants"; protected ConstantsWeightedErc(TArray array) : this(true, array) { } protected ConstantsWeightedErc(bool isEnabled, TArray array, double weight = 1d) : base(isEnabled, weight) { Parameters.Add(new FixedValueParameter(ConstantsParameterName, array)); array.ToStringChanged += (sender, args) => UpdateName(); UpdateName(); } private void UpdateName() { Name = Constants.ToString(); } [StorableConstructor] protected ConstantsWeightedErc(bool deserializing) : base(deserializing) { } protected ConstantsWeightedErc(ConstantsWeightedErc 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) { if (Constants.Length == 0) return default(T); var x = random.Next(Constants.Length); return Constants[x]; } } }