[18063] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Linq;
|
---|
| 4 | using System.Text;
|
---|
| 5 | using System.Threading.Tasks;
|
---|
| 6 | using HeuristicLab.Core;
|
---|
| 7 | using HEAL.Attic;
|
---|
| 8 | using HeuristicLab.Common;
|
---|
| 9 | using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
|
---|
| 10 | using HeuristicLab.Parameters;
|
---|
| 11 | using HeuristicLab.Data;
|
---|
| 12 |
|
---|
| 13 | namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
|
---|
| 14 | [StorableType("598B5DCB-95AC-465A-920B-E1E6DACFFA4B")]
|
---|
| 15 | public class SubFunction : ParameterizedNamedItem {
|
---|
| 16 | #region Constants
|
---|
| 17 | private const string GrammarParameterName = "Grammar";
|
---|
| 18 | private const string MaximumSymbolicExpressionTreeDepthParameterName = "MaximumSymbolicExpressionTreeDepth";
|
---|
| 19 | private const string MaximumSymbolicExpressionTreeLengthParameterName = "MaximumSymbolicExpressionTreeLength";
|
---|
| 20 | #endregion
|
---|
| 21 |
|
---|
| 22 | #region Parameters
|
---|
| 23 | public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName];
|
---|
| 24 | public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName];
|
---|
| 25 | public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName];
|
---|
| 26 | #endregion
|
---|
| 27 |
|
---|
| 28 | #region Properties
|
---|
| 29 | public ISymbolicDataAnalysisGrammar Grammar {
|
---|
| 30 | get => GrammarParameter.Value;
|
---|
| 31 | set => GrammarParameter.Value = value;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | public int MaximumSymbolicExpressionTreeDepth {
|
---|
| 35 | get => MaximumSymbolicExpressionTreeDepthParameter.Value.Value;
|
---|
| 36 | set => MaximumSymbolicExpressionTreeDepthParameter.Value.Value = value;
|
---|
| 37 | }
|
---|
| 38 |
|
---|
| 39 | public int MaximumSymbolicExpressionTreeLength {
|
---|
| 40 | get => MaximumSymbolicExpressionTreeLengthParameter.Value.Value;
|
---|
| 41 | set => MaximumSymbolicExpressionTreeLengthParameter.Value.Value = value;
|
---|
| 42 | }
|
---|
[18065] | 43 |
|
---|
[18069] | 44 | [Storable]
|
---|
[18068] | 45 | public IEnumerable<string> Arguments { get; set; }
|
---|
| 46 | #endregion
|
---|
[18065] | 47 |
|
---|
[18068] | 48 | #region Events
|
---|
| 49 | public event EventHandler Changed;
|
---|
[18063] | 50 | #endregion
|
---|
| 51 |
|
---|
| 52 | #region Constructors
|
---|
| 53 | public SubFunction() {
|
---|
| 54 | Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new LinearScalingGrammar()));
|
---|
| 55 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(10)));
|
---|
| 56 | Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(30)));
|
---|
[18068] | 57 |
|
---|
| 58 | // TODO: separate events for each parameter
|
---|
| 59 | GrammarParameter.ValueChanged += OnParameterValueChanged;
|
---|
| 60 | MaximumSymbolicExpressionTreeDepthParameter.Value.ValueChanged += OnParameterValueChanged;
|
---|
| 61 | MaximumSymbolicExpressionTreeLengthParameter.Value.ValueChanged += OnParameterValueChanged;
|
---|
[18063] | 62 | }
|
---|
| 63 |
|
---|
[18068] | 64 | private void OnParameterValueChanged(object sender, EventArgs e) => Changed?.Invoke(this, EventArgs.Empty);
|
---|
| 65 |
|
---|
[18069] | 66 | protected SubFunction(SubFunction original, Cloner cloner) {
|
---|
| 67 | Arguments = original.Arguments;
|
---|
| 68 | }
|
---|
[18063] | 69 |
|
---|
| 70 | [StorableConstructor]
|
---|
| 71 | protected SubFunction(StorableConstructorFlag _) : base(_) {}
|
---|
| 72 | #endregion
|
---|
| 73 |
|
---|
| 74 | #region Cloning
|
---|
| 75 | public override IDeepCloneable Clone(Cloner cloner) =>
|
---|
| 76 | new SubFunction(this, cloner);
|
---|
| 77 | #endregion
|
---|
| 78 | }
|
---|
| 79 | }
|
---|