Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/14/21 17:59:53 (3 years ago)
Author:
dpiringe
Message:

#3136

  • changed the StructureTemplateView -> nodes of type SubFunctionTreeNode are now clickable
    • still need to overhaul the UI elements
  • added a way to parse SubFunctionTreeNode with a unique name in InfixExpressionParser
Location:
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Importer/InfixExpressionParser.cs

    r18065 r18067  
    8181    internal static readonly BidirectionalLookup<string, ISymbol>
    8282      knownSymbols = new BidirectionalLookup<string, ISymbol>(StringComparer.InvariantCulture, new SymbolComparer());
     83    internal static readonly SubFunctionSymbol subFunctionSymbol = new SubFunctionSymbol();
    8384
    8485    private Constant constant = new Constant();
     
    137138        { "XOR", new Xor()},
    138139        { "DIFF", new Derivative()},
    139         { "LAG", new LaggedVariable() },
    140         { "F", new SubFunctionSymbol() }
     140        { "LAG", new LaggedVariable() }/*,
     141        { "F", new SubFunctionSymbol() }*/
    141142      };
    142143
     
    341342
    342343    private ISymbol GetSymbol(string tok) {
    343       var symb = knownSymbols.GetByFirst(tok).FirstOrDefault();
    344       if (symb == null) throw new ArgumentException(string.Format("Unknown token {0} found.", tok));
    345       return symb;
     344      if(knownSymbols.ContainsFirst(tok))
     345        return knownSymbols.GetByFirst(tok).FirstOrDefault();
     346      else
     347        return subFunctionSymbol;
    346348    }
    347349
     
    453455            laggedVarNode.Lag = (int)Math.Round(sign * lagToken.doubleVal);
    454456            laggedVarNode.Weight = 1.0;
    455           } else if (funcNode.Symbol is SubFunctionSymbol) {
     457          } else if (funcNode.Symbol is SubFunctionSymbol) { // SubFunction
    456458            var subFunction = funcNode as SubFunctionTreeNode;
     459            subFunction.Name = next.strVal;
    457460            // input arguments
    458461            var args = ParseArgList(tokens);
    459             IList<string> functionArguments = new List<string>();
     462            IList<string> arguments = new List<string>();
    460463            foreach (var arg in args)
    461464              if(arg is VariableTreeNode varTreeNode)
    462                 functionArguments.Add(varTreeNode.VariableName);
    463             subFunction.FunctionArguments = functionArguments;
     465                arguments.Add(varTreeNode.VariableName);
     466            subFunction.Arguments = arguments;
    464467          } else {
    465468            // functions
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs

    r18066 r18067  
    6262        if (node is SubFunctionTreeNode subFunctionTreeNode) {
    6363          var subFunction = new SubFunction() {
    64             Name = $"f{count++}({string.Join(",", subFunctionTreeNode.FunctionArguments)})",
    65             FunctionArguments = subFunctionTreeNode.FunctionArguments
     64            Name = $"f{count++}({string.Join(",", subFunctionTreeNode.Arguments)})",
     65            FunctionArguments = subFunctionTreeNode.Arguments
    6666          };
    6767          subFunctionTreeNode.SubFunction = subFunction;
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs

    r18065 r18067  
    4444    }
    4545
    46     public IEnumerable<string> FunctionArguments {
     46    public IEnumerable<string> FunctionArguments { // TODO: gehört weg
    4747      get => FunctionArgumentsParameter.Value.Select(x => x.Value);
    4848      set {
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionTreeNode.cs

    r18066 r18067  
    1010namespace HeuristicLab.Problems.DataAnalysis.Symbolic {
    1111  [StorableType("05130B5F-0125-4367-A4E9-C42D1085024E")]
    12   public class SubFunctionTreeNode : SymbolicExpressionTreeNode {
     12  public class SubFunctionTreeNode : SymbolicExpressionTreeNode { //TODO: as TerminalNode? -> but has children in a fully builded tree
    1313
    1414    #region Properties
    1515    public new SubFunctionSymbol Symbol => (SubFunctionSymbol)base.Symbol;
    1616
    17     public IEnumerable<string> FunctionArguments { get; set; } = Enumerable.Empty<string>();
     17    public IEnumerable<string> Arguments { get; set; } = Enumerable.Empty<string>();
    1818   
    1919    public SubFunction SubFunction { get; set; }
     20
     21    public string Name { get; set; }
    2022    #endregion
    2123
     
    3436    public override IDeepCloneable Clone(Cloner cloner) => new SubFunctionTreeNode(this, cloner);
    3537    #endregion
     38
     39    public override string ToString() {
     40      if (string.IsNullOrEmpty(Name))
     41        return base.ToString();
     42      return Name;
     43    }
     44   
    3645  }
    3746}
Note: See TracChangeset for help on using the changeset viewer.