Free cookie consent management tool by TermsFeed Policy Generator

Changeset 18067 for branches


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
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Regression/3.4/SingleObjective/StructuredSymbolicRegressionSingleObjectiveProblem.cs

    r18066 r18067  
    8282      Parameters.Add(new ValueParameter<ISymbolicDataAnalysisGrammar>(GrammarParameterName, grammar));
    8383
    84       structureTemplate.Template = "f(x)*f(y)+5";
     84      //structureTemplate.Template = "f(x)*f(y)+5";
    8585    }
    8686
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.Designer.cs

    r18063 r18067  
    11
     2using System.Drawing;
     3
    24namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    35  partial class StructureTemplateView {
     
    2527    /// </summary>
    2628    private void InitializeComponent() {
     29      this.components = new System.ComponentModel.Container();
    2730      this.expressionInput = new System.Windows.Forms.TextBox();
    2831      this.parseButton = new System.Windows.Forms.Button();
     
    3033      this.symRegTreeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.GraphicalSymbolicExpressionTreeView();
    3134      this.templateStructureGroupBox = new System.Windows.Forms.GroupBox();
     35      this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    3236      this.splitContainer = new System.Windows.Forms.SplitContainer();
    33       this.subFunctionListView = new HeuristicLab.Problems.DataAnalysis.Symbolic.Views.SubFunctionListView();
     37      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    3438      this.templateStructureGroupBox.SuspendLayout();
    3539      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    7175      //
    7276      this.symRegTreeChart.AllowDrop = true;
    73       this.symRegTreeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
    74             | System.Windows.Forms.AnchorStyles.Left)
     77      this.symRegTreeChart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    7578            | System.Windows.Forms.AnchorStyles.Right)));
    7679      this.symRegTreeChart.Caption = "Graphical SymbolicExpressionTree View";
     
    7982      this.symRegTreeChart.Name = "symRegTreeChart";
    8083      this.symRegTreeChart.ReadOnly = false;
    81       this.symRegTreeChart.Size = new System.Drawing.Size(288, 320);
     84      this.symRegTreeChart.Size = new System.Drawing.Size(288, 153);
    8285      this.symRegTreeChart.TabIndex = 6;
    8386      //
    8487      // templateStructureGroupBox
    8588      //
     89      this.templateStructureGroupBox.Controls.Add(this.treeChart);
    8690      this.templateStructureGroupBox.Controls.Add(this.symRegTreeChart);
    8791      this.templateStructureGroupBox.Controls.Add(this.parseButton);
     
    9599      this.templateStructureGroupBox.TabStop = false;
    96100      this.templateStructureGroupBox.Text = "Template Structure";
     101      //
     102      // treeChart
     103      //
     104      this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
     105            | System.Windows.Forms.AnchorStyles.Right)));
     106      this.treeChart.BackgroundColor = System.Drawing.Color.White;
     107      this.treeChart.LineColor = System.Drawing.Color.Black;
     108      this.treeChart.Location = new System.Drawing.Point(6, 233);
     109      this.treeChart.MinimumHorizontalDistance = 30;
     110      this.treeChart.MinimumHorizontalPadding = 20;
     111      this.treeChart.MinimumVerticalDistance = 30;
     112      this.treeChart.MinimumVerticalPadding = 20;
     113      this.treeChart.Name = "treeChart";
     114      this.treeChart.PreferredNodeHeight = 46;
     115      this.treeChart.PreferredNodeWidth = 70;
     116      this.treeChart.Size = new System.Drawing.Size(288, 150);
     117      this.treeChart.SuspendRepaint = false;
     118      this.treeChart.TabIndex = 7;
     119      this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F);
     120      this.treeChart.Tree = null;
    97121      //
    98122      // splitContainer
     
    110134      // splitContainer.Panel2
    111135      //
    112       this.splitContainer.Panel2.Controls.Add(this.subFunctionListView);
     136      this.splitContainer.Panel2.Controls.Add(this.viewHost);
    113137      this.splitContainer.Panel2MinSize = 5;
    114138      this.splitContainer.Size = new System.Drawing.Size(600, 400);
     
    116140      this.splitContainer.TabIndex = 10;
    117141      //
    118       // subFunctionListView
     142      // viewHost
    119143      //
    120       this.subFunctionListView.Caption = "View";
    121       this.subFunctionListView.Content = null;
    122       this.subFunctionListView.Dock = System.Windows.Forms.DockStyle.Fill;
    123       this.subFunctionListView.Location = new System.Drawing.Point(0, 0);
    124       this.subFunctionListView.Name = "subFunctionListView";
    125       this.subFunctionListView.ReadOnly = false;
    126       this.subFunctionListView.Size = new System.Drawing.Size(296, 400);
    127       this.subFunctionListView.TabIndex = 7;
     144      this.viewHost.Caption = "View";
     145      this.viewHost.Content = null;
     146      this.viewHost.Dock = System.Windows.Forms.DockStyle.Fill;
     147      this.viewHost.Enabled = false;
     148      this.viewHost.Location = new System.Drawing.Point(0, 0);
     149      this.viewHost.Name = "viewHost";
     150      this.viewHost.ReadOnly = false;
     151      this.viewHost.Size = new System.Drawing.Size(296, 400);
     152      this.viewHost.TabIndex = 8;
     153      this.viewHost.ViewsLabelVisible = true;
     154      this.viewHost.ViewType = null;
    128155      //
    129156      // StructureTemplateView
     
    149176    private System.Windows.Forms.Label errorLabel;
    150177    private Encodings.SymbolicExpressionTreeEncoding.Views.GraphicalSymbolicExpressionTreeView symRegTreeChart;
    151     private SubFunctionListView subFunctionListView;
    152178    private System.Windows.Forms.GroupBox templateStructureGroupBox;
    153179    private System.Windows.Forms.SplitContainer splitContainer;
     180    private Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart treeChart;
     181    private MainForm.WindowsForms.ViewHost viewHost;
    154182  }
    155183}
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs

    r18065 r18067  
    88using HeuristicLab.Data;
    99using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding;
     10using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views;
    1011using HeuristicLab.MainForm;
    1112using HeuristicLab.MainForm.WindowsForms;
     
    2425      InitializeComponent();
    2526      errorLabel.Text = "";
     27      treeChart.SymbolicExpressionTreeNodeClicked += TreeChart_SymbolicExpressionTreeNodeClicked;
     28    }
     29
     30    private void TreeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     31      var visualTreeNode = sender as VisualTreeNode<ISymbolicExpressionTreeNode>;
     32      if(visualTreeNode != null) {
     33        var subFunctionTreeNode = visualTreeNode.Content as SubFunctionTreeNode;
     34        viewHost.Content = subFunctionTreeNode?.SubFunction;
     35      }
    2636    }
    2737
     
    3242      expressionInput.Text = Content.Template;
    3343      symRegTreeChart.Content = Content.Tree;
    34       subFunctionListView.Content = new ItemList<SubFunction>(Content.SubFunctions.Values).AsReadOnly();
    35      
     44
     45      treeChart.Tree = Content.Tree;
     46
    3647      errorLabel.Text = "";
    3748     
     
    4354          Content.Template = expressionInput.Text;
    4455          symRegTreeChart.Content = Content.Tree;
    45 
    46           var subFunctionList = new ItemList<SubFunction>();
    47           foreach (var func in Content.SubFunctions.Values)
    48             subFunctionList.Add(func);
    49           subFunctionListView.Content = subFunctionList.AsReadOnly();
     56          treeChart.Tree = Content.Tree;
    5057
    5158          errorLabel.Text = "Template structure successfully parsed.";
  • 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.