Changeset 13757 for branches/PerformanceComparison
- Timestamp:
- 04/13/16 16:25:12 (9 years ago)
- Location:
- branches/PerformanceComparison
- Files:
-
- 5 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis/3.3/QualityAnalysis/ExpectedRuntimeHelper.cs
r12956 r13757 1 using System.Collections.Generic; 1 using HeuristicLab.Optimization; 2 using System; 3 using System.Collections.Generic; 2 4 using System.Globalization; 3 5 using System.Linq; 4 using HeuristicLab.Optimization;5 6 6 7 namespace HeuristicLab.Analysis { 7 8 public static class ExpectedRuntimeHelper { 8 public static ErtCalculationResult CalculateErt( List<IRun> runs, string indexedDataTableName, double target, bool maximization) {9 public static ErtCalculationResult CalculateErt(IEnumerable<IEnumerable<Tuple<double, double>>> convGraphs, double target, bool maximization) { 9 10 var successful = new List<double>(); 10 11 var unsuccessful = new List<double>(); 11 foreach (var r in runs) {12 foreach (var graph in convGraphs) { 12 13 var targetAchieved = false; 13 var row = ((IndexedDataTable<double>)r.Results[indexedDataTableName]).Rows.First();14 foreach (var v in row.Values) {14 var lastEffort = double.MaxValue; 15 foreach (var v in graph) { 15 16 if (maximization && v.Item2 >= target || !maximization && v.Item2 <= target) { 16 17 successful.Add(v.Item1); … … 18 19 break; 19 20 } 21 lastEffort = v.Item1; 20 22 } 21 if (!targetAchieved) unsuccessful.Add( row.Values.Last().Item1);23 if (!targetAchieved) unsuccessful.Add(lastEffort); 22 24 } 23 25 … … 32 34 } 33 35 return new ErtCalculationResult(successful.Count, (successful.Count + unsuccessful.Count), ert); 36 } 37 38 public static ErtCalculationResult CalculateErt(List<IRun> runs, string indexedDataTableName, double target, bool maximization) { 39 return CalculateErt(runs.Select(r => ((IndexedDataTable<double>)r.Results[indexedDataTableName]).Rows.First().Values), target, maximization); 34 40 } 35 41 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/Enums.cs
r13756 r13757 26 26 SeedByCloning 27 27 } 28 29 public enum ProblemInstanceProximityType { 30 FeatureSpace, 31 PCA, 32 MDS, 33 SOM 34 } 28 35 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/HeuristicLab.OptimizationExpertSystem.Common-3.3.csproj
r13750 r13757 150 150 <Compile Include="KnowledgeCenter.cs" /> 151 151 <Compile Include="Plugin.cs" /> 152 <Compile Include=" SeedingStrategyTypes.cs" />152 <Compile Include="Enums.cs" /> 153 153 <None Include="Properties\AssemblyInfo.cs.frame" /> 154 154 <Compile Include="ProblemCharacteristicAnalysis\CharacteristicCalculator.cs" /> -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem.Common/3.3/KnowledgeCenter.cs
r13752 r13757 59 59 } 60 60 61 private readonly DoubleValue minimumTarget; 62 public DoubleValue MinimumTarget { 63 get { return minimumTarget; } 64 } 65 61 66 private readonly RunCollection instanceRuns; 62 67 public RunCollection InstanceRuns { … … 94 99 public ReadOnlyCheckedItemList<StringValue> ProblemCharacteristics { 95 100 get { return readonlyProblemCharacteristics; } 96 } 101 } 102 103 private readonly EnumValue<ProblemInstanceProximityType> problemInstanceProximity; 104 public EnumValue<ProblemInstanceProximityType> ProblemInstanceProximity { 105 get { return problemInstanceProximity; } 106 } 107 108 private readonly DoubleValue problemInstanceNeighborhoodFactor; 109 public DoubleValue ProblemInstanceNeighborhoodFactor { 110 get { return problemInstanceNeighborhoodFactor; } 111 } 97 112 98 113 private readonly CheckedItemList<IScope> solutionSeedingPool; … … 116 131 public KnowledgeCenter() { 117 132 maximumEvaluations = new IntValue(10000); 133 minimumTarget = new DoubleValue(1.05); 118 134 instanceRuns = new RunCollection(); 119 135 seededRuns = new RunCollection(); … … 123 139 problemInstances = new RunCollection(); 124 140 problemCharacteristics = new CheckedItemList<StringValue>(); 141 problemInstanceProximity = new EnumValue<ProblemInstanceProximityType>(ProblemInstanceProximityType.FeatureSpace); 142 problemInstanceNeighborhoodFactor = new DoubleValue(1); 125 143 readonlyProblemCharacteristics = problemCharacteristics.AsReadOnly(); 126 144 problem = new SingleObjectiveOKBProblem(); … … 139 157 private void RegisterEventHandlers() { 140 158 maximumEvaluations.ValueChanged += MaximumEvaluationsOnValueChanged; 159 minimumTarget.ValueChanged += MinimumTargetOnValueChanged; 141 160 problem.ProblemChanged += ProblemOnProblemChanged; 142 161 problem.Solutions.ItemsAdded += ProblemSolutionsChanged; … … 157 176 problemCharacteristics.CollectionReset += CharacteristicChanged; 158 177 problemCharacteristics.CheckedItemsChanged += CharacteristicChanged; 178 problemInstanceProximity.ValueChanged += ProblemInstanceProximityChanged; 179 problemInstanceNeighborhoodFactor.ValueChanged += ProblemInstanceProximityChanged; 159 180 } 160 181 161 182 private void MaximumEvaluationsOnValueChanged(object sender, EventArgs eventArgs) { 183 UpdateSuggestions(); 184 } 185 186 private void MinimumTargetOnValueChanged(object sender, EventArgs e) { 162 187 UpdateSuggestions(); 163 188 } … … 181 206 } 182 207 208 private void ProblemInstanceProximityChanged(object sender, EventArgs e) { 209 UpdateSuggestions(); 210 } 211 183 212 public bool IsCurrentInstance(IRun run) { 184 213 if (!problemId2ProblemInstanceMapping.ContainsSecond(run)) return false; … … 189 218 if (ProblemCharacteristics.Count == 0) return; 190 219 220 var instances = GetProblemCharacteristics(); 221 222 var key2Idx = new BidirectionalDictionary<IRun, int>(); 223 foreach (var kvp in instances.Select((k, i) => new { Index = i, Key = k.Key })) 224 key2Idx.Add(kvp.Key, kvp.Index); 225 226 #region MDS 227 Func<double[], double[], double> euclid = (a, b) => Math.Sqrt(a.Zip(b, (x, y) => (x - y)).Sum(x => x * x)); 228 var num = instances.Count; 229 var matrix = new DoubleMatrix(num, num); 230 for (var i = 0; i < num - 1; i++) { 231 for (var j = i + 1; j < num; j++) { 232 matrix[i, j] = matrix[j, i] = euclid(instances[key2Idx.GetBySecond(i)], instances[key2Idx.GetBySecond(j)]); 233 } 234 } 235 236 var coords = MultidimensionalScaling.KruskalShepard(matrix); 237 #endregion 238 #region PCA 239 var ds = new double[instances.Count, ProblemCharacteristics.CheckedItems.Count()]; 240 foreach (var instance in instances) { 241 var arr = instance.Value; 242 for (var feature = 0; feature < arr.Length; feature++) 243 ds[key2Idx.GetByFirst(instance.Key), feature] = arr[feature]; 244 } 245 246 int info; 247 double[] s2; 248 double[,] v; 249 alglib.pcabuildbasis(ds, ds.GetLength(0), ds.GetLength(1), out info, out s2, out v); 250 #endregion 251 #region SOM 252 var features = new DoubleMatrix(ProblemCharacteristics.CheckedItems.Count(), instances.Count); 253 foreach (var instance in instances) { 254 var arr = instance.Value; 255 for (var feature = 0; feature < arr.Length; feature++) 256 features[feature, key2Idx.GetByFirst(instance.Key)] = arr[feature]; 257 } 258 var somCoords = SOM.Map(features, new MersenneTwister(42), somSize: 20, learningRadius: 20, iterations: 200, jittering: true); 259 #endregion 260 261 ProblemInstances.UpdateOfRunsInProgress = true; 262 try { 263 foreach (var instance in ProblemInstances) { 264 double x = 0, y = 0; 265 for (var feature = 0; feature < ds.GetLength(1); feature++) { 266 x += ds[key2Idx.GetByFirst(instance), feature] * v[feature, 0]; 267 y += ds[key2Idx.GetByFirst(instance), feature] * v[feature, 1]; 268 } 269 270 IItem item; 271 if (instance.Results.TryGetValue("Projection.PCA.X", out item)) { 272 ((DoubleValue)item).Value = x; 273 } else instance.Results.Add("Projection.PCA.X", new DoubleValue(x)); 274 if (instance.Results.TryGetValue("Projection.PCA.Y", out item)) { 275 ((DoubleValue)item).Value = y; 276 } else instance.Results.Add("Projection.PCA.Y", new DoubleValue(y)); 277 278 if (instance.Results.TryGetValue("Projection.MDS.X", out item)) { 279 ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance), 0]; 280 } else instance.Results.Add("Projection.MDS.X", new DoubleValue(coords[key2Idx.GetByFirst(instance), 0])); 281 if (instance.Results.TryGetValue("Projection.MDS.Y", out item)) { 282 ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance), 1]; 283 } else instance.Results.Add("Projection.MDS.Y", new DoubleValue(coords[key2Idx.GetByFirst(instance), 1])); 284 285 if (instance.Results.TryGetValue("Projection.SOM.X", out item)) { 286 ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance), 0]; 287 } else instance.Results.Add("Projection.SOM.X", new DoubleValue(somCoords[key2Idx.GetByFirst(instance), 0])); 288 if (instance.Results.TryGetValue("Projection.SOM.Y", out item)) { 289 ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance), 1]; 290 } else instance.Results.Add("Projection.SOM.Y", new DoubleValue(somCoords[key2Idx.GetByFirst(instance), 1])); 291 } 292 } finally { ProblemInstances.UpdateOfRunsInProgress = false; } 293 } 294 295 private Dictionary<IRun, double[]> GetProblemCharacteristics() { 191 296 var instances = new Dictionary<IRun, double[]>(); 192 297 var values = new List<double>[ProblemCharacteristics.CheckedItems.Count()]; … … 207 312 var median = values.Select(x => x.Count == 0 ? 0.0 : x.Median()).ToList(); 208 313 209 var allValues = instances.Values.Select(x => x.Select((f, i) => new { Idx = i, Val = double.IsNaN(f) ? median[i] : f}).ToList())210 211 212 314 var allValues = instances.Values.Select(x => x.Select((f, i) => new {Idx = i, Val = double.IsNaN(f) ? median[i] : f}).ToList()) 315 .SelectMany(x => x) 316 .GroupBy(x => x.Idx, x => x.Val) 317 .OrderBy(x => x.Key).ToList(); 213 318 var avg = allValues.Select(x => x.Average()).ToList(); 214 319 var stdev = allValues.Select(x => x.StandardDeviation()).ToList(); … … 222 327 } 223 328 } 224 225 var key2Idx = new BidirectionalDictionary<IRun, int>(); 226 foreach (var kvp in instances.Select((k, i) => new { Index = i, Key = k.Key })) 227 key2Idx.Add(kvp.Key, kvp.Index); 228 229 #region MDS 230 Func<double[], double[], double> euclid = (a, b) => Math.Sqrt(a.Zip(b, (x, y) => (x - y)).Sum(x => x * x)); 231 var num = instances.Count; 232 var matrix = new DoubleMatrix(num, num); 233 for (var i = 0; i < num - 1; i++) { 234 for (var j = i + 1; j < num; j++) { 235 matrix[i, j] = matrix[j, i] = euclid(instances[key2Idx.GetBySecond(i)], instances[key2Idx.GetBySecond(j)]); 236 } 237 } 238 239 var coords = MultidimensionalScaling.KruskalShepard(matrix); 240 #endregion 241 #region PCA 242 var ds = new double[instances.Count, ProblemCharacteristics.CheckedItems.Count()]; 243 foreach (var instance in instances) { 244 var arr = instance.Value; 245 for (var feature = 0; feature < arr.Length; feature++) 246 ds[key2Idx.GetByFirst(instance.Key), feature] = arr[feature]; 247 } 248 249 int info; 250 double[] s2; 251 double[,] v; 252 alglib.pcabuildbasis(ds, ds.GetLength(0), ds.GetLength(1), out info, out s2, out v); 253 #endregion 254 #region SOM 255 var features = new DoubleMatrix(ProblemCharacteristics.CheckedItems.Count(), instances.Count); 256 foreach (var instance in instances) { 257 var arr = instance.Value; 258 for (var feature = 0; feature < arr.Length; feature++) 259 features[feature, key2Idx.GetByFirst(instance.Key)] = arr[feature]; 260 } 261 var somCoords = SOM.Map(features, new MersenneTwister(42), somSize: 20, learningRadius: 20, iterations: 200, jittering: true); 262 #endregion 263 264 ProblemInstances.UpdateOfRunsInProgress = true; 265 try { 266 foreach (var instance in ProblemInstances) { 267 double x = 0, y = 0; 268 for (var feature = 0; feature < ds.GetLength(1); feature++) { 269 x += ds[key2Idx.GetByFirst(instance), feature] * v[feature, 0]; 270 y += ds[key2Idx.GetByFirst(instance), feature] * v[feature, 1]; 271 } 272 273 IItem item; 274 if (instance.Results.TryGetValue("Projection.PCA.X", out item)) { 275 ((DoubleValue)item).Value = x; 276 } else instance.Results.Add("Projection.PCA.X", new DoubleValue(x)); 277 if (instance.Results.TryGetValue("Projection.PCA.Y", out item)) { 278 ((DoubleValue)item).Value = y; 279 } else instance.Results.Add("Projection.PCA.Y", new DoubleValue(y)); 280 281 if (instance.Results.TryGetValue("Projection.MDS.X", out item)) { 282 ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance), 0]; 283 } else instance.Results.Add("Projection.MDS.X", new DoubleValue(coords[key2Idx.GetByFirst(instance), 0])); 284 if (instance.Results.TryGetValue("Projection.MDS.Y", out item)) { 285 ((DoubleValue)item).Value = coords[key2Idx.GetByFirst(instance), 1]; 286 } else instance.Results.Add("Projection.MDS.Y", new DoubleValue(coords[key2Idx.GetByFirst(instance), 1])); 287 288 if (instance.Results.TryGetValue("Projection.SOM.X", out item)) { 289 ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance), 0]; 290 } else instance.Results.Add("Projection.SOM.X", new DoubleValue(somCoords[key2Idx.GetByFirst(instance), 0])); 291 if (instance.Results.TryGetValue("Projection.SOM.Y", out item)) { 292 ((DoubleValue)item).Value = somCoords[key2Idx.GetByFirst(instance), 1]; 293 } else instance.Results.Add("Projection.SOM.Y", new DoubleValue(somCoords[key2Idx.GetByFirst(instance), 1])); 294 } 295 } finally { ProblemInstances.UpdateOfRunsInProgress = false; } 329 return instances; 296 330 } 297 331 … … 434 468 problemClassFilter.Value = adminClient.ProblemClasses.Single(x => x.Id == probClassId).Name; 435 469 470 problemId2ProblemInstanceMapping.Clear(); 436 471 progress.Status = "Downloading problem instances..."; 437 472 progress.ProgressValue = 0; … … 550 585 551 586 if (!algInstRunDict.ContainsKey(probInstanceName)) continue; 552 foreach (var kvp in algInstRunDict[probInstanceName]) { 553 // TODO: Things needs to be configurable here (table name, targets) 554 foreach (var target in new[] { 1, 1.01, 1.05, 1.1, 1.2, 1.5 }) { 587 // TODO: Things needs to be configurable here (table name, targets) 588 foreach (var target in new[] { 1, 1.01, 1.05, 1.1, 1.2, 1.5 }) { 589 var indexMap = new BidirectionalDictionary<string, int>(); 590 var dict = new Dictionary<string, double>(); 591 var idx = 0; 592 foreach (var kvp in algInstRunDict[probInstanceName]) { 555 593 var result = ExpectedRuntimeHelper.CalculateErt(kvp.Value, "QualityPerEvaluations", bkQuality * target, maximization); 556 var resultName = kvp.Key + "@" + ((target - 1) * 100) + "%"; 557 characteristics.Add(resultName); 558 IItem item; 559 if (instance.Results.TryGetValue(resultName, out item)) { 560 ((DoubleValue)item).Value = Math.Log10(result.ExpectedRuntime); 561 } else instance.Results.Add(resultName, new DoubleValue(Math.Log10(result.ExpectedRuntime))); 594 indexMap.Add(kvp.Key, idx); 595 dict[kvp.Key] = !double.IsNaN(result.ExpectedRuntime) ? result.ExpectedRuntime : int.MaxValue; 596 idx++; 597 } 598 var points = dict.OrderBy(x => indexMap.GetByFirst(x.Key)).Select(x => x.Value > 0 ? Math.Log10(x.Value) : 0).ToArray(); 599 int[] clusters; 600 Ckmeans1dClusters(points, 5, out clusters); 601 var ranks = clusters.Select((c, i) => new { Cluster = c, Perf = dict[indexMap.GetBySecond(i)] }) 602 .GroupBy(x => x.Cluster, x => x.Perf) 603 .Select(x => new { Cluster = x.Key, AvgPerf = x.Average() }) 604 .OrderBy(x => x.AvgPerf) 605 .Select((c, i) => new { Cluster = c.Cluster, Rank = i }) 606 .ToDictionary(x => x.Cluster, x => x.Rank); 607 for (var i = 0; i < clusters.Length; i++) { 608 var resultName = "Rank." + indexMap.GetBySecond(i) + "@" + ((target - 1) * 100) + "%"; 609 instance.Results[resultName] = new IntValue(dict[indexMap.GetBySecond(i)] < int.MaxValue ? ranks[clusters[i]] : 6); 562 610 } 563 611 } … … 576 624 } finally { progress.Finish(); ProblemInstances.UpdateOfRunsInProgress = false; } 577 625 UpdateInstanceProjection(); 626 UpdateSuggestions(); 578 627 } 579 628 580 629 private void UpdateSuggestions() { 581 630 if (Problem == null) return; 631 var piDistances = GetProblemDistances(); 632 var maxDistance = piDistances.Max(); 633 // Weighted combination of algorithm performances using distance-based exponentially falling weights 634 // Scale distances by maxDistance 635 // Parameter to influence dampening factor 636 // Algorithm performances are given in expected run time 637 // Using convergence graphs up to maximum evaluations effort 638 // Care has to be taken if not every algorithm has been executed on every problem instance 582 639 var instances = new SortedList<double, IAlgorithm>(); 583 640 foreach (var relevantRuns in knowledgeBase.GroupBy(x => algorithmId2RunMapping.GetBySecond(x).Single())) { … … 608 665 } 609 666 667 private DoubleMatrix GetProblemDistances() { 668 var matrix = new DoubleMatrix(ProblemInstances.Count, ProblemInstances.Count); 669 switch (ProblemInstanceProximity.Value) { 670 case ProblemInstanceProximityType.MDS: 671 case ProblemInstanceProximityType.PCA: 672 case ProblemInstanceProximityType.SOM: 673 int i = 0, j = 0; 674 foreach (var a in ProblemInstances) { 675 double xa, ya; 676 GetProjectionCoordinates(a, out xa, out ya); 677 j = 0; 678 foreach (var b in ProblemInstances) { 679 double xb, yb; 680 GetProjectionCoordinates(b, out xb, out yb); 681 matrix[i, j] = Math.Sqrt((xa - xb) * (xa - xb) + (ya - yb) * (ya - yb)); 682 j++; 683 } 684 i++; 685 } 686 break; 687 case ProblemInstanceProximityType.FeatureSpace: 688 int k = 0, l = 0; 689 var features = GetProblemCharacteristics(); 690 foreach (var a in ProblemInstances) { 691 l = 0; 692 var fa = features[a]; 693 foreach (var b in ProblemInstances) { 694 var sum = features[b].Select((t, f) => (fa[f] - t) * (fa[f] - t)).Sum(); 695 matrix[k, l] = Math.Sqrt(sum); 696 l++; 697 } 698 k++; 699 } 700 break; 701 default: throw new InvalidOperationException(string.Format("Unkonwn proximity type {0}", ProblemInstanceProximity.Value)); 702 } 703 return matrix; 704 } 705 706 private void GetProjectionCoordinates(IRun problemInstance, out double x, out double y) { 707 x = ((DoubleValue)problemInstance.Results["Projection." + ProblemInstanceProximity.Value + ".X"]).Value; 708 y = ((DoubleValue)problemInstance.Results["Projection." + ProblemInstanceProximity.Value + ".Y"]).Value; 709 } 710 610 711 public event EventHandler<EventArgs<IProgress>> DownloadStarted; 611 712 private void OnDownloadStarted(IProgress progress) { … … 619 720 if (handler != null) handler(this, new EventArgs<IAlgorithm>(instance)); 620 721 } 722 723 // implement further classes and methods 724 private static SortedList<double, int> Ckmeans1dClusters(double[] estimations, int k, out int[] clusterValues) { 725 int nPoints = estimations.Length; 726 var distinct = estimations.Distinct().OrderBy(x => x).ToArray(); 727 var max = distinct.Max(); 728 if (distinct.Length <= k) { 729 var dict = distinct.Select((v, i) => new { Index = i, Value = v }).ToDictionary(x => x.Value, y => y.Index); 730 for (int i = distinct.Length; i < k; i++) 731 dict.Add(max + i - distinct.Length + 1, i); 732 733 clusterValues = new int[nPoints]; 734 for (int i = 0; i < nPoints; i++) 735 if (!dict.ContainsKey(estimations[i])) clusterValues[i] = 0; 736 else clusterValues[i] = dict[estimations[i]]; 737 738 return new SortedList<double, int>(dict); 739 } 740 741 var n = distinct.Length; 742 var D = new double[n, k]; 743 var B = new int[n, k]; 744 745 for (int m = 0; m < k; m++) { 746 for (int j = m; j <= n - k + m; j++) { 747 if (m == 0) 748 D[j, m] = SumOfSquaredDistances(distinct, 0, j + 1); 749 else { 750 var minD = double.MaxValue; 751 var minI = 0; 752 for (int i = 1; i <= j; i++) { 753 var d = D[i - 1, m - 1] + SumOfSquaredDistances(distinct, i, j + 1); 754 if (d < minD) { 755 minD = d; 756 minI = i; 757 } 758 } 759 D[j, m] = minD; 760 B[j, m] = minI; 761 } 762 } 763 } 764 765 var centers = new SortedList<double, int>(); 766 var upper = B[n - 1, k - 1]; 767 var c = Mean(distinct, upper, n); 768 centers.Add(c, k - 1); 769 for (int i = k - 2; i >= 0; i--) { 770 var lower = B[upper - 1, i]; 771 var c2 = Mean(distinct, lower, upper); 772 centers.Add(c2, i); 773 upper = lower; 774 } 775 776 clusterValues = new int[nPoints]; 777 for (int i = 0; i < estimations.Length; i++) { 778 clusterValues[i] = centers.MinItems(x => Math.Abs(estimations[i] - x.Key)).First().Value; 779 } 780 781 return centers; 782 } 783 784 private static double SumOfSquaredDistances(double[] x, int start, int end) { 785 if (start == end) throw new InvalidOperationException(); 786 if (start + 1 == end) return 0.0; 787 double mean = 0.0; 788 for (int i = start; i < end; i++) { 789 mean += x[i]; 790 } 791 mean /= (end - start); 792 var sum = 0.0; 793 for (int i = start; i < end; i++) { 794 sum += (x[i] - mean) * (x[i] - mean); 795 } 796 return sum; 797 } 798 799 private static double Mean(double[] x, int start, int end) { 800 if (start == end) throw new InvalidOperationException(); 801 double mean = 0.0; 802 for (int i = start; i < end; i++) { 803 mean += x[i]; 804 } 805 mean /= (end - start); 806 return mean; 807 } 621 808 } 622 809 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.Designer.cs
r13752 r13757 54 54 this.mapSplitContainer = new System.Windows.Forms.SplitContainer(); 55 55 this.showCharacteristicsCheckBox = new System.Windows.Forms.CheckBox(); 56 this.fromZeroCheckBox = new System.Windows.Forms.CheckBox(); 56 57 this.invPropCheckBox = new System.Windows.Forms.CheckBox(); 57 58 this.sizeLabel = new System.Windows.Forms.Label(); … … 62 63 this.instancesTabPage = new System.Windows.Forms.TabPage(); 63 64 this.problemInstancesView = new HeuristicLab.MainForm.WindowsForms.ViewHost(); 65 this.colorComboBox = new System.Windows.Forms.ComboBox(); 66 this.colorLabel = new System.Windows.Forms.Label(); 64 67 this.problemInstancesTabControl.SuspendLayout(); 65 68 this.mapTabPage.SuspendLayout(); … … 82 85 this.problemInstancesTabControl.Name = "problemInstancesTabControl"; 83 86 this.problemInstancesTabControl.SelectedIndex = 0; 84 this.problemInstancesTabControl.Size = new System.Drawing.Size(1 000, 760);87 this.problemInstancesTabControl.Size = new System.Drawing.Size(1108, 760); 85 88 this.problemInstancesTabControl.TabIndex = 8; 86 89 // … … 91 94 this.mapTabPage.Name = "mapTabPage"; 92 95 this.mapTabPage.Padding = new System.Windows.Forms.Padding(3); 93 this.mapTabPage.Size = new System.Drawing.Size( 992, 734);96 this.mapTabPage.Size = new System.Drawing.Size(1100, 734); 94 97 this.mapTabPage.TabIndex = 1; 95 98 this.mapTabPage.Text = "Map"; … … 106 109 // 107 110 this.mapSplitContainer.Panel1.Controls.Add(this.showCharacteristicsCheckBox); 111 this.mapSplitContainer.Panel1.Controls.Add(this.fromZeroCheckBox); 108 112 this.mapSplitContainer.Panel1.Controls.Add(this.invPropCheckBox); 113 this.mapSplitContainer.Panel1.Controls.Add(this.colorLabel); 109 114 this.mapSplitContainer.Panel1.Controls.Add(this.sizeLabel); 110 115 this.mapSplitContainer.Panel1.Controls.Add(this.projectionLabel); 111 116 this.mapSplitContainer.Panel1.Controls.Add(this.instanceMapChart); 117 this.mapSplitContainer.Panel1.Controls.Add(this.colorComboBox); 112 118 this.mapSplitContainer.Panel1.Controls.Add(this.sizeComboBox); 113 119 this.mapSplitContainer.Panel1.Controls.Add(this.projectionComboBox); 114 120 this.mapSplitContainer.Panel1.Padding = new System.Windows.Forms.Padding(0, 3, 0, 0); 115 121 this.mapSplitContainer.Panel2Collapsed = true; 116 this.mapSplitContainer.Size = new System.Drawing.Size( 986, 728);122 this.mapSplitContainer.Size = new System.Drawing.Size(1094, 728); 117 123 this.mapSplitContainer.SplitterDistance = 847; 118 124 this.mapSplitContainer.TabIndex = 12; … … 122 128 this.showCharacteristicsCheckBox.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); 123 129 this.showCharacteristicsCheckBox.Appearance = System.Windows.Forms.Appearance.Button; 124 this.showCharacteristicsCheckBox.Location = new System.Drawing.Point( 957, 4);130 this.showCharacteristicsCheckBox.Location = new System.Drawing.Point(1065, 5); 125 131 this.showCharacteristicsCheckBox.Name = "showCharacteristicsCheckBox"; 126 132 this.showCharacteristicsCheckBox.Size = new System.Drawing.Size(26, 23); … … 130 136 this.showCharacteristicsCheckBox.CheckedChanged += new System.EventHandler(this.showCharacteristicsCheckBox_CheckedChanged); 131 137 // 138 // fromZeroCheckBox 139 // 140 this.fromZeroCheckBox.AutoSize = true; 141 this.fromZeroCheckBox.Checked = true; 142 this.fromZeroCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; 143 this.fromZeroCheckBox.Location = new System.Drawing.Point(639, 8); 144 this.fromZeroCheckBox.Name = "fromZeroCheckBox"; 145 this.fromZeroCheckBox.Size = new System.Drawing.Size(69, 17); 146 this.fromZeroCheckBox.TabIndex = 17; 147 this.fromZeroCheckBox.Text = "from zero"; 148 this.fromZeroCheckBox.UseVisualStyleBackColor = true; 149 this.fromZeroCheckBox.CheckedChanged += new System.EventHandler(this.fromZeroCheckBox_CheckedChanged); 150 // 132 151 // invPropCheckBox 133 152 // … … 135 154 this.invPropCheckBox.Checked = true; 136 155 this.invPropCheckBox.CheckState = System.Windows.Forms.CheckState.Checked; 137 this.invPropCheckBox.Location = new System.Drawing.Point(5 79, 12);156 this.invPropCheckBox.Location = new System.Drawing.Point(515, 8); 138 157 this.invPropCheckBox.Name = "invPropCheckBox"; 139 158 this.invPropCheckBox.Size = new System.Drawing.Size(118, 17); … … 146 165 // 147 166 this.sizeLabel.AutoSize = true; 148 this.sizeLabel.Location = new System.Drawing.Point(2 64, 12);167 this.sizeLabel.Location = new System.Drawing.Point(251, 12); 149 168 this.sizeLabel.Name = "sizeLabel"; 150 169 this.sizeLabel.Size = new System.Drawing.Size(30, 13); … … 192 211 this.instanceMapChart.Series.Add(series1); 193 212 this.instanceMapChart.Series.Add(series2); 194 this.instanceMapChart.Size = new System.Drawing.Size(9 80, 692);213 this.instanceMapChart.Size = new System.Drawing.Size(974, 692); 195 214 this.instanceMapChart.TabIndex = 12; 196 215 // … … 199 218 this.sizeComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 200 219 this.sizeComboBox.FormattingEnabled = true; 201 this.sizeComboBox.Location = new System.Drawing.Point( 300, 6);220 this.sizeComboBox.Location = new System.Drawing.Point(287, 6); 202 221 this.sizeComboBox.Name = "sizeComboBox"; 203 this.sizeComboBox.Size = new System.Drawing.Size(2 73, 21);222 this.sizeComboBox.Size = new System.Drawing.Size(222, 21); 204 223 this.sizeComboBox.TabIndex = 13; 205 224 this.sizeComboBox.SelectedIndexChanged += new System.EventHandler(this.SizeComboBoxOnSelectedIndexChanged); … … 221 240 this.instancesTabPage.Name = "instancesTabPage"; 222 241 this.instancesTabPage.Padding = new System.Windows.Forms.Padding(3); 223 this.instancesTabPage.Size = new System.Drawing.Size( 992, 734);242 this.instancesTabPage.Size = new System.Drawing.Size(1106, 734); 224 243 this.instancesTabPage.TabIndex = 0; 225 244 this.instancesTabPage.Text = "Instances"; … … 235 254 this.problemInstancesView.Name = "problemInstancesView"; 236 255 this.problemInstancesView.ReadOnly = false; 237 this.problemInstancesView.Size = new System.Drawing.Size( 986, 728);256 this.problemInstancesView.Size = new System.Drawing.Size(1100, 728); 238 257 this.problemInstancesView.TabIndex = 0; 239 258 this.problemInstancesView.ViewsLabelVisible = true; 240 259 this.problemInstancesView.ViewType = null; 260 // 261 // colorComboBox 262 // 263 this.colorComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 264 this.colorComboBox.FormattingEnabled = true; 265 this.colorComboBox.Location = new System.Drawing.Point(768, 6); 266 this.colorComboBox.Name = "colorComboBox"; 267 this.colorComboBox.Size = new System.Drawing.Size(222, 21); 268 this.colorComboBox.TabIndex = 13; 269 this.colorComboBox.SelectedIndexChanged += new System.EventHandler(this.colorComboBox_SelectedIndexChanged); 270 // 271 // colorLabel 272 // 273 this.colorLabel.AutoSize = true; 274 this.colorLabel.Location = new System.Drawing.Point(728, 9); 275 this.colorLabel.Name = "colorLabel"; 276 this.colorLabel.Size = new System.Drawing.Size(34, 13); 277 this.colorLabel.TabIndex = 15; 278 this.colorLabel.Text = "Color:"; 241 279 // 242 280 // UnderstandingProblemInstanceView … … 246 284 this.Controls.Add(this.problemInstancesTabControl); 247 285 this.Name = "UnderstandingProblemInstanceView"; 248 this.Size = new System.Drawing.Size(1 000, 760);286 this.Size = new System.Drawing.Size(1108, 760); 249 287 this.problemInstancesTabControl.ResumeLayout(false); 250 288 this.mapTabPage.ResumeLayout(false); … … 273 311 private System.Windows.Forms.ComboBox sizeComboBox; 274 312 private System.Windows.Forms.ComboBox projectionComboBox; 313 private System.Windows.Forms.CheckBox fromZeroCheckBox; 314 private System.Windows.Forms.Label colorLabel; 315 private System.Windows.Forms.ComboBox colorComboBox; 275 316 } 276 317 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/Views/UnderstandingProblemInstanceView.cs
r13752 r13757 28 28 using System; 29 29 using System.Collections.Generic; 30 using System.Drawing; 30 31 using System.Linq; 31 32 using System.Text.RegularExpressions; … … 62 63 UpdateProjectionComboBox(); 63 64 UpdateSizeComboBox(); 65 UpdateColorComboBox(); 64 66 } 65 67 } … … 76 78 UpdateProjectionComboBox(); 77 79 UpdateSizeComboBox(); 80 UpdateColorComboBox(); 78 81 UpdateProjection(); 79 82 } … … 108 111 } finally { SuppressEvents = false; } 109 112 } 113 114 private void UpdateColorComboBox() { 115 try { 116 SuppressEvents = true; 117 var selected = colorComboBox.SelectedIndex >= 0 ? (string)colorComboBox.SelectedItem : null; 118 colorComboBox.Items.Clear(); 119 colorComboBox.Items.Add(string.Empty); 120 foreach (var str in Content.ProblemInstances.ResultNames.Where(x => x.StartsWith("Rank."))) { 121 colorComboBox.Items.Add(str); 122 if (selected == str) colorComboBox.SelectedItem = str; 123 } 124 if (selected == null && colorComboBox.Items.Count > 0) 125 colorComboBox.SelectedIndex = 0; 126 } finally { SuppressEvents = false; } 127 } 110 128 111 129 private IEnumerable<string> GetProjections() { … … 130 148 var projection = (string)projectionComboBox.SelectedItem; 131 149 var size = sizeComboBox.SelectedIndex >= 0 ? (string)sizeComboBox.SelectedItem : string.Empty; 132 133 DoProjectProblemInstances(instancesSeries, currentInstanceSeries, projection, size, invPropCheckBox.Checked); 134 } 135 136 private void DoProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection, string size, bool invProp) { 150 var color = colorComboBox.SelectedIndex >= 0 ? (string)colorComboBox.SelectedItem : string.Empty; 151 152 DoProjectProblemInstances(instancesSeries, currentInstanceSeries, projection, 153 size, color, invPropCheckBox.Checked, fromZeroCheckBox.Checked); 154 } 155 156 private void DoProjectProblemInstances(Series instancesSeries, Series currentInstanceSeries, string projection, string size, string color, bool invProp, bool fromZero) { 137 157 instancesSeries.Points.Clear(); 138 158 currentInstanceSeries.Points.Clear(); … … 143 163 if (sizes.Count > 0) { 144 164 maxSize = sizes.Max(x => x.Value); 145 minSize = sizes.Min(x => x.Value); 165 if (maxSize < 0 && fromZero) { 166 maxSize = 0; 167 minSize = sizes.Min(x => x.Value); 168 } else if (fromZero) { 169 minSize = 0; 170 } else { 171 minSize = sizes.Min(x => x.Value); 172 } 146 173 } 147 174 } … … 159 186 if (maxSize > minSize && run.Results.TryGetValue(size, out item)) { 160 187 var dItem = item as Data.DoubleValue; 188 if (dItem == null && item is IntValue) dItem = new DoubleValue(((IntValue)item).Value); 161 189 if (dItem != null) { 162 190 if (double.IsNaN(dItem.Value)) … … 171 199 } else dataPoint.MarkerSize = 1; 172 200 201 if (!string.IsNullOrEmpty(color)) { 202 if (run.Results.TryGetValue(color, out item)) { 203 var v = (int)(item is DoubleValue ? ((DoubleValue)item).Value : (item is IntValue ? ((IntValue)item).Value : int.MaxValue)); 204 switch (v) { 205 case 0: dataPoint.MarkerColor = Color.Green; break; 206 case 1: dataPoint.MarkerColor = Color.LightSeaGreen; break; 207 case 2: dataPoint.MarkerColor = Color.CornflowerBlue; break; 208 case 3: dataPoint.MarkerColor = Color.PaleVioletRed; break; 209 case 4: dataPoint.MarkerColor = Color.IndianRed; break; 210 default: dataPoint.MarkerColor = Color.LightGray; break; 211 } 212 } 213 } 173 214 if (Content.IsCurrentInstance(run)) currentInstanceSeries.Points.Add(dataPoint); 174 215 else instancesSeries.Points.Add(dataPoint); … … 185 226 } 186 227 228 private void colorComboBox_SelectedIndexChanged(object sender, EventArgs e) { 229 UpdateProjection(); 230 } 231 187 232 private void InvPropCheckBoxOnCheckedChanged(object sender, EventArgs e) { 233 UpdateProjection(); 234 } 235 236 private void fromZeroCheckBox_CheckedChanged(object sender, EventArgs e) { 188 237 UpdateProjection(); 189 238 }
Note: See TracChangeset
for help on using the changeset viewer.