Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/30/12 23:15:47 (12 years ago)
Author:
bburlacu
Message:

#1763: Refactored the tree simplifier. Improved tree/node edit operations.

Location:
trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs
Files:
2 copied
2 moved

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeConstantNodeEditDialog.Designer.cs

    r8950 r8980  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    23   partial class ValueChangeDialog {
     23  partial class ConstantNodeEditDialog {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    5151      this.newValueLabel = new System.Windows.Forms.Label();
    5252      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
    53       this.variableNameLabel = new System.Windows.Forms.Label();
    54       this.variableNamesCombo = new System.Windows.Forms.ComboBox();
    5553      this.okButton = new System.Windows.Forms.Button();
    5654      this.cancelButton = new System.Windows.Forms.Button();
     
    6159      //
    6260      this.originalValueLabel.AutoSize = true;
    63       this.originalValueLabel.Location = new System.Drawing.Point(12, 45);
     61      this.originalValueLabel.Location = new System.Drawing.Point(12, 9);
    6462      this.originalValueLabel.Name = "originalValueLabel";
    6563      this.originalValueLabel.Size = new System.Drawing.Size(72, 13);
     
    6967      // oldValueTextBox
    7068      //
    71       this.oldValueTextBox.Location = new System.Drawing.Point(123, 42);
     69      this.oldValueTextBox.Location = new System.Drawing.Point(123, 6);
    7270      this.oldValueTextBox.Name = "oldValueTextBox";
    7371      this.oldValueTextBox.ReadOnly = true;
     
    7775      // newValueTextBox
    7876      //
    79       this.newValueTextBox.Location = new System.Drawing.Point(123, 82);
     77      this.newValueTextBox.Location = new System.Drawing.Point(123, 42);
    8078      this.newValueTextBox.Name = "newValueTextBox";
    8179      this.newValueTextBox.Size = new System.Drawing.Size(131, 20);
     
    8886      //
    8987      this.newValueLabel.AutoSize = true;
    90       this.newValueLabel.Location = new System.Drawing.Point(12, 85);
     88      this.newValueLabel.Location = new System.Drawing.Point(12, 45);
    9189      this.newValueLabel.Name = "newValueLabel";
    9290      this.newValueLabel.Size = new System.Drawing.Size(59, 13);
     
    10098      this.errorProvider.RightToLeft = true;
    10199      //
    102       // variableNameLabel
    103       //
    104       this.variableNameLabel.AutoSize = true;
    105       this.variableNameLabel.Location = new System.Drawing.Point(12, 7);
    106       this.variableNameLabel.Name = "variableNameLabel";
    107       this.variableNameLabel.Size = new System.Drawing.Size(76, 13);
    108       this.variableNameLabel.TabIndex = 6;
    109       this.variableNameLabel.Text = "Variable Name";
    110       this.variableNameLabel.Visible = false;
    111       //
    112       // variableNamesCombo
    113       //
    114       this.variableNamesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    115       this.variableNamesCombo.FormattingEnabled = true;
    116       this.variableNamesCombo.Location = new System.Drawing.Point(123, 4);
    117       this.variableNamesCombo.Name = "variableNamesCombo";
    118       this.variableNamesCombo.Size = new System.Drawing.Size(131, 21);
    119       this.variableNamesCombo.TabIndex = 7;
    120       this.variableNamesCombo.Visible = false;
    121       this.variableNamesCombo.KeyDown += new System.Windows.Forms.KeyEventHandler(this.childControl_KeyDown);
    122       this.variableNamesCombo.Validating += new System.ComponentModel.CancelEventHandler(this.variableNamesCombo_Validating);
    123       this.variableNamesCombo.Validated += new System.EventHandler(this.variableNamesCombo_Validated);
    124       //
    125100      // okButton
    126101      //
    127       this.okButton.Location = new System.Drawing.Point(15, 119);
     102      this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
     103      this.okButton.Location = new System.Drawing.Point(15, 79);
    128104      this.okButton.Name = "okButton";
    129105      this.okButton.Size = new System.Drawing.Size(75, 23);
     
    137113      this.cancelButton.CausesValidation = false;
    138114      this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
    139       this.cancelButton.Location = new System.Drawing.Point(179, 119);
     115      this.cancelButton.Location = new System.Drawing.Point(179, 79);
    140116      this.cancelButton.Name = "cancelButton";
    141117      this.cancelButton.Size = new System.Drawing.Size(75, 23);
     
    145121      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
    146122      //
    147       // ValueChangeDialog
     123      // ConstantNodeEditDialog
    148124      //
    149125      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     
    151127      this.AutoSize = true;
    152128      this.CancelButton = this.cancelButton;
    153       this.ClientSize = new System.Drawing.Size(269, 154);
     129      this.ClientSize = new System.Drawing.Size(269, 116);
    154130      this.ControlBox = false;
    155131      this.Controls.Add(this.cancelButton);
    156132      this.Controls.Add(this.okButton);
    157       this.Controls.Add(this.variableNamesCombo);
    158       this.Controls.Add(this.variableNameLabel);
    159133      this.Controls.Add(this.newValueLabel);
    160134      this.Controls.Add(this.newValueTextBox);
     
    164138      this.MaximizeBox = false;
    165139      this.MinimizeBox = false;
    166       this.Name = "ValueChangeDialog";
     140      this.Name = "ConstantNodeEditDialog";
    167141      this.ShowIcon = false;
    168142      this.ShowInTaskbar = false;
    169143      this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
    170       this.Text = "Change Value or Weight";
    171       this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ValueChangeDialog_KeyDown);
     144      this.Text = "Edit constant value";
     145      this.KeyDown += new System.Windows.Forms.KeyEventHandler(this.ConstantNodeEditDialog_KeyDown);
    172146      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).EndInit();
    173147      this.ResumeLayout(false);
     
    182156    private System.Windows.Forms.Label newValueLabel;
    183157    private System.Windows.Forms.ErrorProvider errorProvider;
    184     private System.Windows.Forms.Label variableNameLabel;
    185158    private System.Windows.Forms.Button cancelButton;
    186159    private System.Windows.Forms.Button okButton;
    187160    public System.Windows.Forms.TextBox newValueTextBox;
    188     public System.Windows.Forms.ComboBox variableNamesCombo;
    189161  }
    190162}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeConstantNodeEditDialog.cs

    r8950 r8980  
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    30   public partial class ValueChangeDialog : Form {
    31     private ISymbolicExpressionTreeNode content;
    32     public ISymbolicExpressionTreeNode Content {
    33       get { return content; }
     30  public partial class ConstantNodeEditDialog : Form {
     31    private ConstantTreeNode constantTreeNode;
     32    public ConstantTreeNode NewNode {
     33      get { return constantTreeNode; }
    3434      set {
    3535        if (InvokeRequired)
    36           Invoke(new Action<SymbolicExpressionTreeNode>(x => content = x), value);
     36          Invoke(new Action<SymbolicExpressionTreeNode>(x => constantTreeNode = (ConstantTreeNode)x), value);
    3737        else
    38           content = value;
     38          constantTreeNode = value;
    3939      }
    4040    }
    4141
    42     public ValueChangeDialog() {
     42    public ConstantNodeEditDialog(ISymbolicExpressionTreeNode node) {
    4343      InitializeComponent();
    4444      oldValueTextBox.TabStop = false; // cannot receive focus using tab key
     45      NewNode = (ConstantTreeNode)node;
     46      InitializeFields();
    4547    }
    4648
    47     public void SetContent(ISymbolicExpressionTreeNode content) {
    48       Content = content;
    49       if (Content is VariableTreeNode) {
    50         this.Text = "Change variable name or weight";
    51         var variable = Content as VariableTreeNode;
    52         newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variable.Weight, 4).ToString();
    53         // add a dropbox containing all the available variable names
    54         variableNameLabel.Visible = true;
    55         variableNamesCombo.Visible = true;
    56         foreach (var name in variable.Symbol.VariableNames) variableNamesCombo.Items.Add(name);
    57         variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variable.VariableName);
    58       } else if (Content is ConstantTreeNode) {
    59         this.Text = "Change constant value";
    60         var constant = Content as ConstantTreeNode;
    61         newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constant.Value, 4).ToString();
     49    private void InitializeFields() {
     50      if (NewNode == null)
     51        throw new ArgumentException("Node is not a constant.");
     52      else {
     53        this.Text = "Edit constant";
     54        newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constantTreeNode.Value, 4).ToString();
    6255      }
    6356    }
     
    9285    #endregion
    9386
    94     #region combo box validation and events
    95     private void variableNamesCombo_Validating(object sender, CancelEventArgs e) {
    96       if (!(Content is VariableTreeNode)) return;
    97       if (variableNamesCombo.Items.Contains(variableNamesCombo.SelectedItem)) return;
    98       e.Cancel = true;
    99       errorProvider.SetError(variableNamesCombo, "Invalid variable name");
    100       variableNamesCombo.SelectAll();
     87    // proxy handler passing key strokes to the parent control
     88    private void childControl_KeyDown(object sender, KeyEventArgs e) {
     89      ConstantNodeEditDialog_KeyDown(sender, e);
    10190    }
    10291
    103     private void variableNamesCombo_Validated(object sender, EventArgs e) {
    104       errorProvider.SetError(variableNamesCombo, String.Empty);
    105     }
    106     #endregion
    107     // proxy handler passing key strokes to the parent control
    108     private void childControl_KeyDown(object sender, KeyEventArgs e) {
    109       ValueChangeDialog_KeyDown(sender, e);
    110     }
    111 
    112     private void ValueChangeDialog_KeyDown(object sender, KeyEventArgs e) {
     92    private void ConstantNodeEditDialog_KeyDown(object sender, KeyEventArgs e) {
    11393      if ((e.KeyCode == Keys.Enter) || (e.KeyCode == Keys.Return)) {
    11494        if (!ValidateChildren()) return;
     
    120100    public event EventHandler DialogValidated;
    121101    private void OnDialogValidated(object sender, EventArgs e) {
     102      if (constantTreeNode == null) return;
     103      var value = double.Parse(newValueTextBox.Text);
     104      // we impose an extra validation condition: that the new value is different from the original value
     105      if (constantTreeNode.Value.Equals(value)) return;
     106
     107      constantTreeNode.Value = value;
     108      DialogResult = DialogResult.OK;
    122109      var dialogValidated = DialogValidated;
    123110      if (dialogValidated != null)
     
    135122      }
    136123    }
    137 
    138124  }
    139125}
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.Designer.cs

    r8950 r8980  
    2121
    2222namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    23   partial class ValueChangeDialog {
     23  partial class VariableNodeEditDialog {
    2424    /// <summary>
    2525    /// Required designer variable.
     
    6161      //
    6262      this.originalValueLabel.AutoSize = true;
    63       this.originalValueLabel.Location = new System.Drawing.Point(12, 45);
     63      this.originalValueLabel.Location = new System.Drawing.Point(12, 48);
    6464      this.originalValueLabel.Name = "originalValueLabel";
    6565      this.originalValueLabel.Size = new System.Drawing.Size(72, 13);
     
    6969      // oldValueTextBox
    7070      //
    71       this.oldValueTextBox.Location = new System.Drawing.Point(123, 42);
     71      this.oldValueTextBox.Location = new System.Drawing.Point(123, 45);
    7272      this.oldValueTextBox.Name = "oldValueTextBox";
    7373      this.oldValueTextBox.ReadOnly = true;
     
    103103      //
    104104      this.variableNameLabel.AutoSize = true;
    105       this.variableNameLabel.Location = new System.Drawing.Point(12, 7);
     105      this.variableNameLabel.Location = new System.Drawing.Point(12, 12);
    106106      this.variableNameLabel.Name = "variableNameLabel";
    107107      this.variableNameLabel.Size = new System.Drawing.Size(76, 13);
     
    114114      this.variableNamesCombo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
    115115      this.variableNamesCombo.FormattingEnabled = true;
    116       this.variableNamesCombo.Location = new System.Drawing.Point(123, 4);
     116      this.variableNamesCombo.Location = new System.Drawing.Point(123, 9);
    117117      this.variableNamesCombo.Name = "variableNamesCombo";
    118118      this.variableNamesCombo.Size = new System.Drawing.Size(131, 21);
     
    125125      // okButton
    126126      //
     127      this.okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
    127128      this.okButton.Location = new System.Drawing.Point(15, 119);
    128129      this.okButton.Name = "okButton";
     
    145146      this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
    146147      //
    147       // ValueChangeDialog
     148      // VariableNodeEditDialog
    148149      //
    149150      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     
    164165      this.MaximizeBox = false;
    165166      this.MinimizeBox = false;
    166       this.Name = "ValueChangeDialog";
     167      this.Name = "VariableNodeEditDialog";
    167168      this.ShowIcon = false;
    168169      this.ShowInTaskbar = false;
  • trunk/sources/HeuristicLab.Problems.DataAnalysis.Symbolic.Views/3.4/TreeEditDialogs/SymbolicExpressionTreeVariableNodeEditDialog.cs

    r8950 r8980  
    2828
    2929namespace HeuristicLab.Problems.DataAnalysis.Symbolic.Views {
    30   public partial class ValueChangeDialog : Form {
    31     private ISymbolicExpressionTreeNode content;
    32     public ISymbolicExpressionTreeNode Content {
    33       get { return content; }
     30  public partial class VariableNodeEditDialog : Form {
     31    private VariableTreeNode variableTreeNode;
     32    public VariableTreeNode NewNode {
     33      get { return variableTreeNode; }
    3434      set {
    3535        if (InvokeRequired)
    36           Invoke(new Action<SymbolicExpressionTreeNode>(x => content = x), value);
     36          Invoke(new Action<SymbolicExpressionTreeNode>(x => variableTreeNode = (VariableTreeNode)x), value);
    3737        else
    38           content = value;
     38          variableTreeNode = value;
    3939      }
    4040    }
    4141
    42     public ValueChangeDialog() {
     42    public VariableNodeEditDialog(ISymbolicExpressionTreeNode node) {
    4343      InitializeComponent();
    4444      oldValueTextBox.TabStop = false; // cannot receive focus using tab key
     45
     46      NewNode = (VariableTreeNode)node; // will throw an invalid cast exception if node is not of the correct type
     47      InitializeFields();
    4548    }
    4649
    47     public void SetContent(ISymbolicExpressionTreeNode content) {
    48       Content = content;
    49       if (Content is VariableTreeNode) {
    50         this.Text = "Change variable name or weight";
    51         var variable = Content as VariableTreeNode;
    52         newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variable.Weight, 4).ToString();
     50    private void InitializeFields() {
     51      if (NewNode == null)
     52        throw new ArgumentException("Node is not a constant.");
     53      else {
     54        this.Text = "Edit variable";
     55        newValueTextBox.Text = oldValueTextBox.Text = Math.Round(variableTreeNode.Weight, 4).ToString();
    5356        // add a dropbox containing all the available variable names
    5457        variableNameLabel.Visible = true;
    5558        variableNamesCombo.Visible = true;
    56         foreach (var name in variable.Symbol.VariableNames) variableNamesCombo.Items.Add(name);
    57         variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variable.VariableName);
    58       } else if (Content is ConstantTreeNode) {
    59         this.Text = "Change constant value";
    60         var constant = Content as ConstantTreeNode;
    61         newValueTextBox.Text = oldValueTextBox.Text = Math.Round(constant.Value, 4).ToString();
     59        foreach (var name in variableTreeNode.Symbol.VariableNames) variableNamesCombo.Items.Add(name);
     60        variableNamesCombo.SelectedIndex = variableNamesCombo.Items.IndexOf(variableTreeNode.VariableName);
    6261      }
    6362    }
     
    9493    #region combo box validation and events
    9594    private void variableNamesCombo_Validating(object sender, CancelEventArgs e) {
    96       if (!(Content is VariableTreeNode)) return;
    9795      if (variableNamesCombo.Items.Contains(variableNamesCombo.SelectedItem)) return;
    9896      e.Cancel = true;
     
    120118    public event EventHandler DialogValidated;
    121119    private void OnDialogValidated(object sender, EventArgs e) {
     120      double weight = double.Parse(newValueTextBox.Text);
     121      var variableName = (string)variableNamesCombo.SelectedItem;
     122      // we impose an extra validation condition: that the weight/value be different than the original ones
     123      if (variableTreeNode.Weight.Equals(weight) && variableTreeNode.VariableName.Equals(variableName)) return;
     124      variableTreeNode.Weight = weight;
     125      variableTreeNode.VariableName = variableName;
     126      DialogResult = DialogResult.OK;
    122127      var dialogValidated = DialogValidated;
    123128      if (dialogValidated != null)
     
    135140      }
    136141    }
    137 
    138142  }
    139143}
Note: See TracChangeset for help on using the changeset viewer.