Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
05/06/13 14:07:17 (12 years ago)
Author:
bburlacu
Message:

#1763: We found a bug in the InteractiveSymbolicDataAnalysisSolutionSimplifierView: when the user removes one of the linear scaling nodes from the tree (using the new tree editing functionality) then clicks optimize, an exception is raised by the constants optimizer.

We removed the tree editing functionality from the trunk, to be added again and fixed after the release.

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  
    5454      this.btnSimplify = new System.Windows.Forms.Button();
    5555      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();
    5757      this.grpViewHost = new System.Windows.Forms.GroupBox();
    5858      ((System.ComponentModel.ISupportInitialize)(this.splitContainer)).BeginInit();
     
    176176      this.treeChart.LineColor = System.Drawing.Color.Black;
    177177      this.treeChart.Location = new System.Drawing.Point(6, 32);
    178       this.treeChart.ModifyTree = null;
    179178      this.treeChart.Name = "treeChart";
    180179      this.treeChart.Size = new System.Drawing.Size(201, 332);
     
    220219    #endregion
    221220
    222     private InteractiveSymbolicExpressionTreeChart treeChart;
     221    private HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Views.SymbolicExpressionTreeChart treeChart;
    223222    private System.Windows.Forms.SplitContainer splitContainer;
    224223    private HeuristicLab.MainForm.WindowsForms.ViewHost viewHost;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/InteractiveSymbolicDataAnalysisSolutionSimplifierView.cs

    r9055 r9445  
    3333  public abstract partial class InteractiveSymbolicDataAnalysisSolutionSimplifierView : AsynchronousContentView {
    3434    private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> foldedNodes;
    35     private Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode> changedNodes;
    3635    private Dictionary<ISymbolicExpressionTreeNode, double> nodeImpacts;
    3736    private enum TreeState { Valid, Invalid }
     
    4140      InitializeComponent();
    4241      foldedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    43       changedNodes = new Dictionary<ISymbolicExpressionTreeNode, ISymbolicExpressionTreeNode>();
    4442      nodeImpacts = new Dictionary<ISymbolicExpressionTreeNode, double>();
    4543      this.Caption = "Interactive Solution Simplifier";
    46 
    47       // initialize the tree modifier that will be used to perform edit operations over the tree
    48       treeChart.ModifyTree = Modify;
    49     }
    50 
    51     /// <summary>
    52     /// Remove, Replace or Insert subtrees
    53     /// </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 operation
    62         node.AddSubtree(newChild);
    63         newChild.Parent = node;
    64       } else if (newChild == null) { // removal operation
    65         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 operation
    81         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 restored
    87           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;
    11744    }
    11845
     
    17097
    17198    private void treeChart_SymbolicExpressionTreeNodeDoubleClicked(object sender, MouseEventArgs e) {
    172       if (treeState == TreeState.Invalid) return;
    17399      var visualNode = (VisualSymbolicExpressionTreeNode)sender;
    174100      var symbExprTreeNode = (SymbolicExpressionTreeNode)visualNode.SymbolicExpressionTreeNode;
     
    177103      var parent = symbExprTreeNode.Parent;
    178104      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)) {
    186106        // undo node folding
    187107        SwitchNodeWithReplacementNode(parent, indexOfSubtree);
     
    231151        }
    232152        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)) {
    236154            visualTree.LineColor = Color.DarkOrange;
    237155          }
Note: See TracChangeset for help on using the changeset viewer.