Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/20/12 22:11:38 (13 years ago)
Author:
bburlacu
Message:

#1763: Added a new context option for leaf nodes (ConstantTreeNode or VariableTreeNode) to change the value or variable weight respectively.

  • Added new dialog: SymbolicExpressionTreeNodeChangeValueDialog
  • Added new SymbolicExpressionTreeNodeChanged event and handler
  • Changed the double click behavior to account for node value/weight changes

Overall the behavior has been slightly changed: if a node was folded(replaced by a ConstantTreeNode), then it is possible to change its value via the context menu. For all changed nodes the original value is kept in a dictionary, so the first double click will restore it. After that, a second double click will unfold the node.

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
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views-3.4.csproj

    r7372 r7388  
    4040    <DebugSymbols>true</DebugSymbols>
    4141    <DebugType>full</DebugType>
    42     <Optimize>false</Optimize>
     42    <Optimize>true</Optimize>
    4343    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    4444    <DefineConstants>DEBUG;TRACE</DefineConstants>
     
    5050    <DebugType>pdbonly</DebugType>
    5151    <Optimize>true</Optimize>
    52     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     52    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    5353    <DefineConstants>TRACE</DefineConstants>
    5454    <ErrorReport>prompt</ErrorReport>
     
    233233      <Install>true</Install>
    234234    </BootstrapperPackage>
    235   </ItemGroup>
    236   <ItemGroup>
    237     <EmbeddedResource Include="SymbolicExpressionTreeChart.resx">
    238       <DependentUpon>SymbolicExpressionTreeChart.cs</DependentUpon>
    239     </EmbeddedResource>
    240235  </ItemGroup>
    241236  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views/3.4/SymbolicExpressionTreeChart.cs

    r7372 r7388  
    2525using System.Drawing.Imaging;
    2626using System.Windows.Forms;
    27 using System.Windows.Forms.VisualStyles;
    2827
    2928namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views {
     
    3332    private Dictionary<ISymbolicExpressionTreeNode, VisualSymbolicExpressionTreeNode> visualTreeNodes;
    3433    private Dictionary<Tuple<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>, VisualSymbolicExpressionTreeNodeConnection> visualLines;
    35     private VisualSymbolicExpressionTreeNode selectedNode;
     34    private VisualSymbolicExpressionTreeNode selectedNode = null;
    3635
    3736    public SymbolicExpressionTreeChart() {
     
    159158
    160159    #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
    161168    public event MouseEventHandler SymbolicExpressionTreeNodeClicked;
    162169    private void OnSymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
     
    362369
    363370    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);
    380373    }
    381374  }
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/HeuristicLab.Problems.DataAnalysis.Symbolic.Views-3.4.csproj

    r7372 r7388  
    5050    <DebugType>pdbonly</DebugType>
    5151    <Optimize>true</Optimize>
    52     <OutputPath>$(SolutionDir)\bin\</OutputPath>
     52    <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
    5353    <DefineConstants>TRACE</DefineConstants>
    5454    <ErrorReport>prompt</ErrorReport>
     
    135135  <ItemGroup>
    136136    <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>
    137143    <Compile Include="TextualSymbolicDataAnalysisModelView.cs">
    138144      <SubType>UserControl</SubType>
     
    211217    </BootstrapperPackage>
    212218  </ItemGroup>
    213   <ItemGroup>
    214     <EmbeddedResource Include="InteractiveSymbolicDataAnalysisSolutionSimplifierView.resx">
    215       <DependentUpon>InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs</DependentUpon>
    216     </EmbeddedResource>
    217   </ItemGroup>
    218219  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    219220  <!-- 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  
    5151      this.btnSimplify = new System.Windows.Forms.Button();
    5252      this.btnOptimizeConstants = new System.Windows.Forms.Button();
     53      this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    5354      this.grpViewHost = new System.Windows.Forms.GroupBox();
    54       this.treeChart = new HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart();
    5555      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
    5656      this.splitContainer.Panel1.SuspendLayout();
     
    6464      // viewHost
    6565      //
    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)
    6868            | System.Windows.Forms.AnchorStyles.Right)));
    6969      this.viewHost.Caption = "View";
     
    109109      // flowLayoutPanel
    110110      //
    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)
    112112            | System.Windows.Forms.AnchorStyles.Right)));
    113113      this.flowLayoutPanel.Controls.Add(this.btnSimplify);
     
    141141      this.btnOptimizeConstants.Click += new System.EventHandler(this.btnOptimizeConstants_Click);
    142142      //
    143       // grpViewHost
    144       //
    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       //
    154143      // treeChart
    155144      //
    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)
    158147            | System.Windows.Forms.AnchorStyles.Right)));
    159148      this.treeChart.BackgroundColor = System.Drawing.Color.White;
     
    167156      this.treeChart.TextFont = new System.Drawing.Font("Times New Roman", 8F);
    168157      this.treeChart.Tree = null;
     158      this.treeChart.SymbolicExpressionTreeNodeChanged += new System.EventHandler(this.treeChart_SymbolicExpressionTreeNodeChanged);
    169159      this.treeChart.SymbolicExpressionTreeNodeClicked += new System.Windows.Forms.MouseEventHandler(this.treeChart_SymbolicExpressionTreeNodeClicked);
    170160      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";
    171172      //
    172173      // InteractiveSymbolicDataAnalysisSolutionSimplifierView
  • branches/HeuristicLab.TreeSimplifierView/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r7372 r7388  
    3434    private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> replacementNodes;
    3535    private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
     36    private Dictionary<ISymbolicExpressionTreeNode, double> originalValues;
    3637    private bool updateInProgress = false;
    3738
     
    4041      this.replacementNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    4142      this.nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
     43      this.originalValues = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4244      this.Caption = "Interactive Solution Simplifier";
    4345    }
     
    9294
    9395        if (!updateInProgress) {
    94           // automatically fold all branches with impact = 1
     96          // automatically fold all branches with impact = 0
    9597          List<ISymbolicExpressionTreeNode> nodeList = Content.Model.SymbolicExpressionTree.Root.GetSubtree(0).IterateNodesPrefix().ToList();
    9698          foreach (var parent in nodeList) {
     
    129131      VisualSymbolicExpressionTreeNode visualTreeNode = (VisualSymbolicExpressionTreeNode)sender;
    130132      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
    131150      foreach (SymbolicExpressionTreeNode treeNode in tree.IterateNodesPostfix()) {
    132151        for (int i = 0; i < treeNode.SubtreeCount; i++) {
     
    153172    private void treeChart_SymbolicExpressionTreeNodeClicked(object sender, MouseEventArgs e) {
    154173      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;
    158175        var menu = treeChart.ContextMenuStrip;
     176
     177        bool flag = (node.Symbol is Constant || node.Symbol is Variable);
     178
    159179        ToolStripItem[] items = menu.Items.Find("changeValueToolStripMenuItem", false);
    160180        ToolStripItem changeValueMenuItem = null;
    161         if (items.Length > 0) {
     181        if (items.Any())
    162182          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;
    176220      }
    177221    }
     
    223267    private void PaintCollapsedNodes() {
    224268      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))
    226272          this.treeChart.GetVisualSymbolicExpressionTreeNode(treeNode).LineColor = Color.DarkOrange;
    227273        else {
Note: See TracChangeset for help on using the changeset viewer.