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

Last change on this file since 18063 was 18063, checked in by dpiringe, 2 months ago

#3136

  • added view components and classes for sub functions
File size: 1.8 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;
10
11namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
12  [StorableType("E3C038DB-C6AA-457D-9F65-AF16C44CCE22")]
13  [Item("StructureTemplate", "Structure Template")]
14  public class StructureTemplate : Item {
15
16    [Storable]
17    private string template = "";
18    public string Template {
19      get => template;
20      set {
21        if(template != value) {
22          template = value;
23          tree = Parser.Parse(template);
24          subFunctions = GetSubFunctions(Tree);
25        }
26      }
27    }
28
29    [Storable]
30    private ISymbolicExpressionTree tree;
31    public ISymbolicExpressionTree Tree => tree;
32
33    [Storable]
34    private IEnumerable<SubFunction> subFunctions;
35    public IEnumerable<SubFunction> SubFunctions => subFunctions;
36
37    protected InfixExpressionParser Parser { get; set; } = new InfixExpressionParser();
38
39
40    #region Constructors
41    public StructureTemplate() { }
42
43    [StorableConstructor]
44    protected StructureTemplate(StorableConstructorFlag _) : base(_) { }
45
46    protected StructureTemplate(StructureTemplate original, Cloner cloner) { }
47    #endregion
48
49    #region Cloning
50    public override IDeepCloneable Clone(Cloner cloner) =>
51      new StructureTemplate(this, cloner);
52    #endregion
53
54    private IEnumerable<SubFunction> GetSubFunctions(ISymbolicExpressionTree tree) {
55      int count = 1;
56      foreach (var node in tree.IterateNodesPrefix())
57        if (node.Symbol is SubFunctionSymbol)
58          yield return new SubFunction() { Name = $"f{count++}" };
59    }
60  }
61}
Note: See TracBrowser for help on using the repository browser.