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 WeightedErcItem : ParameterizedNamedItem, IWeightedErcItem { private const string WeightParameterName = "Weight"; [Storable] protected bool isEnabled; public event EventHandler EnabledChanged; protected WeightedErcItem() : this(false, 1d) { } protected WeightedErcItem(bool isEnabled, double weigth) { this.isEnabled = isEnabled; Parameters.Add(new FixedValueParameter(WeightParameterName, new DoubleValue(weigth))); } [StorableConstructor] protected WeightedErcItem(bool deserializing) : base(deserializing) { } protected WeightedErcItem(WeightedErcItem 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); } }