Changeset 7388 for branches/HeuristicLab.TreeSimplifierView
- Timestamp:
- 01/20/12 22:11:38 (13 years ago)
- Location:
- branches/HeuristicLab.TreeSimplifierView
- Files:
-
- 2 added
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.TreeSimplifierView
-
Property
svn:ignore
set to
_ReSharper.HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4
bin
-
Property
svn:ignore
set to
-
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj
r7372 r7388 40 40 <DebugSymbols>true</DebugSymbols> 41 41 <DebugType>full</DebugType> 42 <Optimize> false</Optimize>42 <Optimize>true</Optimize> 43 43 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 44 44 <DefineConstants>DEBUG;TRACE</DefineConstants> … … 50 50 <DebugType>pdbonly</DebugType> 51 51 <Optimize>true</Optimize> 52 <OutputPath> $(SolutionDir)\bin\</OutputPath>52 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 53 53 <DefineConstants>TRACE</DefineConstants> 54 54 <ErrorReport>prompt</ErrorReport> … … 233 233 <Install>true</Install> 234 234 </BootstrapperPackage> 235 </ItemGroup>236 <ItemGroup>237 <EmbeddedResource Include="SymbolicExpressionTreeChart.resx">238 <DependentUpon>SymbolicExpressionTreeChart.cs</DependentUpon>239 </EmbeddedResource>240 235 </ItemGroup> 241 236 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs
r7372 r7388 25 25 using System.Drawing.Imaging; 26 26 using System.Windows.Forms; 27 using System.Windows.Forms.VisualStyles;28 27 29 28 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views { … … 33 32 private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes; 34 33 private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines; 35 private VisualSymbolicExpressionTreeNode selectedNode ;34 private VisualSymbolicExpressionTreeNode selectedNode = null; 36 35 37 36 public SymbolicExpressionTreeChart() { … … 159 158 160 159 #region events 160 public event EventHandler SymbolicExpressionTreeNodeChanged; 161 private void OnSymbolicExpressionTreeNodeChanged(object sender, EventArgs e) { 162 var changed = SymbolicExpressionTreeNodeChanged; 163 if (changed != null) { 164 changed(sender, e); 165 } 166 } 167 161 168 public event MouseEventHandler SymbolicExpressionTreeNodeClicked; 162 169 private void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { … … 362 369 363 370 private void changeValueToolStripMenuItem_Click(object sender, EventArgs e) { 364 var treeNode = selectedNode.SymbolicExpressionTreeNode; 365 // textbox as a popup/tooltip 366 var dialog = new Core.Views.TextDialog("Change value", String.Empty, false); 367 dialog.AutoSize = true; 368 dialog.ShowDialog(this); 369 double newValue; 370 if (double.TryParse(dialog.Text, out newValue)) { 371 if (treeNode.Symbol is Problems.DataAnalysis.Symbolic.Constant) { 372 var node = treeNode as Problems.DataAnalysis.Symbolic.ConstantTreeNode; 373 node.Value = newValue; 374 } else if (treeNode.Symbol is Problems.DataAnalysis.Symbolic.Variable) { 375 var node = treeNode as Problems.DataAnalysis.Symbolic.VariableTreeNode; 376 node.Weight = newValue; 377 } 378 } 379 this.Repaint(); 371 if (selectedNode != null) // this should never be null anyway 372 OnSymbolicExpressionTreeNodeChanged(selectedNode, e); 380 373 } 381 374 } -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj
r7372 r7388 50 50 <DebugType>pdbonly</DebugType> 51 51 <Optimize>true</Optimize> 52 <OutputPath> $(SolutionDir)\bin\</OutputPath>52 <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath> 53 53 <DefineConstants>TRACE</DefineConstants> 54 54 <ErrorReport>prompt</ErrorReport> … … 135 135 <ItemGroup> 136 136 <Compile Include="Plugin.cs" /> 137 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.cs"> 138 <SubType>Form</SubType> 139 </Compile> 140 <Compile Include="SymbolicExpressionTreeNodeChangeValueDialog.designer.cs"> 141 <DependentUpon>SymbolicExpressionTreeNodeChangeValueDialog.cs</DependentUpon> 142 </Compile> 137 143 <Compile Include="TextualSymbolicDataAnalysisModelView.cs"> 138 144 <SubType>UserControl</SubType> … … 211 217 </BootstrapperPackage> 212 218 </ItemGroup> 213 <ItemGroup>214 <EmbeddedResource Include="InteractiveSymbolicDataAnalysisSolutionSimplifierView.resx">215 <DependentUpon>InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs</DependentUpon>216 </EmbeddedResource>217 </ItemGroup>218 219 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 219 220 <!-- 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
r7372 r7388 51 51 this.btnSimplify = new System.Windows.Forms.Button(); 52 52 this.btnOptimizeConstants = new System.Windows.Forms.Button(); 53 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart(); 53 54 this.grpViewHost = new System.Windows.Forms.GroupBox(); 54 this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();55 55 ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit(); 56 56 this.splitContainer.Panel1.SuspendLayout(); … … 64 64 // viewHost 65 65 // 66 this.viewHost.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 67 | System.Windows.Forms.AnchorStyles.Left) 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 68 | System.Windows.Forms.AnchorStyles.Right))); 69 69 this.viewHost.Caption = "View"; … … 109 109 // flowLayoutPanel 110 110 // 111 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 111 this.flowLayoutPanel.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left) 112 112 | System.Windows.Forms.AnchorStyles.Right))); 113 113 this.flowLayoutPanel.Controls.Add(this.btnSimplify); … … 141 141 this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click); 142 142 // 143 // grpViewHost144 //145 this.grpViewHost.Controls.Add(this.viewHost);146 this.grpViewHost.Dock = System.Windows.Forms.DockStyle.Fill;147 this.grpViewHost.Location = new System.Drawing.Point(0, 0);148 this.grpViewHost.Name = "grpViewHost";149 this.grpViewHost.Size = new System.Drawing.Size(347, 348);150 this.grpViewHost.TabIndex = 1;151 this.grpViewHost.TabStop = false;152 this.grpViewHost.Text = "Details";153 //154 143 // treeChart 155 144 // 156 this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 157 | System.Windows.Forms.AnchorStyles.Left) 145 this.treeChart.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 146 | System.Windows.Forms.AnchorStyles.Left) 158 147 | System.Windows.Forms.AnchorStyles.Right))); 159 148 this.treeChart.BackgroundColor = System.Drawing.Color.White; … … 167 156 this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F); 168 157 this.treeChart.Tree = null; 158 this.treeChart.SymbolicExpressionTreeNodeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeChanged); 169 159 this.treeChart.SymbolicExpressionTreeNodeClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeClicked); 170 160 this.treeChart.SymbolicExpressionTreeNodeDoubleClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeDoubleClicked); 161 // 162 // grpViewHost 163 // 164 this.grpViewHost.Controls.Add(this.viewHost); 165 this.grpViewHost.Dock = System.Windows.Forms.DockStyle.Fill; 166 this.grpViewHost.Location = new System.Drawing.Point(0, 0); 167 this.grpViewHost.Name = "grpViewHost"; 168 this.grpViewHost.Size = new System.Drawing.Size(347, 348); 169 this.grpViewHost.TabIndex = 1; 170 this.grpViewHost.TabStop = false; 171 this.grpViewHost.Text = "Details"; 171 172 // 172 173 // InteractiveSymbolicDataAnalysisSolutionSimplifierView -
branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs
r7372 r7388 34 34 private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> replacementNodes; 35 35 private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts; 36 private Dictionary<ISymbolicExpressionTreeNode, double> originalValues; 36 37 private bool updateInProgress = false; 37 38 … … 40 41 this.replacementNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>(); 41 42 this.nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>(); 43 this.originalValues = new Dictionary<ISymbolicExpressionTreeNode, double>(); 42 44 this.Caption = "Interactive Solution Simplifier"; 43 45 } … … 92 94 93 95 if (!updateInProgress) { 94 // automatically fold all branches with impact = 196 // automatically fold all branches with impact = 0 95 97 List<ISymbolicExpressionTreeNode> nodeList = Content.Model.SymbolicExpressionTree.Root.GetSubtree(0).IterateNodesPrefix().ToList(); 96 98 foreach (var parent in nodeList) { … … 129 131 VisualSymbolicExpressionTreeNode visualTreeNode = (VisualSymbolicExpressionTreeNode)sender; 130 132 var tree = Content.Model.SymbolicExpressionTree; 133 // check if the node value/weight has been altered 134 // if so, the first double click will return the node to its original value/weight 135 // the next double click will replace the ConstantNode with the original SymbolicExpressionTreeNode 136 if (originalValues.ContainsKey(visualTreeNode.SymbolicExpressionTreeNode)) { 137 double value = originalValues[visualTreeNode.SymbolicExpressionTreeNode]; 138 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 139 if (subTree.Symbol is Constant) 140 (subTree as ConstantTreeNode).Value = value; 141 else if (subTree.Symbol is Variable) 142 (subTree as VariableTreeNode).Weight = value; 143 originalValues.Remove(subTree); 144 updateInProgress = true; 145 UpdateModel(tree); 146 updateInProgress = false; 147 return; 148 } 149 131 150 foreach (SymbolicExpressionTreeNode treeNode in tree.IterateNodesPostfix()) { 132 151 for (int i = 0; i < treeNode.SubtreeCount; i++) { … … 153 172 private void treeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) { 154 173 if (e.Button == MouseButtons.Right) { 155 var visualTreeNode = sender as VisualSymbolicExpressionTreeNode; 156 var node = visualTreeNode.SymbolicExpressionTreeNode; 157 // on a right click we want to show the option of changing the node value (if the node is a constant) or the weight (if the node is a variable) 174 var node = (sender as VisualSymbolicExpressionTreeNode).SymbolicExpressionTreeNode; 158 175 var menu = treeChart.ContextMenuStrip; 176 177 bool flag = (node.Symbol is Constant || node.Symbol is Variable); 178 159 179 ToolStripItem[] items = menu.Items.Find("changeValueToolStripMenuItem", false); 160 180 ToolStripItem changeValueMenuItem = null; 161 if (items. Length > 0) {181 if (items.Any()) 162 182 changeValueMenuItem = items[0]; 163 } 164 165 if (node.Symbol is Constant || node.Symbol is Variable) { 166 if (changeValueMenuItem != null) { 167 changeValueMenuItem.Enabled = true; 168 changeValueMenuItem.Visible = true; 169 } 170 } else { 171 if (changeValueMenuItem != null) { 172 changeValueMenuItem.Enabled = false; 173 changeValueMenuItem.Visible = false; 174 } 175 } 183 if (changeValueMenuItem != null) { 184 changeValueMenuItem.Enabled = flag; 185 changeValueMenuItem.Visible = flag; 186 } 187 } 188 } 189 190 private void treeChart_SymbolicExpressionTreeNodeChanged(object sender, EventArgs e) { 191 var tree = Content.Model.SymbolicExpressionTree; 192 var visualTreeNode = sender as VisualSymbolicExpressionTreeNode; 193 var subTree = visualTreeNode.SymbolicExpressionTreeNode; 194 string title = String.Empty; 195 double value = 0.0; 196 197 if (subTree.Symbol is Constant) { 198 title = "Change Constant Value"; 199 value = (subTree as ConstantTreeNode).Value; 200 } else if (subTree.Symbol is Variable) { 201 title = "Change Weight Value"; 202 value = (subTree as VariableTreeNode).Weight; 203 } 204 205 if (!originalValues.ContainsKey(subTree)) 206 originalValues.Add(subTree, value); 207 var dialog = new ValueChangeDialog(title, Math.Round(value,4).ToString()); 208 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; 176 220 } 177 221 } … … 223 267 private void PaintCollapsedNodes() { 224 268 foreach (ISymbolicExpressionTreeNode treeNode in Content.Model.SymbolicExpressionTree.IterateNodesPostfix()) { 225 if (treeNode is ConstantTreeNode && replacementNodes.ContainsKey(treeNode)) 269 if (originalValues.ContainsKey(treeNode)) 270 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.Blue; 271 else if (treeNode is ConstantTreeNode && replacementNodes.ContainsKey(treeNode)) 226 272 this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DarkOrange; 227 273 else {
Note: See TracChangeset
for help on using the changeset viewer.