Free cookie consent management tool by TermsFeed Policy Generator

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

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.