Changeset 7411
- Timestamp:
- 01/25/12 17:26:29 (13 years ago)
- Location:
- branches/HeuristicLab.TreeSimplifierView
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r7388 r7411 32 32 private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes; 33 33 private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines; 34 private VisualSymbolicExpressionTreeNode selectedNode = null;34 private VisualSymbolicExpressionTreeNode selectedNode; 35 35 36 36 public SymbolicExpressionTreeChart() { -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r7388 r7411 217 217 </BootstrapperPackage> 218 218 </ItemGroup> 219 <ItemGroup> 220 <EmbeddedResource Include="InteractiveSymbolicDataAnalysisSolutionSimplifierView.resx"> 221 <DependentUpon>InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs</DependentUpon> 222 </EmbeddedResource> 223 <EmbeddedResource Include="SymbolicExpressionTreeNodeChangeValueDialog.resx"> 224 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon> 225 </EmbeddedResource> 226 </ItemGroup> 219 227 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 220 228 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs
r7388 r7411 53 53 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart(); 54 54 this.grpViewHost = new System.Windows.Forms.GroupBox(); 55 this.btnPrune = new System.Windows.Forms.Button(); 56 this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker(); 55 57 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 56 58 this.splitContainer.Panel1.SuspendLayout(); … … 64 66 // viewHost 65 67 // 66 this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 67 | System.Windows.Forms.AnchorStyles.Left) 68 this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 69 | System.Windows.Forms.AnchorStyles.Left) 68 70 | System.Windows.Forms.AnchorStyles.Right))); 69 71 this.viewHost.Caption = "View"; … … 97 99 // grpSimplify 98 100 // 101 this.grpSimplify.AutoSize = true; 99 102 this.grpSimplify.Controls.Add(this.flowLayoutPanel); 100 103 this.grpSimplify.Controls.Add(this.treeChart); … … 109 112 // flowLayoutPanel 110 113 // 111 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 114 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 112 115 | System.Windows.Forms.AnchorStyles.Right))); 113 116 this.flowLayoutPanel.Controls.Add(this.btnSimplify); 117 this.flowLayoutPanel.Controls.Add(this.btnPrune); 114 118 this.flowLayoutPanel.Controls.Add(this.btnOptimizeConstants); 115 119 this.flowLayoutPanel.Location = new System.Drawing.Point(6, 313); … … 133 137 this.btnOptimizeConstants.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 134 138 this.btnOptimizeConstants.Enabled = false; 135 this.btnOptimizeConstants.Location = new System.Drawing.Point( 104, 3);139 this.btnOptimizeConstants.Location = new System.Drawing.Point(205, 3); 136 140 this.btnOptimizeConstants.Name = "btnOptimizeConstants"; 137 141 this.btnOptimizeConstants.Size = new System.Drawing.Size(97, 23); … … 143 147 // treeChart 144 148 // 145 this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 146 | System.Windows.Forms.AnchorStyles.Left) 149 this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 150 | System.Windows.Forms.AnchorStyles.Left) 147 151 | System.Windows.Forms.AnchorStyles.Right))); 148 152 this.treeChart.BackgroundColor = System.Drawing.Color.White; … … 171 175 this.grpViewHost.Text = "Details"; 172 176 // 177 // btnPrune 178 // 179 this.btnPrune.Location = new System.Drawing.Point(104, 3); 180 this.btnPrune.Name = "btnPrune"; 181 this.btnPrune.Size = new System.Drawing.Size(95, 23); 182 this.btnPrune.TabIndex = 3; 183 this.btnPrune.Text = "Prune"; 184 this.btnPrune.UseVisualStyleBackColor = true; 185 this.btnPrune.Click += new System.EventHandler(this.btnPrune_Click); 186 // 187 // backgroundWorker1 188 // 189 this.backgroundWorker1.WorkerSupportsCancellation = true; 190 this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork); 191 this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted); 192 // 173 193 // InteractiveSymbolicDataAnalysisSolutionSimplifierView 174 194 // … … 179 199 this.Size = new System.Drawing.Size(564, 348); 180 200 this.splitContainer.Panel1.ResumeLayout(false); 201 this.splitContainer.Panel1.PerformLayout(); 181 202 this.splitContainer.Panel2.ResumeLayout(false); 182 203 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).EndInit(); … … 199 220 private System.Windows.Forms.FlowLayoutPanel flowLayoutPanel; 200 221 protected System.Windows.Forms.Button btnOptimizeConstants; 222 private System.Windows.Forms.Button btnPrune; 223 private System.ComponentModel.BackgroundWorker backgroundWorker1; 201 224 } 202 225 } -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r7388 r7411 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.ComponentModel; 24 25 using System.Drawing; 25 26 using System.Linq; … … 36 37 private Dictionary<ISymbolicExpressionTreeNode, double> originalValues; 37 38 private bool updateInProgress = false; 39 private VisualSymbolicExpressionTreeNode visualTreeNode; // need some kind of state for correctly handling events 38 40 39 41 public InteractiveSymbolicDataAnalysisSolutionSimplifierView() { … … 129 131 130 132 private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { 131 VisualSymbolicExpressionTreeNodevisualTreeNode = (VisualSymbolicExpressionTreeNode)sender;133 visualTreeNode = (VisualSymbolicExpressionTreeNode)sender; 132 134 var tree = Content.Model.SymbolicExpressionTree; 133 135 // check if the node value/weight has been altered … … 189 191 190 192 private void treeChart_SymbolicExpressionTreeNodeChanged(object sender, EventArgs e) { 191 var tree = Content.Model.SymbolicExpressionTree; 192 var visualTreeNode = sender as VisualSymbolicExpressionTreeNode; 193 visualTreeNode = sender as VisualSymbolicExpressionTreeNode; 193 194 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 194 195 string title = String.Empty; … … 203 204 } 204 205 206 double originalValue = value; 207 205 208 if (!originalValues.ContainsKey(subTree)) 206 209 originalValues.Add(subTree, value); 207 var dialog = new ValueChangeDialog(title, Math.Round(value,4).ToString()); 210 else originalValue = originalValues[subTree]; 211 212 var dialog = new ValueChangeDialog(title, Math.Round(originalValue, 4).ToString(), Math.Round(value, 4).ToString()); 213 dialog.NewValueTextBox.Validated += OnNewValueValidated; 208 214 dialog.ShowDialog(this); 209 if (dialog.DialogResult == DialogResult.OK) { 210 value = double.Parse(dialog.NewValue); 211 if (subTree.Symbol is Constant) 212 (subTree as ConstantTreeNode).Value = value; 213 else if (subTree.Symbol is Variable) 214 (subTree as VariableTreeNode).Weight = value; 215 // show only interesting part of solution 216 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 217 updateInProgress = true; 218 UpdateModel(tree); 219 updateInProgress = false; 220 } 215 } 216 217 private void OnNewValueValidated(object sender, EventArgs e) { 218 var textBox = sender as TextBox; 219 var value = double.Parse(textBox.Text); 220 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 221 var tree = Content.Model.SymbolicExpressionTree; 222 223 if (subTree.Symbol is Constant) 224 (subTree as ConstantTreeNode).Value = value; 225 else if (subTree.Symbol is Variable) 226 (subTree as VariableTreeNode).Weight = value; 227 228 // show only interesting part of solution 229 treeChart.Tree = tree.Root.SubtreeCount > 1 ? new SymbolicExpressionTree(tree.Root) : new SymbolicExpressionTree(tree.Root.GetSubtree(0).GetSubtree(0)); 230 updateInProgress = true; 231 UpdateModel(tree); 232 updateInProgress = false; 221 233 } 222 234 … … 238 250 double min = impacts.Min(); 239 251 foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { 252 VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 253 bool flag1 = replacementNodes.ContainsKey(treeNode); 254 bool flag2 = originalValues.ContainsKey(treeNode); 255 bool flag3 = treeNode is ConstantTreeNode; 256 257 if (flag2) // constant or variable node was changed 258 visualTree.ToolTip += Environment.NewLine + "Original value: " + originalValues[treeNode]; 259 else if (flag1 && flag3) // node was folded to a constant 260 visualTree.ToolTip += Environment.NewLine + "Original node: " + replacementNodes[treeNode]; 261 240 262 if (!(treeNode is ConstantTreeNode) && nodeImpacts.ContainsKey(treeNode)) { 241 263 double impact = nodeImpacts[treeNode]; 242 VisualSymbolicExpressionTreeNode visualTree = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode);243 264 244 265 // impact = 0 if no change … … 267 288 private void PaintCollapsedNodes() { 268 289 foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { 269 if (originalValues.ContainsKey(treeNode)) 270 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.Blue; 271 else if (treeNode is ConstantTreeNode && replacementNodes.ContainsKey(treeNode)) 272 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DarkOrange; 273 else { 274 VisualSymbolicExpressionTreeNode visNode = treeChart.GetVisualSymbolicExpressionTreeNode(treeNode); 275 if (visNode != null) 276 visNode.LineColor = Color.Black; 290 bool flag1 = replacementNodes.ContainsKey(treeNode); 291 bool flag2 = originalValues.ContainsKey(treeNode); 292 if (flag1 && treeNode is ConstantTreeNode) { 293 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = flag2 ? Color.DarkViolet : Color.DarkOrange; 294 } else if (flag2) { 295 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DodgerBlue; 277 296 } 278 297 } … … 285 304 } 286 305 306 private void btnPrune_Click(object sender, EventArgs e) { 307 backgroundWorker1.RunWorkerAsync(); 308 } 309 310 private static IEnumerable<ISymbolicExpressionTreeNode> GetNodesAtDepth(ISymbolicExpressionTreeNode root, Data.IntRange range) { 311 var list = new List<Tuple<ISymbolicExpressionTreeNode, int>> { new Tuple<ISymbolicExpressionTreeNode, int>(root, 0) }; 312 int offset = 0; 313 int level = 0; 314 while (level < range.End) { 315 ++level; 316 int count = list.Count; 317 for (int i = offset; i != count; ++i) { 318 if (list[i].Item1.Subtrees.Any()) 319 list.AddRange(from s in list[i].Item1.Subtrees select new Tuple<ISymbolicExpressionTreeNode, int>(s, level)); 320 } 321 offset = count; 322 } 323 // taking advantage of the fact that the list is already sorted by level 324 for (int i = list.Count - 1; i >= 0; --i) { 325 if (list[i].Item2 >= range.Start) 326 yield return list[i].Item1; 327 else break; 328 } 329 } 330 287 331 protected abstract void btnOptimizeConstants_Click(object sender, EventArgs e); 332 333 private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { 334 BackgroundWorker worker = sender as BackgroundWorker; 335 PruneTree(worker); 336 337 } 338 339 private void PruneTree(BackgroundWorker worker) { 340 var tree = Content.Model.SymbolicExpressionTree; 341 // get all tree nodes 342 foreach (var node in GetNodesAtDepth(tree.Root, new Data.IntRange(2, tree.Depth))) { 343 if (worker.CancellationPending) 344 break; // pruning cancelled 345 if (!(node.Symbol is Constant) && nodeImpacts.ContainsKey(node) && nodeImpacts[node] < 0.001) { 346 SwitchNodeWithReplacementNode(node.Parent, node.Parent.IndexOfSubtree(node)); 347 CalculateReplacementNodesAndNodeImpacts(); 348 } 349 } 350 } 351 352 private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { 353 if (e.Cancelled) { 354 // The user canceled the operation. 355 } else if (e.Error != null) { 356 // There was an error during the operation. 357 // Error-handling 358 } else { 359 // The operation completed normally. We can update the model 360 UpdateModel(Content.Model.SymbolicExpressionTree); 361 } 362 } 288 363 } 289 364 } -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicExpressionTreeNodeChangeValueDialog.Designer.cs
r7388 r7411 46 46 private void InitializeComponent() { 47 47 this.components = new System.ComponentModel.Container(); 48 this.okButton = new System.Windows.Forms.Button(); 49 this.oldValueLabel = new System.Windows.Forms.Label(); 50 this.oldValueTextBox = new System.Windows.Forms.TextBox(); 48 this.originalValueLabel = new System.Windows.Forms.Label(); 49 this.originalValueTextBox = new System.Windows.Forms.TextBox(); 51 50 this.newValueTextBox = new System.Windows.Forms.TextBox(); 52 51 this.newValueLabel = new System.Windows.Forms.Label(); … … 55 54 this.SuspendLayout(); 56 55 // 57 // o kButton56 // originalValueLabel 58 57 // 59 this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); 60 this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK; 61 this.okButton.Enabled = false; 62 this.okButton.Location = new System.Drawing.Point(66, 74); 63 this.okButton.Name = "okButton"; 64 this.okButton.Size = new System.Drawing.Size(75, 23); 65 this.okButton.TabIndex = 0; 66 this.okButton.Text = "&OK"; 67 this.okButton.UseVisualStyleBackColor = true; 68 this.okButton.Click += new System.EventHandler(this.okButton_Click); 58 this.originalValueLabel.AutoSize = true; 59 this.originalValueLabel.Location = new System.Drawing.Point(14, 15); 60 this.originalValueLabel.Name = "originalValueLabel"; 61 this.originalValueLabel.Size = new System.Drawing.Size(72, 13); 62 this.originalValueLabel.TabIndex = 2; 63 this.originalValueLabel.Text = "Original Value"; 69 64 // 70 // o ldValueLabel65 // originalValueTextBox 71 66 // 72 this.oldValueLabel.AutoSize = true; 73 this.oldValueLabel.Location = new System.Drawing.Point(14, 15); 74 this.oldValueLabel.Name = "oldValueLabel"; 75 this.oldValueLabel.Size = new System.Drawing.Size(53, 13); 76 this.oldValueLabel.TabIndex = 2; 77 this.oldValueLabel.Text = "Old Value"; 78 // 79 // oldValueTextBox 80 // 81 this.oldValueTextBox.Location = new System.Drawing.Point(91, 12); 82 this.oldValueTextBox.Name = "oldValueTextBox"; 83 this.oldValueTextBox.ReadOnly = true; 84 this.oldValueTextBox.Size = new System.Drawing.Size(100, 20); 85 this.oldValueTextBox.TabIndex = 3; 67 this.originalValueTextBox.Location = new System.Drawing.Point(91, 12); 68 this.originalValueTextBox.Name = "originalValueTextBox"; 69 this.originalValueTextBox.ReadOnly = true; 70 this.originalValueTextBox.Size = new System.Drawing.Size(100, 20); 71 this.originalValueTextBox.TabIndex = 3; 86 72 // 87 73 // newValueTextBox … … 90 76 this.newValueTextBox.Name = "newValueTextBox"; 91 77 this.newValueTextBox.Size = new System.Drawing.Size(100, 20); 92 this.newValueTextBox.TabIndex = 4;78 this.newValueTextBox.TabIndex = 0; 93 79 this.newValueTextBox.KeyDown += new System.Windows.Forms.KeyEventHandler(this.newValueTextBox_KeyDown); 94 80 this.newValueTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.newValueTextBox_Validating); … … 98 84 // 99 85 this.newValueLabel.AutoSize = true; 100 this.newValueLabel.Location = new System.Drawing.Point( 8, 41);86 this.newValueLabel.Location = new System.Drawing.Point(14, 41); 101 87 this.newValueLabel.Name = "newValueLabel"; 102 88 this.newValueLabel.Size = new System.Drawing.Size(59, 13); … … 115 101 this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 116 102 this.AutoSize = true; 117 this.ClientSize = new System.Drawing.Size(209, 109);103 this.ClientSize = new System.Drawing.Size(209, 71); 118 104 this.Controls.Add(this.newValueLabel); 119 105 this.Controls.Add(this.newValueTextBox); 120 this.Controls.Add(this.oldValueTextBox); 121 this.Controls.Add(this.oldValueLabel); 122 this.Controls.Add(this.okButton); 106 this.Controls.Add(this.originalValueTextBox); 107 this.Controls.Add(this.originalValueLabel); 123 108 this.MaximizeBox = false; 124 109 this.MinimizeBox = false; … … 136 121 #endregion 137 122 138 protected System.Windows.Forms.Button okButton; 139 private System.Windows.Forms.Label oldValueLabel; 140 private System.Windows.Forms.TextBox oldValueTextBox; 123 private System.Windows.Forms.Label originalValueLabel; 124 private System.Windows.Forms.TextBox originalValueTextBox; 141 125 private System.Windows.Forms.TextBox newValueTextBox; 142 126 private System.Windows.Forms.Label newValueLabel; -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/SymbolicExpressionTreeNodeChangeValueDialog.cs
r7388 r7411 24 24 using System.Text; 25 25 using System.Windows.Forms; 26 using HeuristicLab.Common;27 26 using HeuristicLab.Data; 28 27 … … 38 37 } 39 38 } 40 public string O ldValue {41 get { return o ldValueTextBox.Text; }39 public string OriginalValue { 40 get { return originalValueTextBox.Text; } 42 41 set { 43 42 if (InvokeRequired) 44 43 Invoke(new Action<string>(x => this.NewValue = x), value); 45 44 else 46 o ldValueTextBox.Text = value;45 originalValueTextBox.Text = value; 47 46 } 48 47 } … … 56 55 } 57 56 } 57 public TextBox NewValueTextBox { 58 get { return newValueTextBox; } 59 } 58 60 59 61 public ValueChangeDialog() { 60 62 InitializeComponent(); 63 originalValueTextBox.TabStop = false; // cannot receive focus using tab key 61 64 } 62 public ValueChangeDialog(string caption, string o ldValue)65 public ValueChangeDialog(string caption, string originalValue, string newValue) 63 66 : this() { 64 67 Caption = caption; 65 O ldValue = oldValue;66 NewValue = string.Empty;68 OriginalValue = originalValue; 69 NewValue = newValue; 67 70 } 68 71 … … 84 87 if (!Validate(newValueTextBox.Text, out errorMessage)) { 85 88 e.Cancel = true; 86 okButton.Enabled = false;87 89 errorProvider.SetError(newValueTextBox, errorMessage); 88 90 newValueTextBox.SelectAll(); … … 91 93 private void newValueTextBox_Validated(object sender, EventArgs e) { 92 94 errorProvider.SetError(newValueTextBox, string.Empty); 93 okButton.Enabled = true;94 95 } 95 96
Note: See TracChangeset
for help on using the changeset viewer.