using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using HeuristicLab.Core; using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding; using HeuristicLab.Parameters; using HeuristicLab.Data; namespace HeuristicLab.Problems.DataAnalysis.Symbolic { [StorableType("598B5DCB-95AC-465A-920B-E1E6DACFFA4B")] public class SubFunction : ParameterizedNamedItem { #region Constants private const string GrammarParameterName = "Grammar"; private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth"; private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength"; #endregion #region Parameters public IValueParameter GrammarParameter => (IValueParameter)Parameters[GrammarParameterName]; public IFixedValueParameter MaximumSymbolicExpressionTreeDepthParameter => (IFixedValueParameter)Parameters[MaximumSymbolicExpressionTreeDepthParameterName]; public IFixedValueParameter MaximumSymbolicExpressionTreeLengthParameter => (IFixedValueParameter)Parameters[MaximumSymbolicExpressionTreeLengthParameterName]; #endregion #region Properties public ISymbolicDataAnalysisGrammar Grammar { get => GrammarParameter.Value; set => GrammarParameter.Value = value; } public int MaximumSymbolicExpressionTreeDepth { get => MaximumSymbolicExpressionTreeDepthParameter.Value.Value; set => MaximumSymbolicExpressionTreeDepthParameter.Value.Value = value; } public int MaximumSymbolicExpressionTreeLength { get => MaximumSymbolicExpressionTreeLengthParameter.Value.Value; set => MaximumSymbolicExpressionTreeLengthParameter.Value.Value = value; } [Storable] public IEnumerable Arguments { get; set; } #endregion #region Events public event EventHandler Changed; #endregion #region Constructors public SubFunction() { Parameters.Add(new ValueParameter(GrammarParameterName, new LinearScalingGrammar())); Parameters.Add(new FixedValueParameter(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(10))); Parameters.Add(new FixedValueParameter(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(30))); // TODO: separate events for each parameter GrammarParameter.ValueChanged += OnParameterValueChanged; MaximumSymbolicExpressionTreeDepthParameter.Value.ValueChanged += OnParameterValueChanged; MaximumSymbolicExpressionTreeLengthParameter.Value.ValueChanged += OnParameterValueChanged; } private void OnParameterValueChanged(object sender, EventArgs e) => Changed?.Invoke(this, EventArgs.Empty); protected SubFunction(SubFunction original, Cloner cloner) { Arguments = original.Arguments; } [StorableConstructor] protected SubFunction(StorableConstructorFlag _) : base(_) {} #endregion #region Cloning public override IDeepCloneable Clone(Cloner cloner) => new SubFunction(this, cloner); #endregion } }