- Timestamp:
- 05/06/13 14:07:17 (12 years ago)
- Location:
- trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.Designer.cs
r9055 r9445 54 54 this.btnSimplify = new System.Windows.Forms.Button(); 55 55 this.treeStatusLabel = new System.Windows.Forms.Label(); 56 this.treeChart = new HeuristicLab. Problems.DataAnalysis.Symbolic.Views.InteractiveSymbolicExpressionTreeChart();56 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart(); 57 57 this.grpViewHost = new System.Windows.Forms.GroupBox(); 58 58 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); … … 176 176 this.treeChart.LineColor = System.Drawing.Color.Black; 177 177 this.treeChart.Location = new System.Drawing.Point(6, 32); 178 this.treeChart.ModifyTree = null;179 178 this.treeChart.Name = "treeChart"; 180 179 this.treeChart.Size = new System.Drawing.Size(201, 332); … … 220 219 #endregion 221 220 222 private InteractiveSymbolicExpressionTreeChart treeChart;221 private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart treeChart; 223 222 private System.Windows.Forms.SplitContainer splitContainer; 224 223 private HeuristicLab.MainForm.WindowsForms.ViewHost viewHost; -
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r9055 r9445 33 33 public abstract partial class InteractiveSymbolicDataAnalysisSolutionSimplifierView : AsynchronousContentView { 34 34 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes; 35 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes;36 35 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 37 36 private enum TreeState { Valid, Invalid } … … 41 40 InitializeComponent(); 42 41 foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); 43 changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();44 42 nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 45 43 this.Caption = "Interactive Solution Simplifier"; 46 47 // initialize the tree modifier that will be used to perform edit operations over the tree48 treeChart.ModifyTree = Modify;49 }50 51 /// <summary>52 /// Remove, Replace or Insert subtrees53 /// </summary>54 /// <param name="tree">The symbolic expression tree</param>55 /// <param name="node">The insertion point (ie, the parent node who will receive a new child)</param>56 /// <param name="oldChild">The subtree to be replaced</param>57 /// <param name="newChild">The replacement subtree</param>58 /// <param name="removeSubtree">Flag used to indicate if whole subtrees should be removed (default behavior), or just the subtree root</param>59 private void Modify(ISymbolicExpressionTree tree, ISymbolicExpressionTreeNode node, ISymbolicExpressionTreeNode oldChild, ISymbolicExpressionTreeNode newChild, bool removeSubtree = true) {60 if (oldChild == null && newChild == null) throw new ArgumentException();61 if (oldChild == null) { // insertion operation62 node.AddSubtree(newChild);63 newChild.Parent = node;64 } else if (newChild == null) { // removal operation65 node.RemoveSubtree(node.IndexOfSubtree(oldChild));66 changedNodes.Remove(oldChild);67 foldedNodes.Remove(oldChild);68 if (removeSubtree) {69 foreach (var subtree in oldChild.IterateNodesPrefix()) {70 changedNodes.Remove(subtree);71 foldedNodes.Remove(subtree);72 }73 } else {74 for (int i = oldChild.SubtreeCount - 1; i >= 0; --i) {75 var subtree = oldChild.GetSubtree(i);76 oldChild.RemoveSubtree(i);77 node.AddSubtree(subtree);78 }79 }80 } else { // replacement operation81 var replacementIndex = node.IndexOfSubtree(oldChild);82 node.RemoveSubtree(replacementIndex);83 node.InsertSubtree(replacementIndex, newChild);84 newChild.Parent = node;85 if (changedNodes.ContainsKey(oldChild)) {86 changedNodes.Add(newChild, changedNodes[oldChild]); // so that on double click the original node is restored87 changedNodes.Remove(oldChild);88 } else {89 changedNodes.Add(newChild, oldChild);90 }91 }92 if (IsValid(tree)) {93 treeState = TreeState.Valid;94 UpdateModel(Content.Model.SymbolicExpressionTree);95 } else {96 treeState = TreeState.Invalid;97 }98 }99 100 private bool IsValid(ISymbolicExpressionTree tree) {101 treeChart.Tree = tree;102 treeChart.Repaint();103 bool valid = !tree.IterateNodesPostfix().Any(node => node.SubtreeCount < node.Symbol.MinimumArity || node.SubtreeCount > node.Symbol.MaximumArity);104 if (valid) {105 btnOptimizeConstants.Enabled = true;106 btnSimplify.Enabled = true;107 treeStatusValue.Text = "Valid";108 treeStatusValue.ForeColor = Color.Green;109 } else {110 btnOptimizeConstants.Enabled = false;111 btnSimplify.Enabled = false;112 treeStatusValue.Text = "Invalid";113 treeStatusValue.ForeColor = Color.Red;114 }115 this.Refresh();116 return valid;117 44 } 118 45 … … 170 97 171 98 private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) { 172 if (treeState == TreeState.Invalid) return;173 99 var visualNode = (VisualSymbolicExpressionTreeNode)sender; 174 100 var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.SymbolicExpressionTreeNode; … … 177 103 var parent = symbExprTreeNode.Parent; 178 104 int indexOfSubtree = parent.IndexOfSubtree(symbExprTreeNode); 179 if (changedNodes.ContainsKey(symbExprTreeNode)) { 180 // undo node change 181 parent.RemoveSubtree(indexOfSubtree); 182 var originalNode = changedNodes[symbExprTreeNode]; 183 parent.InsertSubtree(indexOfSubtree, originalNode); 184 changedNodes.Remove(symbExprTreeNode); 185 } else if (foldedNodes.ContainsKey(symbExprTreeNode)) { 105 if (foldedNodes.ContainsKey(symbExprTreeNode)) { 186 106 // undo node folding 187 107 SwitchNodeWithReplacementNode(parent, indexOfSubtree); … … 231 151 } 232 152 if (visualTree != null) 233 if (changedNodes.ContainsKey(treeNode)) { 234 visualTree.LineColor = Color.DodgerBlue; 235 } else if (treeNode is ConstantTreeNode && foldedNodes.ContainsKey(treeNode)) { 153 if (treeNode is ConstantTreeNode && foldedNodes.ContainsKey(treeNode)) { 236 154 visualTree.LineColor = Color.DarkOrange; 237 155 }
Note: See TracChangeset
for help on using the changeset viewer.