Changeset 16140 for branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems
- Timestamp:
- 09/14/18 11:36:59 (6 years ago)
- Location:
- branches/2817-BinPackingSpeedup
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2817-BinPackingSpeedup
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views
- Property svn:mergeinfo changed
-
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ChangeDataOfOptimizersMenuItem.cs
r14805 r16140 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-201 4Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/CreateEnsembleMenuItem.cs
r14185 r16140 1 1 #region License Information 2 2 /* HeuristicLab 3 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)3 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 4 4 * 5 5 * This file is part of HeuristicLab. -
branches/2817-BinPackingSpeedup/HeuristicLab.Problems.DataAnalysis.Views/3.4/MenuItems/ShrinkDataAnalysisRunsMenuItem.cs
r14185 r16140 2 2 3 3 /* HeuristicLab 4 * Copyright (C) 2002-201 6Heuristic and Evolutionary Algorithms Laboratory (HEAL)4 * Copyright (C) 2002-2018 Heuristic and Evolutionary Algorithms Laboratory (HEAL) 5 5 * 6 6 * This file is part of HeuristicLab. … … 23 23 24 24 using System; 25 using System.Collections;26 25 using System.Collections.Generic; 27 26 using System.Linq; 28 using System.Linq.Expressions;29 using HeuristicLab.Common;30 27 using HeuristicLab.MainForm; 31 28 using HeuristicLab.Optimization; … … 33 30 34 31 using MenuItem = HeuristicLab.MainForm.WindowsForms.MenuItem; 35 using ValuesType = System.Collections.Generic.Dictionary<string, System.Collections.IList>;36 32 37 33 namespace HeuristicLab.Problems.DataAnalysis.Views { … … 79 75 mainForm.AddOperationProgressToContent(activeView.Content, "Removing duplicate datasets."); 80 76 81 Action<IContentView> action = (view) => { 82 var variableValuesMapping = new Dictionary<ValuesType, ValuesType>(); 83 foreach (var problemData in view.Content.GetObjectGraphObjects(excludeStaticMembers: true).OfType<IDataAnalysisProblemData>()) { 84 var dataset = problemData.Dataset as Dataset; 85 if (dataset == null) continue; 86 var originalValues = variableValuesGetter(dataset); 87 var matchingValues = GetEqualValues(originalValues, variableValuesMapping); 88 variableValuesSetter(dataset, matchingValues); 89 } 90 }; 77 Action<IContentView> action = (view) => DatasetUtil.RemoveDuplicateDatasets(view.Content); 91 78 92 action.BeginInvoke(activeView, delegate (IAsyncResult result) {79 action.BeginInvoke(activeView, delegate (IAsyncResult result) { 93 80 action.EndInvoke(result); 94 81 mainForm.RemoveOperationProgressFromContent(activeView.Content); 95 82 }, null); 96 83 } 97 98 private static ValuesType GetEqualValues(ValuesType originalValues, Dictionary<ValuesType, ValuesType> variableValuesMapping) {99 if (variableValuesMapping.ContainsKey(originalValues)) return variableValuesMapping[originalValues];100 101 var matchingValues = variableValuesMapping.FirstOrDefault(kv => kv.Key == kv.Value && EqualVariableValues(originalValues, kv.Key)).Key ?? originalValues;102 variableValuesMapping[originalValues] = matchingValues;103 return matchingValues;104 }105 106 private static bool EqualVariableValues(ValuesType values1, ValuesType values2) {107 //compare variable names for equality108 if (!values1.Keys.SequenceEqual(values2.Keys)) return false;109 foreach (var key in values1.Keys) {110 var v1 = values1[key];111 var v2 = values2[key];112 if (v1.Count != v2.Count) return false;113 for (int i = 0; i < v1.Count; i++) {114 if (!v1[i].Equals(v2[i])) return false;115 }116 }117 return true;118 }119 120 private static readonly Action<Dataset, Dictionary<string, IList>> variableValuesSetter;121 private static readonly Func<Dataset, Dictionary<string, IList>> variableValuesGetter;122 /// <summary>123 /// The static initializer is used to create expressions for getting and setting the private variableValues field in the dataset.124 /// This is done by expressions because the field is private and compiled expression calls are much faster compared to standad reflection calls.125 /// </summary>126 static ShrinkDataAnalysisRunsMenuItem() {127 var dataset = Expression.Parameter(typeof(Dataset));128 var variableValues = Expression.Parameter(typeof(ValuesType));129 var valuesExpression = Expression.Field(dataset, "variableValues");130 var assignExpression = Expression.Assign(valuesExpression, variableValues);131 132 var variableValuesSetExpression = Expression.Lambda<Action<Dataset, ValuesType>>(assignExpression, dataset, variableValues);133 variableValuesSetter = variableValuesSetExpression.Compile();134 135 var variableValuesGetExpression = Expression.Lambda<Func<Dataset, ValuesType>>(valuesExpression, dataset);136 variableValuesGetter = variableValuesGetExpression.Compile();137 }138 84 } 139 85 }
Note: See TracChangeset
for help on using the changeset viewer.