Changeset 15125 for trunk/sources
- Timestamp:
- 07/06/17 01:30:45 (7 years ago)
- Location:
- trunk/sources
- Files:
-
- 3 added
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Common/3.3/HeuristicLab.Common-3.3.csproj
r12292 r15125 131 131 <Compile Include="Constants.cs" /> 132 132 <Compile Include="ArrayExtensions.cs" /> 133 <Compile Include="Statistics\EmpiricalCumulativeDistributionFunction.cs" /> 133 134 <Compile Include="ListExtensions.cs" /> 134 135 <Compile Include="Point2D.cs" /> … … 139 140 <Compile Include="DeepCloneable.cs" /> 140 141 <Compile Include="Content\IContent.cs" /> 141 <Compile Include=" EnumerableStatisticExtensions.cs" />142 <Compile Include="Statistics\EnumerableStatisticExtensions.cs" /> 142 143 <Compile Include="IDeepCloneable.cs" /> 143 144 <Compile Include="Plugin.cs" /> -
trunk/sources/HeuristicLab.Common/3.3/Point2D.cs
r14860 r15125 54 54 } 55 55 56 public static Point2D<T> Create(T x, T y, object tag = null) { 57 return new Point2D<T>(x, y, tag); 58 } 59 56 60 public static bool operator ==(Point2D<T> left, Point2D<T> right) { 57 61 return left.x.Equals(right.x) && left.y.Equals(right.y) && left.tag == right.tag; -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.Designer.cs
r14652 r15125 45 45 private void InitializeComponent() { 46 46 this.components = new System.ComponentModel.Container(); 47 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea 1= new System.Windows.Forms.DataVisualization.Charting.ChartArea();48 System.Windows.Forms.DataVisualization.Charting.Legend legend 1= new System.Windows.Forms.DataVisualization.Charting.Legend();47 System.Windows.Forms.DataVisualization.Charting.ChartArea chartArea2 = new System.Windows.Forms.DataVisualization.Charting.ChartArea(); 48 System.Windows.Forms.DataVisualization.Charting.Legend legend2 = new System.Windows.Forms.DataVisualization.Charting.Legend(); 49 49 this.dataTableComboBox = new System.Windows.Forms.ComboBox(); 50 50 this.dataTableLabel = new System.Windows.Forms.Label(); … … 66 66 this.relativeOrAbsoluteComboBox = new System.Windows.Forms.ComboBox(); 67 67 this.targetChart = new HeuristicLab.Visualization.ChartControlsExtensions.EnhancedChart(); 68 this.showLabelsCheckBox = new System.Windows.Forms.CheckBox(); 68 69 this.markerCheckBox = new System.Windows.Forms.CheckBox(); 69 70 this.boundShadingCheckBox = new System.Windows.Forms.CheckBox(); … … 71 72 this.byCostViewHost = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 72 73 this.budgetLogScalingCheckBox = new System.Windows.Forms.CheckBox(); 73 this.aggregateBudgetsCheckBox = new System.Windows.Forms.CheckBox();74 74 this.generateBudgetsButton = new System.Windows.Forms.Button(); 75 75 this.byTableTabPage = new System.Windows.Forms.TabPage(); … … 202 202 this.budgetsTextBox.Location = new System.Drawing.Point(59, 8); 203 203 this.budgetsTextBox.Name = "budgetsTextBox"; 204 this.budgetsTextBox.Size = new System.Drawing.Size(3 09, 20);204 this.budgetsTextBox.Size = new System.Drawing.Size(391, 20); 205 205 this.budgetsTextBox.TabIndex = 6; 206 206 this.budgetsTextBox.Validating += new System.ComponentModel.CancelEventHandler(this.budgetsTextBox_Validating); … … 249 249 this.byTargetTabPage.Controls.Add(this.relativeOrAbsoluteComboBox); 250 250 this.byTargetTabPage.Controls.Add(this.targetChart); 251 this.byTargetTabPage.Controls.Add(this.showLabelsCheckBox); 251 252 this.byTargetTabPage.Controls.Add(this.markerCheckBox); 252 253 this.byTargetTabPage.Controls.Add(this.boundShadingCheckBox); … … 284 285 | System.Windows.Forms.AnchorStyles.Left) 285 286 | System.Windows.Forms.AnchorStyles.Right))); 286 chartArea 1.AxisX.IsStartedFromZero = false;287 chartArea 1.AxisX.MinorGrid.Enabled = true;288 chartArea 1.AxisX.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;289 chartArea 1.AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;290 chartArea 1.AxisY.Maximum = 1D;291 chartArea 1.AxisY.Minimum = 0D;292 chartArea 1.AxisY.MinorGrid.Enabled = true;293 chartArea 1.AxisY.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke;294 chartArea 1.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash;295 chartArea 1.Name = "ChartArea1";296 this.targetChart.ChartAreas.Add(chartArea 1);297 legend 1.Alignment = System.Drawing.StringAlignment.Center;298 legend 1.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top;299 legend 1.Name = "Legend1";300 this.targetChart.Legends.Add(legend 1);287 chartArea2.AxisX.IsStartedFromZero = false; 288 chartArea2.AxisX.MinorGrid.Enabled = true; 289 chartArea2.AxisX.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke; 290 chartArea2.AxisX.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash; 291 chartArea2.AxisY.Maximum = 1D; 292 chartArea2.AxisY.Minimum = 0D; 293 chartArea2.AxisY.MinorGrid.Enabled = true; 294 chartArea2.AxisY.MinorGrid.LineColor = System.Drawing.Color.WhiteSmoke; 295 chartArea2.AxisY.MinorGrid.LineDashStyle = System.Windows.Forms.DataVisualization.Charting.ChartDashStyle.Dash; 296 chartArea2.Name = "ChartArea1"; 297 this.targetChart.ChartAreas.Add(chartArea2); 298 legend2.Alignment = System.Drawing.StringAlignment.Center; 299 legend2.Docking = System.Windows.Forms.DataVisualization.Charting.Docking.Top; 300 legend2.Name = "Legend1"; 301 this.targetChart.Legends.Add(legend2); 301 302 this.targetChart.Location = new System.Drawing.Point(6, 34); 302 303 this.targetChart.Name = "targetChart"; … … 308 309 this.targetChart.MouseDown += new System.Windows.Forms.MouseEventHandler(this.chart_MouseDown); 309 310 this.targetChart.MouseMove += new System.Windows.Forms.MouseEventHandler(this.chart_MouseMove); 311 // 312 // showLabelsCheckBox 313 // 314 this.showLabelsCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 315 this.showLabelsCheckBox.AutoSize = true; 316 this.showLabelsCheckBox.Checked = true; 317 this.showLabelsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; 318 this.showLabelsCheckBox.Location = new System.Drawing.Point(329, 364); 319 this.showLabelsCheckBox.Name = "showLabelsCheckBox"; 320 this.showLabelsCheckBox.Size = new System.Drawing.Size(81, 17); 321 this.showLabelsCheckBox.TabIndex = 6; 322 this.showLabelsCheckBox.Text = "show labels"; 323 this.showLabelsCheckBox.UseVisualStyleBackColor = true; 324 this.showLabelsCheckBox.CheckedChanged += new System.EventHandler(this.showLabelsCheckBox_CheckedChanged); 310 325 // 311 326 // markerCheckBox … … 339 354 this.byCostTabPage.Controls.Add(this.byCostViewHost); 340 355 this.byCostTabPage.Controls.Add(this.budgetLogScalingCheckBox); 341 this.byCostTabPage.Controls.Add(this.aggregateBudgetsCheckBox);342 356 this.byCostTabPage.Controls.Add(this.generateBudgetsButton); 343 357 this.byCostTabPage.Controls.Add(this.budgetsLabel); … … 379 393 this.budgetLogScalingCheckBox.UseVisualStyleBackColor = true; 380 394 this.budgetLogScalingCheckBox.CheckedChanged += new System.EventHandler(this.logScalingCheckBox_CheckedChanged); 381 //382 // aggregateBudgetsCheckBox383 //384 this.aggregateBudgetsCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));385 this.aggregateBudgetsCheckBox.AutoSize = true;386 this.aggregateBudgetsCheckBox.Checked = true;387 this.aggregateBudgetsCheckBox.CheckState = System.Windows.Forms.CheckState.Checked;388 this.aggregateBudgetsCheckBox.Location = new System.Drawing.Point(374, 10);389 this.aggregateBudgetsCheckBox.Name = "aggregateBudgetsCheckBox";390 this.aggregateBudgetsCheckBox.Size = new System.Drawing.Size(74, 17);391 this.aggregateBudgetsCheckBox.TabIndex = 10;392 this.aggregateBudgetsCheckBox.Text = "aggregate";393 this.aggregateBudgetsCheckBox.UseVisualStyleBackColor = true;394 this.aggregateBudgetsCheckBox.CheckedChanged += new System.EventHandler(this.aggregateBudgetsCheckBox_CheckedChanged);395 395 // 396 396 // generateBudgetsButton … … 496 496 private System.Windows.Forms.TabPage byCostTabPage; 497 497 private System.Windows.Forms.TabPage byTableTabPage; 498 private System.Windows.Forms.CheckBox aggregateBudgetsCheckBox;499 498 private System.Windows.Forms.Button generateBudgetsButton; 500 499 private System.Windows.Forms.CheckBox budgetLogScalingCheckBox; … … 507 506 private System.Windows.Forms.CheckBox markerCheckBox; 508 507 private System.Windows.Forms.ComboBox relativeOrAbsoluteComboBox; 508 private System.Windows.Forms.CheckBox showLabelsCheckBox; 509 509 } 510 510 } -
trunk/sources/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs
r14775 r15125 81 81 private double[] budgets; 82 82 private bool targetsAreRelative = true; 83 private bool showLabelsInTargetChart = true; 83 84 private readonly BindingList<ProblemInstance> problems; 84 85 … … 96 97 targetChart.ChartAreas[0].CursorX.Interval = 1; 97 98 targetChart.SuppressExceptions = true; 98 byCostDataTable = new IndexedDataTable<double>("ECDF by Cost", "A data table containing the ECDF of each of a number of groups.") {99 byCostDataTable = new IndexedDataTable<double>("ECDF by Cost", "A data table containing the ECDF of function values (relative to best-known).") { 99 100 VisualProperties = { 100 YAxisTitle = "Proportion of unused budgets",101 YAxisTitle = "Proportion of runs", 101 102 YAxisMinimumFixedValue = 0, 102 103 YAxisMinimumAuto = false, … … 284 285 addTargetsAsResultButton.Enabled = Content != null && targets != null && dataTableComboBox.SelectedIndex >= 0; 285 286 addBudgetsAsResultButton.Enabled = Content != null && budgets != null && dataTableComboBox.SelectedIndex >= 0; 287 generateTargetsButton.Enabled = targets != null; 286 288 } 287 289 … … 314 316 targetChart.Series.Clear(); 315 317 invisibleTargetSeries.Clear(); 316 318 317 319 var table = (string)dataTableComboBox.SelectedItem; 318 320 if (string.IsNullOrEmpty(table)) return; … … 424 426 if (!labelPrinted && row.Points.Count > 0) { 425 427 var point = row.Points.Last(); 426 point.Label = row.Name; 428 if (showLabelsInTargetChart) 429 point.Label = row.Name; 427 430 point.MarkerStyle = MarkerStyle.Cross; 428 431 point.MarkerBorderWidth = 1; … … 456 459 if (!labelPrinted) { 457 460 var point = row.Points.Last(); 458 point.Label = row.Name; 461 if (showLabelsInTargetChart) 462 point.Label = row.Name; 459 463 point.MarkerStyle = MarkerStyle.Cross; 460 464 point.MarkerBorderWidth = 1; … … 504 508 if (!labelPrinted && row.Points.Count > 0) { 505 509 var point = row.Points.Last(); 506 point.Label = row.Name; 510 if (showLabelsInTargetChart) 511 point.Label = row.Name; 507 512 point.MarkerStyle = MarkerStyle.Cross; 508 513 point.MarkerBorderWidth = 1; … … 514 519 if (!labelPrinted) { 515 520 var point = row.Points.Last(); 516 point.Label = row.Name; 521 if (showLabelsInTargetChart) 522 point.Label = row.Name; 517 523 point.MarkerStyle = MarkerStyle.Cross; 518 524 point.MarkerBorderWidth = 1; … … 572 578 private void GenerateDefaultTargets() { 573 579 targets = new[] { 0.1, 0.095, 0.09, 0.085, 0.08, 0.075, 0.07, 0.065, 0.06, 0.055, 0.05, 0.045, 0.04, 0.035, 0.03, 0.025, 0.02, 0.015, 0.01, 0.005, 0 }; 574 suppressTargetsEvents = true; 575 targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%"; 576 suppressTargetsEvents = false; 580 SynchronizeTargetTextBox(); 577 581 } 578 582 579 583 private Tuple<bool, double> GetEffortToHitTarget( 580 IEnumerable<Tuple<double, double>> convergenceGraph,584 ObservableList<Tuple<double, double>> convergenceGraph, 581 585 double absTarget, bool maximization) { 582 var hit = false; 583 var effort = double.NaN; 584 foreach (var dent in convergenceGraph) { 585 effort = dent.Item1; 586 hit = maximization && dent.Item2 >= absTarget || !maximization && dent.Item2 <= absTarget; 587 if (hit) break; 588 } 589 if (double.IsNaN(effort)) throw new ArgumentException("Convergence graph is empty.", "convergenceGraph"); 590 return Tuple.Create(hit, effort); 586 if (convergenceGraph.Count == 0) 587 throw new ArgumentException("Convergence graph is empty.", "convergenceGraph"); 588 589 var index = convergenceGraph.BinarySearch(Tuple.Create(0.0, absTarget), new TargetComparer(maximization)); 590 if (index >= 0) { 591 return Tuple.Create(true, convergenceGraph[index].Item1); 592 } else { 593 index = ~index; 594 if (index >= convergenceGraph.Count) 595 return Tuple.Create(false, convergenceGraph.Last().Item1); 596 return Tuple.Create(true, convergenceGraph[index].Item1); 597 } 591 598 } 592 599 593 600 private void UpdateErtTables(List<AlgorithmInstance> algorithmInstances) { 594 601 ertTableView.Content = null; 595 var columns = 1 + targets.Length + 1; 596 var matrix = new string[algorithmInstances.Count * algorithmInstances.Max(x => x.GetNumberOfProblemInstances()) + algorithmInstances.Max(x => x.GetNumberOfProblemInstances()), columns]; 602 var columns = targets.Length + 1; 603 var totalRows = algorithmInstances.Count * algorithmInstances.Max(x => x.GetNumberOfProblemInstances()) + algorithmInstances.Max(x => x.GetNumberOfProblemInstances()); 604 var matrix = new StringMatrix(totalRows, columns); 605 var rowNames = new List<string>(); 606 matrix.ColumnNames = targets.Select(x => targetsAreRelative ? (100 * x).ToString() + "%" : x.ToString()) 607 .Concat(new[] { "#succ" }).ToList(); 597 608 var rowCount = 0; 598 609 … … 604 615 foreach (var problem in problems) { 605 616 var max = problem.IsMaximization(); 606 matrix[rowCount, 0] = problem.ToString();617 rowNames.Add(problem.ToString()); 607 618 var absTargets = GetAbsoluteTargetsWorstToBest(problem); 608 for (var i = 0; i < absTargets.Length; i++) { 609 matrix[rowCount, i + 1] = absTargets[i].ToString(CultureInfo.CurrentCulture.NumberFormat); 610 } 611 matrix[rowCount, columns - 1] = "#succ"; 619 if (targetsAreRelative) { 620 // print out the absolute target values 621 for (var i = 0; i < absTargets.Length; i++) { 622 matrix[rowCount, i] = absTargets[i].ToString("##,0.0", CultureInfo.CurrentCulture.NumberFormat); 623 } 624 } 612 625 rowCount++; 613 626 614 627 foreach (var alg in algorithmInstances) { 615 matrix[rowCount, 0] = alg.Name;628 rowNames.Add(alg.Name); 616 629 var runs = alg.GetRuns(problem).ToList(); 617 630 if (runs.Count == 0) { … … 623 636 for (var i = 0; i < absTargets.Length; i++) { 624 637 result = ExpectedRuntimeHelper.CalculateErt(runs, tableName, absTargets[i], max); 625 matrix[rowCount, i + 1] = result.ToString();638 matrix[rowCount, i] = result.ToString(); 626 639 } 627 640 matrix[rowCount, columns - 1] = targets.Length > 0 ? result.SuccessfulRuns + "/" + result.TotalRuns : "-"; … … 629 642 } 630 643 } 631 ertTableView.Content = new StringMatrix(matrix); 644 matrix.RowNames = rowNames; 645 ertTableView.Content = matrix; 632 646 ertTableView.DataGridView.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCells); 633 647 } … … 658 672 var resultsTable = (IndexedDataTable<double>)run.Results[table]; 659 673 660 if (aggregateBudgetsCheckBox.Checked) { 661 CalculateHitsForAllBudgets(hits, resultsTable.Rows.First(), alg.GetNumberOfProblemInstances(), problem, alg.Name, alg.GetNumberOfRuns(problem)); 662 } else { 663 CalculateHitsForEachBudget(hits, resultsTable.Rows.First(), alg.GetNumberOfProblemInstances(), problem, alg.Name, alg.GetNumberOfRuns(problem)); 664 } 674 CalculateHitsForEachBudget(hits, resultsTable.Rows.First(), problem, alg.Name); 665 675 } 666 676 } … … 678 688 679 689 var total = 0.0; 690 var count = list.Value.Count; 680 691 foreach (var h in list.Value) { 681 692 total += h.Value; 682 row.Values.Add(Tuple.Create(h.Key, total ));693 row.Values.Add(Tuple.Create(h.Key, total / (double)count)); 683 694 } 684 695 … … 697 708 var min = runs.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Select(y => y.Item1).Min()).Min(); 698 709 var max = runs.Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Select(y => y.Item1).Max()).Max(); 699 var points = 20;710 var points = 3; 700 711 budgets = Enumerable.Range(1, points).Select(x => min + (x / (double)points) * (max - min)).ToArray(); 701 712 suppressBudgetsEvents = true; … … 704 715 } 705 716 706 private void CalculateHitsForEachBudget(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, int groupCount, ProblemInstance problem, string groupName, int problemCount) {717 private void CalculateHitsForEachBudget(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, ProblemInstance problem, string groupName) { 707 718 var max = problem.IsMaximization(); 719 var prevIndex = 0; 708 720 foreach (var b in budgets) { 709 721 var key = groupName + "-" + b; 722 var index = row.Values.BinarySearch(prevIndex, row.Values.Count - prevIndex, Tuple.Create(b, 0.0), new CostComparer()); 723 if (index < 0) { 724 index = ~index; 725 if (index >= row.Values.Count) break; // the run wasn't long enough to use up budget b (or any subsequent larger one) 726 } 710 727 if (!hits.ContainsKey(key)) hits.Add(key, new SortedList<double, double>()); 711 Tuple<double, double> prev = null; 712 foreach (var v in row.Values) { 713 if (v.Item1 >= b) { 714 // the budget may be too low to achieve any target 715 if (prev == null && v.Item1 != b) break; 716 var tgt = ((prev == null || v.Item1 == b) ? v.Item2 : prev.Item2); 717 var relTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, tgt) + 1; 718 if (hits[key].ContainsKey(relTgt)) 719 hits[key][relTgt] += 1.0 / (groupCount * problemCount); 720 else hits[key][relTgt] = 1.0 / (groupCount * problemCount); 721 break; 722 } 723 prev = v; 724 } 725 if (hits[key].Count == 0) hits.Remove(key); 726 } 727 } 728 729 private void CalculateHitsForAllBudgets(Dictionary<string, SortedList<double, double>> hits, IndexedDataRow<double> row, int groupCount, ProblemInstance problem, string groupName, int problemCount) { 730 var values = row.Values; 731 if (!hits.ContainsKey(groupName)) hits.Add(groupName, new SortedList<double, double>()); 732 733 var i = 0; 734 var j = 0; 735 Tuple<double, double> prev = null; 736 var max = problem.IsMaximization(); 737 while (i < budgets.Length && j < values.Count) { 738 var current = values[j]; 739 if (current.Item1 >= budgets[i]) { 740 if (prev != null || current.Item1 == budgets[i]) { 741 var tgt = (prev == null || current.Item1 == budgets[i]) ? current.Item2 : prev.Item2; 742 var relTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, tgt) + 1; 743 if (!hits[groupName].ContainsKey(relTgt)) hits[groupName][relTgt] = 0; 744 hits[groupName][relTgt] += 1.0 / (groupCount * problemCount * budgets.Length); 745 } 746 i++; 747 } else { 748 j++; 749 prev = current; 750 } 751 } 752 var lastTgt = values.Last().Item2; 753 var lastRelTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, lastTgt) + 1; 754 if (i < budgets.Length && !hits[groupName].ContainsKey(lastRelTgt)) hits[groupName][lastRelTgt] = 0; 755 while (i < budgets.Length) { 756 hits[groupName][lastRelTgt] += 1.0 / (groupCount * problemCount * budgets.Length); 757 i++; 728 var v = row.Values[index]; 729 var relTgt = CalculateRelativeDifference(max, problem.BestKnownQuality, v.Item2) + 1; 730 if (hits[key].ContainsKey(relTgt)) 731 hits[key][relTgt]++; 732 else hits[key][relTgt] = 1.0; 733 prevIndex = index; 758 734 } 759 735 } … … 762 738 private void UpdateCaption() { 763 739 Caption = Content != null ? Content.OptimizerName + " RLD View" : ViewAttribute.GetViewName(GetType()); 740 } 741 742 private void SynchronizeTargetTextBox() { 743 if (InvokeRequired) Invoke((Action)SynchronizeTargetTextBox); 744 else { 745 suppressTargetsEvents = true; 746 try { 747 if (targetsAreRelative) 748 targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%"; 749 else targetsTextBox.Text = string.Join(" ; ", targets); 750 } finally { suppressTargetsEvents = false; } 751 } 764 752 } 765 753 … … 814 802 errorProvider.SetError(targetsTextBox, null); 815 803 targets = targetsAreRelative ? targetList.Select(x => (double)x).OrderByDescending(x => x).ToArray() : targetList.Select(x => (double)x).ToArray(); 816 suppressTargetsEvents = true; 817 try { 818 if (targetsAreRelative) 819 targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%"; 820 else targetsTextBox.Text = string.Join(" ; ", targets); 821 } finally { suppressTargetsEvents = false; } 822 804 805 SynchronizeTargetTextBox(); 823 806 UpdateResultsByTarget(); 824 807 SetEnabledStateOfControls(); … … 848 831 } 849 832 targetsAreRelative = (string)relativeOrAbsoluteComboBox.SelectedItem == "relative"; 850 S uspendRepaint();851 suppressTargetsEvents = true; 833 SynchronizeTargetTextBox(); 834 852 835 try { 853 if (targetsAreRelative) 854 targetsTextBox.Text = string.Join("% ; ", targets.Select(x => x * 100)) + "%"; 855 else targetsTextBox.Text = string.Join(" ; ", targets); 856 836 SuspendRepaint(); 857 837 UpdateResultsByTarget(); 858 } finally { suppressTargetsEvents = false;ResumeRepaint(true); }838 } finally { ResumeRepaint(true); } 859 839 } 860 840 861 841 private void generateTargetsButton_Click(object sender, EventArgs e) { 862 decimal max = 1, min = 0, count = 10; 863 if (targets != null) { 864 max = (decimal)targets.Max(); 865 min = (decimal)targets.Min(); 866 count = targets.Length; 867 } else if (Content.Count > 0 && dataTableComboBox.SelectedIndex >= 0) { 868 var table = (string)dataTableComboBox.SelectedItem; 869 max = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item2)).Max(); 870 min = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item2)).Min(); 871 count = 6; 842 if (targets == null) return; 843 decimal max = 10, min = 0, count = 10; 844 max = (decimal)targets.Max(); 845 min = (decimal)targets.Min(); 846 count = targets.Length - 1; 847 if (targetsAreRelative) { 848 max *= 100; 849 min *= 100; 872 850 } 873 851 using (var dialog = new DefineArithmeticProgressionDialog(false, min, max, (max - min) / count)) { 874 852 if (dialog.ShowDialog() == DialogResult.OK) { 875 853 if (dialog.Values.Any()) { 876 targets = dialog.Values.Select(x => (double)x).ToArray(); 877 suppressTargetsEvents = true; 878 if (targetsAreRelative) 879 targetsTextBox.Text = string.Join("% ; ", targets); 880 else targetsTextBox.Text = string.Join(" ; ", targets); 881 suppressTargetsEvents = false; 882 854 targets = targetsAreRelative 855 ? dialog.Values.OrderByDescending(x => x).Select(x => (double)x / 100.0).ToArray() 856 : dialog.Values.Select(x => (double)x).ToArray(); 857 858 SynchronizeTargetTextBox(); 883 859 UpdateResultsByTarget(); 884 860 SetEnabledStateOfControls(); … … 896 872 var resultsTable = (IndexedDataTable<double>)run.Results[table]; 897 873 var values = resultsTable.Rows.First().Values; 898 var i = 0;899 var j = 0;900 874 var pd = new ProblemInstance(run); 875 pd = problems.Single(x => x.Equals(pd)); 901 876 var max = pd.IsMaximization(); 902 var absTargets = GetAbsoluteTargetsWorstToBest(problems.Single(x => x.Equals(pd))); 903 while (i < absTargets.Length && j < values.Count) { 904 var target = absTargets[i]; 905 var current = values[j]; 906 if (max && current.Item2 >= target || !max && current.Item2 <= target) { 907 run.Results[table + ".Target" + target] = new DoubleValue(current.Item1); 908 i++; 909 } else { 910 j++; 911 } 877 var absTargets = GetAbsoluteTargetsWorstToBest(pd); 878 879 var prevIndex = 0; 880 for (var i = 0; i < absTargets.Length; i++) { 881 var absTarget = absTargets[i]; 882 var index = values.BinarySearch(prevIndex, values.Count - prevIndex, Tuple.Create(0.0, absTarget), new TargetComparer(max)); 883 if (index < 0) { 884 index = ~index; 885 if (index >= values.Count) break; // the target (and subsequent ones) wasn't achieved 886 } 887 var target = targetsAreRelative ? (targets[i] * 100) : absTarget; 888 run.Results[table + (targetsAreRelative ? ".RelTarget " : ".AbsTarget ") + target + (targetsAreRelative ? "%" : string.Empty)] = new DoubleValue(values[index].Item1); 889 prevIndex = index; 912 890 } 913 891 } … … 915 893 916 894 private void markerCheckBox_CheckedChanged(object sender, EventArgs e) { 895 SuspendRepaint(); 896 try { 897 UpdateResultsByTarget(); 898 } finally { ResumeRepaint(true); } 899 } 900 901 private void showLabelsCheckBox_CheckedChanged(object sender, EventArgs e) { 902 showLabelsInTargetChart = showLabelsCheckBox.Checked; 917 903 SuspendRepaint(); 918 904 try { … … 931 917 double b; 932 918 if (!double.TryParse(ts, out b)) { 933 errorProvider.SetError(budgetsTextBox, "Not all targets can be parsed: " + ts);919 errorProvider.SetError(budgetsTextBox, "Not all budgets can be parsed: " + ts); 934 920 e.Cancel = true; 935 921 return; … … 938 924 } 939 925 if (budgetList.Count == 0) { 940 errorProvider.SetError(budgetsTextBox, "Give at least one target value!");926 errorProvider.SetError(budgetsTextBox, "Give at least one budget value!"); 941 927 e.Cancel = true; 942 928 return; … … 944 930 e.Cancel = false; 945 931 errorProvider.SetError(budgetsTextBox, null); 946 budgets = budgetList.ToArray(); 932 budgets = budgetList.OrderBy(x => x).ToArray(); 933 try { 934 suppressBudgetsEvents = true; 935 budgetsTextBox.Text = string.Join(" ; ", budgets); 936 } finally { suppressBudgetsEvents = false; } 947 937 UpdateResultsByCost(); 948 938 SetEnabledStateOfControls(); 949 }950 951 private void aggregateBudgetsCheckBox_CheckedChanged(object sender, EventArgs e) {952 SuspendRepaint();953 try {954 UpdateResultsByCost();955 } finally { ResumeRepaint(true); }956 939 } 957 940 … … 966 949 min = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Min(y => y.Item1)).Min(); 967 950 max = (decimal)Content.Where(x => x.Results.ContainsKey(table)).Select(x => ((IndexedDataTable<double>)x.Results[table]).Rows.First().Values.Max(y => y.Item1)).Max(); 968 count = 6;951 count = 3; 969 952 } 970 953 using (var dialog = new DefineArithmeticProgressionDialog(false, min, max, (max - min) / count)) { … … 973 956 budgets = dialog.Values.OrderBy(x => x).Select(x => (double)x).ToArray(); 974 957 975 suppressBudgetsEvents = true; 976 budgetsTextBox.Text = string.Join(" ; ", budgets); 977 suppressBudgetsEvents = false; 958 try { 959 suppressBudgetsEvents = true; 960 budgetsTextBox.Text = string.Join(" ; ", budgets); 961 } finally { suppressBudgetsEvents = false; } 978 962 979 963 UpdateResultsByCost(); … … 986 970 private void addBudgetsAsResultButton_Click(object sender, EventArgs e) { 987 971 var table = (string)dataTableComboBox.SelectedItem; 988 var budgetStrings = budgetsTextBox.Text.Split(new[] { ';', '\t', ' ' }, StringSplitOptions.RemoveEmptyEntries);989 if (budgetStrings.Length == 0) {990 MessageBox.Show("Define a number of budgets.");991 return;992 }993 var budgetList = new List<double>();994 foreach (var bs in budgetStrings) {995 double v;996 if (!double.TryParse(bs, out v)) {997 MessageBox.Show("Budgets must be a valid number: " + bs);998 return;999 }1000 budgetList.Add(v);1001 }1002 budgetList.Sort();1003 972 1004 973 foreach (var run in Content) { … … 1006 975 var resultsTable = (IndexedDataTable<double>)run.Results[table]; 1007 976 var values = resultsTable.Rows.First().Values; 1008 var i = 0; 1009 var j = 0; 1010 Tuple<double, double> prev = null; 1011 while (i < budgetList.Count && j < values.Count) { 1012 var current = values[j]; 1013 if (current.Item1 >= budgetList[i]) { 1014 if (prev != null || current.Item1 == budgetList[i]) { 1015 var tgt = (prev == null || current.Item1 == budgetList[i]) ? current.Item2 : prev.Item2; 1016 run.Results[table + ".Cost" + budgetList[i]] = new DoubleValue(tgt); 1017 } 1018 i++; 1019 } else { 1020 j++; 1021 prev = current; 1022 } 977 var pd = new ProblemInstance(run); 978 pd = problems.Single(x => x.Equals(pd)); 979 980 var prevIndex = 0; 981 foreach (var b in budgets) { 982 var index = values.BinarySearch(prevIndex, values.Count - prevIndex, Tuple.Create(b, 0.0), new CostComparer()); 983 if (index < 0) { 984 index = ~index; 985 if (index >= values.Count) break; // the run wasn't long enough to use up budget b (or any subsequent larger one) 986 } 987 var v = values[index]; 988 var tgt = targetsAreRelative ? CalculateRelativeDifference(pd.IsMaximization(), pd.BestKnownQuality, v.Item2) : v.Item2; 989 run.Results[table + (targetsAreRelative ? ".CostForRelTarget " : ".CostForAbsTarget ") + b] = new DoubleValue(tgt); 990 prevIndex = index; 1023 991 } 1024 992 } … … 1080 1048 else pd.BestKnownQuality = double.NaN; 1081 1049 } 1082 //problemComboBox.ResetBindings();1083 1050 } 1084 1051 #endregion 1085 1052 1086 1053 private void ConfigureSeries(Series series) { 1087 series.SmartLabelStyle.Enabled = true;1054 series.SmartLabelStyle.Enabled = showLabelsInTargetChart; 1088 1055 series.SmartLabelStyle.AllowOutsidePlotArea = LabelOutsidePlotAreaStyle.No; 1089 1056 series.SmartLabelStyle.CalloutLineAnchorCapStyle = LineAnchorCapStyle.None; … … 1418 1385 } 1419 1386 } 1387 1388 private class CostComparer : Comparer<Tuple<double, double>> { 1389 public override int Compare(Tuple<double, double> x, Tuple<double, double> y) { 1390 return x.Item1.CompareTo(y.Item1); 1391 } 1392 } 1393 1394 private class TargetComparer : Comparer<Tuple<double, double>> { 1395 public bool Maximization { get; } 1396 public TargetComparer(bool maximization) { 1397 Maximization = maximization; 1398 } 1399 1400 public override int Compare(Tuple<double, double> x, Tuple<double, double> y) { 1401 return Maximization ? x.Item2.CompareTo(y.Item2) : y.Item2.CompareTo(x.Item2); 1402 } 1403 } 1420 1404 } 1421 1405 }
Note: See TracChangeset
for help on using the changeset viewer.