Changeset 18069 for branches/3136_Structural_GP
- Timestamp:
- 10/19/21 13:39:44 (3 years ago)
- 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 32 32 this.infoLabel = new System.Windows.Forms.Label(); 33 33 this.templateStructureGroupBox = new System.Windows.Forms.GroupBox(); 34 this.linearScalingCheckBox = new System.Windows.Forms.CheckBox(); 34 35 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart(); 35 36 this.splitContainer = new System.Windows.Forms.SplitContainer(); … … 48 49 this.expressionInput.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) 49 50 | 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); 51 52 this.expressionInput.Name = "expressionInput"; 52 this.expressionInput.Size = new System.Drawing.Size(2 88, 20);53 this.expressionInput.Size = new System.Drawing.Size(291, 20); 53 54 this.expressionInput.TabIndex = 1; 54 55 this.expressionInput.TextChanged += new System.EventHandler(this.ExpressionInputTextChanged); 56 this.expressionInput.KeyUp += new System.Windows.Forms.KeyEventHandler(this.ExpressionInputKeyUp); 55 57 // 56 58 // parseButton 57 59 // 58 this.parseButton.Location = new System.Drawing.Point( 6, 45);60 this.parseButton.Location = new System.Drawing.Point(3, 45); 59 61 this.parseButton.Name = "parseButton"; 60 this.parseButton.Size = new System.Drawing.Size(14 3, 23);62 this.parseButton.Size = new System.Drawing.Size(140, 23); 61 63 this.parseButton.TabIndex = 3; 62 64 this.parseButton.Text = "Parse"; … … 64 66 this.parseButton.Click += new System.EventHandler(this.ParseButtonClick); 65 67 // 66 // errorLabel68 // infoLabel 67 69 // 68 70 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"; 71 74 this.infoLabel.Size = new System.Drawing.Size(54, 13); 72 75 this.infoLabel.TabIndex = 4; … … 75 78 // templateStructureGroupBox 76 79 // 80 this.templateStructureGroupBox.Controls.Add(this.linearScalingCheckBox); 81 this.templateStructureGroupBox.Controls.Add(this.infoLabel); 77 82 this.templateStructureGroupBox.Controls.Add(this.treeChart); 78 83 this.templateStructureGroupBox.Controls.Add(this.parseButton); 79 this.templateStructureGroupBox.Controls.Add(this.infoLabel);80 84 this.templateStructureGroupBox.Controls.Add(this.expressionInput); 81 85 this.templateStructureGroupBox.Dock = System.Windows.Forms.DockStyle.Fill; … … 87 91 this.templateStructureGroupBox.Text = "Template Structure"; 88 92 // 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 // 89 104 // treeChart 90 105 // … … 94 109 this.treeChart.BackgroundColor = System.Drawing.Color.White; 95 110 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); 97 112 this.treeChart.MinimumHorizontalDistance = 30; 98 113 this.treeChart.MinimumHorizontalPadding = 20; … … 102 117 this.treeChart.PreferredNodeHeight = 46; 103 118 this.treeChart.PreferredNodeWidth = 70; 104 this.treeChart.Size = new System.Drawing.Size(2 88, 320);119 this.treeChart.Size = new System.Drawing.Size(291, 320); 105 120 this.treeChart.SuspendRepaint = false; 106 121 this.treeChart.TabIndex = 7; … … 180 195 private MainForm.WindowsForms.ViewHost viewHost; 181 196 private System.Windows.Forms.GroupBox detailsGroupBox; 197 private System.Windows.Forms.CheckBox linearScalingCheckBox; 182 198 } 183 199 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/StructureTemplate/StructureTemplateView.cs
r18068 r18069 42 42 if (Content == null) return; 43 43 expressionInput.Text = Content.Template; 44 linearScalingCheckBox.Checked = Content.ApplyLinearScaling; 44 45 PaintTree(); 45 46 infoLabel.Text = ""; … … 47 48 48 49 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(); 60 51 } 61 52 … … 79 70 } 80 71 } 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 } 81 96 } 82 97 } -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/StructureTemplate.cs
r18068 r18069 19 19 set { 20 20 template = value; 21 tree = Parser.Parse(template); 22 GetSubFunctions(Tree); 21 Tree = Parser.Parse(template); 23 22 OnChanged(); 24 23 } … … 26 25 27 26 [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 } 30 38 31 39 [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 } 33 52 34 53 protected InfixExpressionParser Parser { get; set; } = new InfixExpressionParser(); … … 56 75 #endregion 57 76 58 private void GetSubFunctions(ISymbolicExpressionTree tree) {77 private Dictionary<string, SubFunction> GetSubFunctions() { 59 78 var subFunctions = new Dictionary<string, SubFunction>(); 60 foreach (var node in tree.IterateNodesPrefix())79 foreach (var node in Tree.IterateNodesPrefix()) 61 80 if (node is SubFunctionTreeNode subFunctionTreeNode) { 62 81 if (!subFunctionTreeNode.Arguments.Any()) … … 77 96 } 78 97 } 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; 80 127 } 81 128 -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/StructureTemplate/SubFunction.cs
r18068 r18069 42 42 } 43 43 44 [Storable] 44 45 public IEnumerable<string> Arguments { get; set; } 45 46 #endregion … … 63 64 private void OnParameterValueChanged(object sender, EventArgs e) => Changed?.Invoke(this, EventArgs.Empty); 64 65 65 protected SubFunction(SubFunction original, Cloner cloner) { } 66 protected SubFunction(SubFunction original, Cloner cloner) { 67 Arguments = original.Arguments; 68 } 66 69 67 70 [StorableConstructor] -
branches/3136_Structural_GP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Symbols/SubFunctionTreeNode.cs
r18068 r18069 15 15 public new SubFunctionSymbol Symbol => (SubFunctionSymbol)base.Symbol; 16 16 17 [Storable] 17 18 public IEnumerable<string> Arguments { get; set; } = Enumerable.Empty<string>(); 18 19 20 [Storable] 19 21 public string Name { get; set; } 20 22 #endregion … … 26 28 protected SubFunctionTreeNode(StorableConstructorFlag _) : base(_) { } 27 29 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 } 29 34 #endregion 30 35
Note: See TracChangeset
for help on using the changeset viewer.