Changeset 12806


Ignore:
Timestamp:
07/27/15 16:10:23 (4 years ago)
Author:
abeham
Message:

#2431: added options to add results based on targets or budgets

Location:
branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.Designer.cs

    r12804 r12806  
    4646      this.components = new System.ComponentModel.Container();
    4747      this.dataTableComboBox = new System.Windows.Forms.ComboBox();
    48       this.label1 = new System.Windows.Forms.Label();
     48      this.dataTableLabel = new System.Windows.Forms.Label();
    4949      this.viewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost();
    50       this.label2 = new System.Windows.Forms.Label();
     50      this.groupLabel = new System.Windows.Forms.Label();
    5151      this.groupComboBox = new System.Windows.Forms.ComboBox();
    5252      this.logScalingCheckBox = new System.Windows.Forms.CheckBox();
    5353      this.targetsTextBox = new System.Windows.Forms.TextBox();
    54       this.label3 = new System.Windows.Forms.Label();
     54      this.targetsLabel = new System.Windows.Forms.Label();
    5555      this.errorProvider = new System.Windows.Forms.ErrorProvider(this.components);
     56      this.fixedTargetButton = new System.Windows.Forms.Button();
     57      this.generateTargetsButton = new System.Windows.Forms.Button();
     58      this.toolTip = new System.Windows.Forms.ToolTip(this.components);
     59      this.budgetsLabel = new System.Windows.Forms.Label();
     60      this.budgetsTextBox = new System.Windows.Forms.TextBox();
     61      this.fixedCostButton = new System.Windows.Forms.Button();
    5662      ((System.ComponentModel.ISupportInitialize)(this.errorProvider)).BeginInit();
    5763      this.SuspendLayout();
     
    6975      this.dataTableComboBox.SelectedIndexChanged += new System.EventHandler(this.dataTableComboBox_SelectedIndexChanged);
    7076      //
    71       // label1
    72       //
    73       this.label1.AutoSize = true;
    74       this.label1.Location = new System.Drawing.Point(3, 33);
    75       this.label1.Name = "label1";
    76       this.label1.Size = new System.Drawing.Size(60, 13);
    77       this.label1.TabIndex = 1;
    78       this.label1.Text = "DataTable:";
     77      // dataTableLabel
     78      //
     79      this.dataTableLabel.AutoSize = true;
     80      this.dataTableLabel.Location = new System.Drawing.Point(3, 33);
     81      this.dataTableLabel.Name = "dataTableLabel";
     82      this.dataTableLabel.Size = new System.Drawing.Size(60, 13);
     83      this.dataTableLabel.TabIndex = 1;
     84      this.dataTableLabel.Text = "DataTable:";
    7985      //
    8086      // viewHost
     
    94100      this.viewHost.ViewType = null;
    95101      //
    96       // label2
    97       //
    98       this.label2.AutoSize = true;
    99       this.label2.Location = new System.Drawing.Point(3, 6);
    100       this.label2.Name = "label2";
    101       this.label2.Size = new System.Drawing.Size(39, 13);
    102       this.label2.TabIndex = 3;
    103       this.label2.Text = "Group:";
     102      // groupLabel
     103      //
     104      this.groupLabel.AutoSize = true;
     105      this.groupLabel.Location = new System.Drawing.Point(3, 6);
     106      this.groupLabel.Name = "groupLabel";
     107      this.groupLabel.Size = new System.Drawing.Size(39, 13);
     108      this.groupLabel.TabIndex = 3;
     109      this.groupLabel.Text = "Group:";
    104110      //
    105111      // groupComboBox
     
    133139      this.targetsTextBox.Location = new System.Drawing.Point(69, 57);
    134140      this.targetsTextBox.Name = "targetsTextBox";
    135       this.targetsTextBox.Size = new System.Drawing.Size(455, 20);
     141      this.targetsTextBox.Size = new System.Drawing.Size(265, 20);
    136142      this.targetsTextBox.TabIndex = 6;
     143      this.toolTip.SetToolTip(this.targetsTextBox, "The order of the targets is important, first to-hit targets\r\nshould be given firs" +
     144        "t. The sequence should be monotonous.\r\n\r\nTargets should be separated by semicolo" +
     145        "n, tab or space.");
    137146      this.targetsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.targetsTextBox_Validating);
    138147      //
    139       // label3
    140       //
    141       this.label3.AutoSize = true;
    142       this.label3.Location = new System.Drawing.Point(3, 60);
    143       this.label3.Name = "label3";
    144       this.label3.Size = new System.Drawing.Size(46, 13);
    145       this.label3.TabIndex = 1;
    146       this.label3.Text = "Targets:";
     148      // targetsLabel
     149      //
     150      this.targetsLabel.AutoSize = true;
     151      this.targetsLabel.Location = new System.Drawing.Point(3, 60);
     152      this.targetsLabel.Name = "targetsLabel";
     153      this.targetsLabel.Size = new System.Drawing.Size(46, 13);
     154      this.targetsLabel.TabIndex = 1;
     155      this.targetsLabel.Text = "Targets:";
    147156      //
    148157      // errorProvider
     
    150159      this.errorProvider.ContainerControl = this;
    151160      //
     161      // fixedTargetButton
     162      //
     163      this.fixedTargetButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     164      this.fixedTargetButton.Location = new System.Drawing.Point(435, 54);
     165      this.fixedTargetButton.Name = "fixedTargetButton";
     166      this.fixedTargetButton.Size = new System.Drawing.Size(89, 23);
     167      this.fixedTargetButton.TabIndex = 7;
     168      this.fixedTargetButton.Text = "Add as Result";
     169      this.fixedTargetButton.UseVisualStyleBackColor = true;
     170      this.fixedTargetButton.Click += new System.EventHandler(this.fixedTargetButton_Click);
     171      //
     172      // generateTargetsButton
     173      //
     174      this.generateTargetsButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
     175      this.generateTargetsButton.Location = new System.Drawing.Point(340, 54);
     176      this.generateTargetsButton.Name = "generateTargetsButton";
     177      this.generateTargetsButton.Size = new System.Drawing.Size(89, 23);
     178      this.generateTargetsButton.TabIndex = 7;
     179      this.generateTargetsButton.Text = "Generate...";
     180      this.generateTargetsButton.UseVisualStyleBackColor = true;
     181      this.generateTargetsButton.Click += new System.EventHandler(this.generateTargetsButton_Click);
     182      //
     183      // budgetsLabel
     184      //
     185      this.budgetsLabel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
     186      this.budgetsLabel.AutoSize = true;
     187      this.budgetsLabel.Location = new System.Drawing.Point(235, 353);
     188      this.budgetsLabel.Name = "budgetsLabel";
     189      this.budgetsLabel.Size = new System.Drawing.Size(49, 13);
     190      this.budgetsLabel.TabIndex = 1;
     191      this.budgetsLabel.Text = "Budgets:";
     192      //
     193      // budgetsTextBox
     194      //
     195      this.budgetsTextBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)
     196            | System.Windows.Forms.AnchorStyles.Right)));
     197      this.budgetsTextBox.Location = new System.Drawing.Point(290, 350);
     198      this.budgetsTextBox.Name = "budgetsTextBox";
     199      this.budgetsTextBox.Size = new System.Drawing.Size(139, 20);
     200      this.budgetsTextBox.TabIndex = 6;
     201      this.budgetsTextBox.Text = "1e2 ; 1e3 ; 1e4 ; 1e5 ; 1e6";
     202      this.budgetsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.targetsTextBox_Validating);
     203      //
     204      // fixedCostButton
     205      //
     206      this.fixedCostButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
     207      this.fixedCostButton.Location = new System.Drawing.Point(435, 348);
     208      this.fixedCostButton.Name = "fixedCostButton";
     209      this.fixedCostButton.Size = new System.Drawing.Size(89, 23);
     210      this.fixedCostButton.TabIndex = 7;
     211      this.fixedCostButton.Text = "Add as Result";
     212      this.fixedCostButton.UseVisualStyleBackColor = true;
     213      this.fixedCostButton.Click += new System.EventHandler(this.fixedCostButton_Click);
     214      //
    152215      // RunCollectionRLDView
    153216      //
    154217      this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Inherit;
     218      this.Controls.Add(this.generateTargetsButton);
     219      this.Controls.Add(this.fixedCostButton);
     220      this.Controls.Add(this.fixedTargetButton);
     221      this.Controls.Add(this.budgetsTextBox);
    155222      this.Controls.Add(this.targetsTextBox);
    156223      this.Controls.Add(this.logScalingCheckBox);
    157224      this.Controls.Add(this.groupComboBox);
    158       this.Controls.Add(this.label2);
     225      this.Controls.Add(this.groupLabel);
     226      this.Controls.Add(this.budgetsLabel);
    159227      this.Controls.Add(this.viewHost);
    160       this.Controls.Add(this.label3);
    161       this.Controls.Add(this.label1);
     228      this.Controls.Add(this.targetsLabel);
     229      this.Controls.Add(this.dataTableLabel);
    162230      this.Controls.Add(this.dataTableComboBox);
    163231      this.Name = "RunCollectionRLDView";
     
    172240
    173241    private System.Windows.Forms.ComboBox dataTableComboBox;
    174     private System.Windows.Forms.Label label1;
     242    private System.Windows.Forms.Label dataTableLabel;
    175243    private MainForm.WindowsForms.ViewHost viewHost;
    176     private System.Windows.Forms.Label label2;
     244    private System.Windows.Forms.Label groupLabel;
    177245    private System.Windows.Forms.ComboBox groupComboBox;
    178246    private System.Windows.Forms.CheckBox logScalingCheckBox;
    179247    private System.Windows.Forms.TextBox targetsTextBox;
    180     private System.Windows.Forms.Label label3;
     248    private System.Windows.Forms.Label targetsLabel;
    181249    protected System.Windows.Forms.ErrorProvider errorProvider;
     250    private System.Windows.Forms.Button fixedTargetButton;
     251    private System.Windows.Forms.Button generateTargetsButton;
     252    private System.Windows.Forms.ToolTip toolTip;
     253    private System.Windows.Forms.Button fixedCostButton;
     254    private System.Windows.Forms.TextBox budgetsTextBox;
     255    private System.Windows.Forms.Label budgetsLabel;
    182256  }
    183257}
  • branches/PerformanceComparison/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs

    r12804 r12806  
    2929using HeuristicLab.Common;
    3030using HeuristicLab.Core.Views;
     31using HeuristicLab.Data;
    3132using HeuristicLab.MainForm;
     33using HeuristicLab.MainForm.WindowsForms;
    3234
    3335namespace HeuristicLab.Optimization.Views {
     
    156158        UpdateDataTableComboBox();
    157159      }
     160    }
     161
     162    protected override void SetEnabledStateOfControls() {
     163      base.SetEnabledStateOfControls();
     164      groupComboBox.Enabled = Content != null;
     165      dataTableComboBox.Enabled = Content != null;
     166      fixedTargetButton.Enabled = Content != null && levels != null && dataTableComboBox.SelectedIndex >= 0;
    158167    }
    159168
     
    172181          var worst = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).First();
    173182          var best = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Last();
    174           levels = Enumerable.Range(0, 51).Select(x => worst + (x / 50.0) * (best - worst)).ToArray();
     183          levels = Enumerable.Range(0, 11).Select(x => worst + (x / 10.0) * (best - worst)).ToArray();
    175184          suppressTargetsEvents = true;
    176185          targetsTextBox.Text = string.Join(" ; ", levels);
     
    263272    private void groupComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    264273      UpdateRuns();
     274      SetEnabledStateOfControls();
    265275    }
    266276    private void dataTableComboBox_SelectedIndexChanged(object sender, EventArgs e) {
    267277      UpdateRuns();
     278      SetEnabledStateOfControls();
    268279    }
    269280
     
    294305      errorProvider.SetError(targetsTextBox, null);
    295306      levels = targetList.ToArray();
     307      UpdateRuns();
     308      SetEnabledStateOfControls();
     309    }
     310
     311    private void generateTargetsButton_Click(object sender, EventArgs e) {
     312      decimal max = 1, min = 0, count = 10;
     313      if (levels != null) {
     314        max = (decimal)Math.Max(levels.First(), levels.Last());
     315        min = (decimal)Math.Min(levels.First(), levels.Last());
     316        count = levels.Length;
     317      } else if (Content.Count > 0 && dataTableComboBox.SelectedIndex >= 0) {
     318        var table = (string)dataTableComboBox.SelectedItem;
     319        var worst = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).First();
     320        var best = Content.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Last();
     321        max = (decimal)Math.Max(best, worst);
     322        min = (decimal)Math.Min(best, worst);
     323        count = 10;
     324      }
     325      using (var dialog = new DefineArithmeticProgressionDialog(false, min, max, (max - min) / count)) {
     326        if (dialog.ShowDialog() == DialogResult.OK) {
     327          if (dialog.Values.Any()) {
     328            var maximization = true;
     329            if (Content.Count > 0 && Content.First().Parameters.ContainsKey("Maximization"))
     330              maximization = ((BoolValue)Content.First().Parameters["Maximization"]).Value;
     331
     332            levels = maximization ? dialog.Values.Select(x => (double)x).ToArray()
     333                                  : dialog.Values.Reverse().Select(x => (double)x).ToArray();
     334            UpdateRuns();
     335            SetEnabledStateOfControls();
     336          }
     337        }
     338      }
     339    }
     340
     341    private void fixedTargetButton_Click(object sender, EventArgs e) {
     342      var table = (string)dataTableComboBox.SelectedItem;
     343      foreach (var run in Content) {
     344        var resultsTable = (IndexedDataTable<double>)run.Results[table];
     345        var values = resultsTable.Rows.First().Values;
     346        var maximization = values.First().Item2 < values.Last().Item2;
     347        var i = 0;
     348        var j = 0;
     349        var current = values[j];
     350        var prev = Tuple.Create(-1.0, double.NaN);
     351        while (i < levels.Length) {
     352          if (prev.Item2 != current.Item2
     353              && (maximization && current.Item2 >= levels[i]
     354              || !maximization && current.Item2 <= levels[i])) {
     355            run.Results[table + ".Target" + levels[i]] = new DoubleValue(current.Item1);
     356            i++;
     357          } else {
     358            j++;
     359            if (j >= values.Count) break;
     360            prev = current;
     361            current = values[j];
     362          }
     363        }
     364      }
     365    }
     366
     367    private void fixedCostButton_Click(object sender, EventArgs e) {
     368      var table = (string)dataTableComboBox.SelectedItem;
     369      var budgetStrings = budgetsTextBox.Text.Split(new[] { ';', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);
     370      if (budgetStrings.Length == 0) {
     371        MessageBox.Show("Define a number of budgets.");
     372        return;
     373      }
     374      var budgetList = new List<double>();
     375      foreach (var bs in budgetStrings) {
     376        double v;
     377        if (!double.TryParse(bs, out v)) {
     378          MessageBox.Show("Budgets must be a valid number: " + bs);
     379          return;
     380        }
     381        budgetList.Add(v);
     382      }
     383      budgetList.Sort();
     384
     385      foreach (var run in Content) {
     386        var resultsTable = (IndexedDataTable<double>)run.Results[table];
     387        var values = resultsTable.Rows.First().Values;
     388        var i = 0;
     389        var j = 0;
     390        var current = values[j];
     391        var prev = Tuple.Create(-1.0, double.NaN);
     392        while (i < budgetList.Count) {
     393          if (prev.Item2 != current.Item2 && current.Item1 >= budgetList[i]) {
     394            run.Results[table + ".Cost" + budgetList[i]] = new DoubleValue(double.IsNaN(prev.Item2) || current.Item1 == budgetList[i] ? current.Item2 : prev.Item2);
     395            i++;
     396          } else {
     397            j++;
     398            if (j >= values.Count) break;
     399            prev = current;
     400            current = values[j];
     401          }
     402        }
     403      }
    296404    }
    297405  }
Note: See TracChangeset for help on using the changeset viewer.