source: branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs @ 18065

Last change on this file since 18065 was 18065, checked in by dpiringe, 9 months ago

#3136

  • modified InfixExpressionParser to fully support SubFunctionSymbol
    • created a SubFunctionTreeNode to store the function arguments
  • modified StructureTemplateView to regenerate the content state
  • first implementation for the main tree build up logic
File size: 3.7 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Threading.Tasks;
6using HeuristicLab.Core;
7using HEAL.Attic;
8using HeuristicLab.Common;
9using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
10using HeuristicLab.Parameters;
11using HeuristicLab.Data;
12
13namespace 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    private const string FunctionArgumentsParameterName = "Function Arguments";
21    #endregion
22
23    #region Parameters
24    public IValueParameter<ISymbolicDataAnalysisGrammar> GrammarParameter => (IValueParameter<ISymbolicDataAnalysisGrammar>)Parameters[GrammarParameterName];
25    public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeDepthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeDepthParameterName];
26    public IFixedValueParameter<IntValue> MaximumSymbolicExpressionTreeLengthParameter => (IFixedValueParameter<IntValue>)Parameters[MaximumSymbolicExpressionTreeLengthParameterName];
27    public IValueParameter<ReadOnlyItemList<StringValue>> FunctionArgumentsParameter => (IValueParameter<ReadOnlyItemList<StringValue>>)Parameters[FunctionArgumentsParameterName];
28    #endregion
29
30    #region Properties
31    public ISymbolicDataAnalysisGrammar Grammar {
32      get => GrammarParameter.Value;
33      set => GrammarParameter.Value = value;
34    }
35
36    public int MaximumSymbolicExpressionTreeDepth {
37      get => MaximumSymbolicExpressionTreeDepthParameter.Value.Value;
38      set => MaximumSymbolicExpressionTreeDepthParameter.Value.Value = value;
39    }
40
41    public int MaximumSymbolicExpressionTreeLength {
42      get => MaximumSymbolicExpressionTreeLengthParameter.Value.Value;
43      set => MaximumSymbolicExpressionTreeLengthParameter.Value.Value = value;
44    }
45
46    public IEnumerable<string> FunctionArguments {
47      get => FunctionArgumentsParameter.Value.Select(x => x.Value);
48      set {
49        var varSym = (Variable)Grammar.GetSymbol("Variable");
50        if (varSym == null)
51          throw new ArgumentException($"No variable symbol existent.");
52
53        FunctionArgumentsParameter.Value = new ItemList<StringValue>(value.Select(x => new StringValue(x))).AsReadOnly();
54
55        varSym.AllVariableNames = FunctionArguments;
56        varSym.VariableNames = FunctionArguments;
57        varSym.Enabled = true;
58      }
59    }
60    #endregion
61
62    #region Constructors
63    public SubFunction() {
64      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, new LinearScalingGrammar()));
65      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeDepthParameterName, new IntValue(10)));
66      Parameters.Add(new FixedValueParameter<IntValue>(MaximumSymbolicExpressionTreeLengthParameterName, new IntValue(30)));
67      Parameters.Add(new ValueParameter<ReadOnlyItemList<StringValue>>(FunctionArgumentsParameterName, new ReadOnlyItemList<StringValue>()));
68    }
69
70    protected SubFunction(SubFunction original, Cloner cloner) { }
71
72    [StorableConstructor]
73    protected SubFunction(StorableConstructorFlag _) : base(_) {}
74    #endregion
75
76    #region Cloning
77    public override IDeepCloneable Clone(Cloner cloner) =>
78      new SubFunction(this, cloner);
79    #endregion
80  }
81}
Note: See TracBrowser for help on using the repository browser.