namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc.String { using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; [StorableClass] public class StringConstantErc : WeightedErcItem { private const string ConstantsParameterName = "Constants"; public StringConstantErc() : this(true, 1d) { } public StringConstantErc(params string[] constants) : this(true, 1d, constants) { } public StringConstantErc(bool isEnabled, double weight = 1d, params string[] constants) : base(isEnabled, weight) { Parameters.Add(new FixedValueParameter(ConstantsParameterName, new StringArray(constants))); Constants.ToStringChanged += (sender, args) => UpdateName(); UpdateName(); } private void UpdateName() { Name = Constants.ToString(); } [StorableConstructor] public StringConstantErc(bool deserializing) : base(deserializing) { } public StringConstantErc(StringConstantErc origin, Cloner cloner) : base(origin, cloner) { } public IValueParameter ConstantsParameter { get { return (IValueParameter)Parameters[ConstantsParameterName]; } } public StringArray Constants { get { return ConstantsParameter.Value; } } public override IDeepCloneable Clone(Cloner cloner) { return new StringConstantErc(this, cloner); } public override string GetErcValue(IRandom random) { if (Constants.Length == 0) return string.Empty; var x = random.Next(Constants.Length); return Constants[x]; } } }