Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/19/21 13:39:44 (3 years ago)
Author:
dpiringe
Message:

#3136

  • added linear scaling support for structure template parameter
Location:
branches/3136_Structural_GP
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.Designer.cs

    r18068 r18069  
    3232      this.infoLabel = new System.Windows.Forms.Label();
    3333      this.templateStructureGroupBox = new System.Windows.Forms.GroupBox();
     34      this.linearScalingCheckBox = new System.Windows.Forms.CheckBox();
    3435      this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    3536      this.splitContainer = new System.Windows.Forms.SplitContainer();
     
    4849      this.expressionInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
    4950            | System.Windows.Forms.AnchorStyles.Right)));
    50       this.expressionInput.Location = new System.Drawing.Point(6, 19);
     51      this.expressionInput.Location = new System.Drawing.Point(3, 19);
    5152      this.expressionInput.Name = "expressionInput";
    52       this.expressionInput.Size = new System.Drawing.Size(288, 20);
     53      this.expressionInput.Size = new System.Drawing.Size(291, 20);
    5354      this.expressionInput.TabIndex = 1;
    5455      this.expressionInput.TextChanged += new System.EventHandler(this.ExpressionInputTextChanged);
     56      this.expressionInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.ExpressionInputKeyUp);
    5557      //
    5658      // parseButton
    5759      //
    58       this.parseButton.Location = new System.Drawing.Point(6, 45);
     60      this.parseButton.Location = new System.Drawing.Point(3, 45);
    5961      this.parseButton.Name = "parseButton";
    60       this.parseButton.Size = new System.Drawing.Size(143, 23);
     62      this.parseButton.Size = new System.Drawing.Size(140, 23);
    6163      this.parseButton.TabIndex = 3;
    6264      this.parseButton.Text = "Parse";
     
    6466      this.parseButton.Click += new System.EventHandler(this.ParseButtonClick);
    6567      //
    66       // errorLabel
     68      // infoLabel
    6769      //
    6870      this.infoLabel.AutoSize = true;
    69       this.infoLabel.Location = new System.Drawing.Point(155, 50);
    70       this.infoLabel.Name = "errorLabel";
     71      this.infoLabel.BackColor = System.Drawing.Color.White;
     72      this.infoLabel.Location = new System.Drawing.Point(3, 74);
     73      this.infoLabel.Name = "infoLabel";
    7174      this.infoLabel.Size = new System.Drawing.Size(54, 13);
    7275      this.infoLabel.TabIndex = 4;
     
    7578      // templateStructureGroupBox
    7679      //
     80      this.templateStructureGroupBox.Controls.Add(this.linearScalingCheckBox);
     81      this.templateStructureGroupBox.Controls.Add(this.infoLabel);
    7782      this.templateStructureGroupBox.Controls.Add(this.treeChart);
    7883      this.templateStructureGroupBox.Controls.Add(this.parseButton);
    79       this.templateStructureGroupBox.Controls.Add(this.infoLabel);
    8084      this.templateStructureGroupBox.Controls.Add(this.expressionInput);
    8185      this.templateStructureGroupBox.Dock = System.Windows.Forms.DockStyle.Fill;
     
    8791      this.templateStructureGroupBox.Text = "Template Structure";
    8892      //
     93      // linearScalingCheckBox
     94      //
     95      this.linearScalingCheckBox.AutoSize = true;
     96      this.linearScalingCheckBox.Location = new System.Drawing.Point(149, 49);
     97      this.linearScalingCheckBox.Name = "linearScalingCheckBox";
     98      this.linearScalingCheckBox.Size = new System.Drawing.Size(122, 17);
     99      this.linearScalingCheckBox.TabIndex = 8;
     100      this.linearScalingCheckBox.Text = "Apply Linear Scaling";
     101      this.linearScalingCheckBox.UseVisualStyleBackColor = true;
     102      this.linearScalingCheckBox.CheckStateChanged += new System.EventHandler(this.LinearScalingCheckBoxCheckStateChanged);
     103      //
    89104      // treeChart
    90105      //
     
    94109      this.treeChart.BackgroundColor = System.Drawing.Color.White;
    95110      this.treeChart.LineColor = System.Drawing.Color.Black;
    96       this.treeChart.Location = new System.Drawing.Point(6, 74);
     111      this.treeChart.Location = new System.Drawing.Point(3, 74);
    97112      this.treeChart.MinimumHorizontalDistance = 30;
    98113      this.treeChart.MinimumHorizontalPadding = 20;
     
    102117      this.treeChart.PreferredNodeHeight = 46;
    103118      this.treeChart.PreferredNodeWidth = 70;
    104       this.treeChart.Size = new System.Drawing.Size(288, 320);
     119      this.treeChart.Size = new System.Drawing.Size(291, 320);
    105120      this.treeChart.SuspendRepaint = false;
    106121      this.treeChart.TabIndex = 7;
     
    180195    private MainForm.WindowsForms.ViewHost viewHost;
    181196    private System.Windows.Forms.GroupBox detailsGroupBox;
     197    private System.Windows.Forms.CheckBox linearScalingCheckBox;
    182198  }
    183199}
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs

    r18068 r18069  
    4242      if (Content == null) return;
    4343      expressionInput.Text = Content.Template;
     44      linearScalingCheckBox.Checked = Content.ApplyLinearScaling;
    4445      PaintTree();
    4546      infoLabel.Text = "";
     
    4748
    4849    private void ParseButtonClick(object sender, EventArgs e) {
    49       if(!string.IsNullOrEmpty(expressionInput.Text)) {
    50         try {
    51           Content.Template = expressionInput.Text;
    52           PaintTree();
    53           infoLabel.Text = "Template structure successfully parsed.";
    54           infoLabel.ForeColor = Color.DarkGreen;
    55         } catch (Exception ex) {
    56           infoLabel.Text = ex.Message;
    57           infoLabel.ForeColor = Color.DarkRed;
    58         }
    59       }
     50      Parse();
    6051    }
    6152
     
    7970      }
    8071    }
     72
     73    private void ExpressionInputKeyUp(object sender, KeyEventArgs e) {
     74      if (e.KeyCode == Keys.Enter)
     75        Parse();
     76    }
     77
     78    private void Parse() {
     79      if (!string.IsNullOrEmpty(expressionInput.Text)) {
     80        try {
     81          Content.Template = expressionInput.Text;
     82          PaintTree();
     83          infoLabel.Text = "Template structure successfully parsed.";
     84          infoLabel.ForeColor = Color.DarkGreen;
     85        } catch (Exception ex) {
     86          infoLabel.Text = ex.Message;
     87          infoLabel.ForeColor = Color.DarkRed;
     88        }
     89      }
     90    }
     91
     92    private void LinearScalingCheckBoxCheckStateChanged(object sender, EventArgs e) {
     93      Content.ApplyLinearScaling = linearScalingCheckBox.Checked;
     94      PaintTree();
     95    }
    8196  }
    8297}
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs

    r18068 r18069  
    1919      set {
    2020        template = value;
    21         tree = Parser.Parse(template);
    22         GetSubFunctions(Tree);
     21        Tree = Parser.Parse(template);
    2322        OnChanged();
    2423      }
     
    2625
    2726    [Storable]
    28     private ISymbolicExpressionTree tree;
    29     public ISymbolicExpressionTree Tree => tree;
     27    private ISymbolicExpressionTree treeWithoutLinearScaling;
     28    [Storable]
     29    private ISymbolicExpressionTree treeWithLinearScaling;
     30    public ISymbolicExpressionTree Tree {
     31      get => ApplyLinearScaling ? treeWithLinearScaling : treeWithoutLinearScaling;
     32      private set {
     33        treeWithLinearScaling = AddLinearScalingTerms(value);
     34        treeWithoutLinearScaling = value;
     35        SubFunctions = GetSubFunctions();
     36      }
     37    }
    3038
    3139    [Storable]
    32     public IReadOnlyDictionary<string, SubFunction> SubFunctions { get; private set; } = new Dictionary<string, SubFunction>();
     40    public IReadOnlyDictionary<string, SubFunction> SubFunctions { get; private set; }
     41
     42    [Storable]
     43    private bool applyLinearScaling = false;
     44    public bool ApplyLinearScaling {
     45      get => applyLinearScaling;
     46      set {
     47        applyLinearScaling = value;
     48        //subFunctions = GetSubFunctions();
     49        OnChanged();
     50      }
     51    }
    3352
    3453    protected InfixExpressionParser Parser { get; set; } = new InfixExpressionParser();
     
    5675    #endregion
    5776
    58     private void GetSubFunctions(ISymbolicExpressionTree tree) {
     77    private Dictionary<string, SubFunction> GetSubFunctions() {
    5978      var subFunctions = new Dictionary<string, SubFunction>();
    60       foreach (var node in tree.IterateNodesPrefix())
     79      foreach (var node in Tree.IterateNodesPrefix())
    6180        if (node is SubFunctionTreeNode subFunctionTreeNode) {
    6281          if (!subFunctionTreeNode.Arguments.Any())
     
    7796          }
    7897        }
    79       SubFunctions = subFunctions;
     98      return subFunctions;
     99    }
     100
     101    private ISymbolicExpressionTree AddLinearScalingTerms(ISymbolicExpressionTree tree) {
     102      var clonedTree = (ISymbolicExpressionTree)tree.Clone();
     103      var startNode = clonedTree.Root.Subtrees.First();
     104      var template = startNode.Subtrees.First();
     105
     106      var add = new Addition();
     107      var addNode = add.CreateTreeNode();
     108
     109      var mul = new Multiplication();
     110      var mulNode = mul.CreateTreeNode();
     111
     112      var c1 = new Constant();
     113      var c1Node = (ConstantTreeNode)c1.CreateTreeNode();
     114      c1Node.Value = 0.0;
     115      var c2 = new Constant();
     116      var c2Node = (ConstantTreeNode)c2.CreateTreeNode();
     117      c2Node.Value = 1.0;
     118     
     119      addNode.AddSubtree(c1Node);
     120      addNode.AddSubtree(mulNode);
     121      mulNode.AddSubtree(c2Node);
     122       
     123      startNode.RemoveSubtree(0);
     124      startNode.AddSubtree(addNode);
     125      mulNode.AddSubtree(template);
     126      return clonedTree;
    80127    }
    81128
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs

    r18068 r18069  
    4242    }
    4343
     44    [Storable]
    4445    public IEnumerable<string> Arguments { get; set; }
    4546    #endregion
     
    6364    private void OnParameterValueChanged(object sender, EventArgs e) => Changed?.Invoke(this, EventArgs.Empty);
    6465
    65     protected SubFunction(SubFunction original, Cloner cloner) { }
     66    protected SubFunction(SubFunction original, Cloner cloner) {
     67      Arguments = original.Arguments;
     68    }
    6669
    6770    [StorableConstructor]
  • branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionTreeNode.cs

    r18068 r18069  
    1515    public new SubFunctionSymbol Symbol => (SubFunctionSymbol)base.Symbol;
    1616
     17    [Storable]
    1718    public IEnumerable<string> Arguments { get; set; } = Enumerable.Empty<string>();
    1819   
     20    [Storable]
    1921    public string Name { get; set; }
    2022    #endregion
     
    2628    protected SubFunctionTreeNode(StorableConstructorFlag _) : base(_) { }
    2729
    28     protected SubFunctionTreeNode(SubFunctionTreeNode original, Cloner cloner) : base(original, cloner) { }
     30    protected SubFunctionTreeNode(SubFunctionTreeNode original, Cloner cloner) : base(original, cloner) {
     31      Arguments = original.Arguments;
     32      Name = (string)original.Name.Clone();
     33    }
    2934    #endregion
    3035
Note: See TracChangeset for help on using the changeset viewer.