namespace HeuristicLab.Problems.ProgramSynthesis.Base.Erc { using System; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Parameters; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; [StorableClass] public abstract class WeightedErcValueItem : ParameterizedNamedItem, IWeightedErcValueItem { private const string WeightParameterName = "Weight"; [Storable] protected bool isEnabled; public event EventHandler EnabledChanged; protected WeightedErcValueItem() : this(false, 1d) { } protected WeightedErcValueItem(bool isEnabled, double weigth) { this.isEnabled = isEnabled; Parameters.Add(new FixedValueParameter(WeightParameterName, new DoubleValue(weigth))); } [StorableConstructor] protected WeightedErcValueItem(bool deserializing) : base(deserializing) { } protected WeightedErcValueItem(WeightedErcValueItem origin, Cloner cloner) : base(origin, cloner) { isEnabled = origin.IsEnabled; } public IValueParameter WeightParameter { get { return (IValueParameter)Parameters[WeightParameterName]; } } public double Weight { get { return WeightParameter.Value.Value; } set { WeightParameter.Value.Value = value; } } public bool IsEnabled { get { return isEnabled; } set { if (value == isEnabled) return; isEnabled = value; if (EnabledChanged != null) EnabledChanged(this, value); } } public abstract T GetErcValue(IRandom random); } }