Changeset 15718 for branches/1614_GeneralizedQAP
- Timestamp:
- 02/04/18 21:06:14 (7 years ago)
- Location:
- branches/1614_GeneralizedQAP
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/DoubleMatrixCharacteristicCalculator.cs
r14678 r15718 20 20 #endregion 21 21 22 using System; 23 using System.Linq; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Data; 24 using System;25 using System.Linq;26 26 27 27 namespace HeuristicLab.Analysis.FitnessLandscape { … … 30 30 var avg = m.Average(); 31 31 var stdDev = m.StandardDeviation(); 32 return stdDev / avg; 33 } 34 35 public static double CoeffVariationNonZeroes(DoubleMatrix m) { 36 var nonzeroes = m.Where(x => !x.IsAlmost(0)); 37 var avg = nonzeroes.Average(); 38 var stdDev = nonzeroes.StandardDeviation(); 32 39 return stdDev / avg; 33 40 } -
branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/GQAP/GQAPCharacteristicCalculator.cs
r15713 r15718 66 66 yield return new Result(chara, new DoubleValue(inst.Capacities.Length / (double)inst.Demands.Length)); 67 67 if (chara == "FlowDominance") 68 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation (inst.Weights)));68 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariationNonZeroes(inst.Weights))); 69 69 if (chara == "DistanceDominance") 70 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation (inst.Distances)));70 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariationNonZeroes(inst.Distances))); 71 71 if (chara == "FlowSparsity") 72 72 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(inst.Weights))); -
branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/GQAP/GQAPDirectedWalk.cs
r15713 r15718 134 134 public static IEnumerable<List<Tuple<IntegerVector, double>>> Run(IRandom random, GQAP gqap, IEnumerable<IntegerVector> points, bool bestImprovement = true) { 135 135 var iter = points.GetEnumerator(); 136 if (!iter.MoveNext()) yield break;136 if (!iter.MoveNext()) return new List<Tuple<IntegerVector, double>>[0]; 137 137 138 138 var start = iter.Current; 139 var walks = new List<List<Tuple<IntegerVector, double>>>(); 139 140 while (iter.MoveNext()) { 140 141 var end = iter.Current; 141 142 142 143 var walk = (bestImprovement ? BestDirectedWalk(gqap, start, end) : FirstDirectedWalk(random, gqap, start, end)).ToList(); 143 yield return walk.ToList();144 walks.Add(walk); 144 145 start = end; 145 146 } // end paths 147 148 var min = walks.SelectMany(x => x.Select(y => y.Item2)).Min(); 149 var max = walks.SelectMany(x => x.Select(y => y.Item2)).Max(); 150 151 if (min == max) max = min + 1; 152 return walks.Select(w => w.Select(x => Tuple.Create(x.Item1, (x.Item2 - min) / (max - min))).ToList()); 146 153 } 147 154 -
branches/1614_GeneralizedQAP/HeuristicLab.Optimization.Views/3.3/RunCollectionViews/RunCollectionRLDView.cs
r15713 r15718 31 31 using HeuristicLab.Analysis; 32 32 using HeuristicLab.Collections; 33 using HeuristicLab.Common; 33 34 using HeuristicLab.Core; 34 35 using HeuristicLab.Core.Views; … … 146 147 return; 147 148 } 149 if (updateInProgress) return; 148 150 try { 149 151 updateInProgress = true; 150 UpdateGroupAndProblemComboBox(); 151 UpdateDataTableComboBox(); 152 UpdateComboBoxes(); 152 153 GroupRuns(); 153 154 } finally { updateInProgress = false; } … … 160 161 return; 161 162 } 163 if (updateInProgress) return; 162 164 try { 163 165 updateInProgress = true; 164 UpdateGroupAndProblemComboBox(); 165 UpdateDataTableComboBox(); 166 UpdateComboBoxes(); 166 167 GroupRuns(); 167 168 } finally { updateInProgress = false; } … … 175 176 return; 176 177 } 178 if (updateInProgress) return; 177 179 try { 178 180 updateInProgress = true; 179 UpdateGroupAndProblemComboBox(); 180 UpdateDataTableComboBox(); 181 UpdateComboBoxes(); 181 182 GroupRuns(); 182 183 } finally { updateInProgress = false; } … … 194 195 suppressContentEvents = Content.UpdateOfRunsInProgress; 195 196 if (!suppressContentEvents) { 197 if (updateInProgress) return; 196 198 try { 197 199 updateInProgress = true; 198 UpdateGroupAndProblemComboBox(); 199 UpdateDataTableComboBox(); 200 UpdateComboBoxes(); 200 201 GroupRuns(); 201 202 } finally { updateInProgress = false; } … … 215 216 } else { 216 217 if (e.PropertyName == "Visible") { 218 if (updateInProgress) return; 217 219 try { 218 220 updateInProgress = true; … … 238 240 try { 239 241 updateInProgress = true; 240 UpdateGroupAndProblemComboBox(); 241 UpdateDataTableComboBox(); 242 UpdateComboBoxes(); 242 243 UpdateRuns(); 243 244 } finally { updateInProgress = false; } … … 246 247 247 248 248 private void Update GroupAndProblemComboBox() {249 private void UpdateComboBoxes() { 249 250 var selectedGroupItem = (string)groupComboBox.SelectedItem; 250 251 … … 259 260 } 260 261 262 string selectedDataTable = (string)dataTableComboBox.SelectedItem; 263 264 dataTableComboBox.Items.Clear(); 265 var dataTables = (from run in Content 266 from result in run.Results 267 where result.Value is IndexedDataTable<double> 268 select result.Key).Distinct().ToArray(); 269 270 dataTableComboBox.Items.AddRange(dataTables); 271 if (selectedDataTable != null && dataTableComboBox.Items.Contains(selectedDataTable)) { 272 dataTableComboBox.SelectedItem = selectedDataTable; 273 } else if (dataTableComboBox.Items.Count > 0) { 274 dataTableComboBox.SelectedItem = dataTableComboBox.Items[0]; 275 } 276 261 277 var selectedProblemItem = (ProblemInstance)problemComboBox.SelectedItem; 262 278 … … 271 287 272 288 SetEnabledStateOfControls(); 273 }274 275 private void UpdateDataTableComboBox() {276 string selectedItem = (string)dataTableComboBox.SelectedItem;277 278 dataTableComboBox.Items.Clear();279 var dataTables = (from run in Content280 from result in run.Results281 where result.Value is IndexedDataTable<double>282 select result.Key).Distinct().ToArray();283 284 dataTableComboBox.Items.AddRange(dataTables);285 if (selectedItem != null && dataTableComboBox.Items.Contains(selectedItem)) {286 dataTableComboBox.SelectedItem = selectedItem;287 } else if (dataTableComboBox.Items.Count > 0) {288 dataTableComboBox.SelectedItem = dataTableComboBox.Items[0];289 }290 291 UpdateProblemInstances();292 289 } 293 290 … … 318 315 && r.Visible 319 316 && selectedProblem.Match(r) 320 && r.Results.ContainsKey(table) 321 && r.Results[table] is IndexedDataTable<double> 322 let key = selectedGroup == AllInstances ? AllInstances : r.Parameters[selectedGroup].ToString() 317 let key = selectedGroup == AllInstances 318 ? AllInstances : r.Parameters[selectedGroup].ToString() 323 319 group r by key into g 324 320 select g) { 325 var trials = from run in alg 326 from pd in problems 327 where pd.Equals(new ProblemInstance(run)) 328 let cgraph = ((IndexedDataTable<double>)run.Results[table]) 329 where cgraph.Rows.Count > 0 && cgraph.Rows.First().Values.Count > 0 321 var trials = (from run in alg 322 from pd in problems.Skip(1) // exclude artificial match all 323 where pd.Match(run) && run.Results.ContainsKey(table) 324 let cgraph = run.Results[table] as IndexedDataTable<double> 325 where cgraph != null && cgraph.Rows.Count > 0 326 && cgraph.Rows.First().Values.Count > 0 330 327 group cgraph by pd into g 331 select g; 332 328 select g).ToList(); 329 330 if (trials.Count == 0) continue; 333 331 groups.Add(new AlgorithmInstance(alg.Key, trials)); 334 332 } … … 339 337 problems.Clear(); 340 338 var table = (string)dataTableComboBox.SelectedItem; 341 if (string.IsNullOrEmpty(table)) return; 342 339 343 340 var problemDict = CalculateBestTargetPerProblemInstance(table); 344 341 … … 350 347 351 348 problems.Add(ProblemInstance.MatchAll); 352 foreach (var p in problemDict. ToList()) {349 foreach (var p in problemDict.OrderBy(x => x.Key.ProblemName, new NaturalStringComparer()).ToList()) { 353 350 p.Key.BestKnownQuality = p.Value; 354 351 p.Key.DisplayProblemType = problemTypesDifferent; … … 394 391 misses[alg.Name] = epdfMisses = new SortedList<double, int>(); 395 392 } 396 foreach (var problem in alg.GetCases() ) {397 var max = problem. IsMaximization();393 foreach (var problem in alg.GetCases().Where(x => x.Maximization.HasValue)) { 394 var max = problem.Maximization.Value; 398 395 var absTargets = GetAbsoluteTargets(problem).ToArray(); 399 396 foreach (var run in alg.GetTrials(problem)) { … … 450 447 foreach (var list in hits) { 451 448 var row = new Series(list.Key) { 452 ChartType = SeriesChartType.StepLine,449 ChartType = list.Value.Count > 1000 ? SeriesChartType.FastLine : SeriesChartType.StepLine, 453 450 BorderWidth = 3, 454 451 Color = colors[colorCount], … … 603 600 private IEnumerable<double> GetAbsoluteTargets(ProblemInstance pInstance) { 604 601 if (!targetsAreRelative) return targets; 605 606 var maximization = pInstance.IsMaximization(); 602 if (!pInstance.Maximization.HasValue) throw new ArgumentException("Problem doesn't specify if it is to be maximized or minimized."); 603 604 var maximization = pInstance.Maximization.Value; 607 605 var bestKnown = pInstance.BestKnownQuality; 608 606 if (double.IsNaN(bestKnown)) throw new ArgumentException("Problem instance does not have a defined best - known quality."); … … 621 619 private double[] GetAbsoluteTargetsWorstToBest(ProblemInstance pInstance) { 622 620 if (targetsAreRelative && double.IsNaN(pInstance.BestKnownQuality)) throw new ArgumentException("Problem instance does not have a defined best-known quality."); 621 if (!pInstance.Maximization.HasValue) throw new ArgumentException("Problem doesn't specify if it is to be maximized or minimized."); 623 622 var absTargets = GetAbsoluteTargets(pInstance); 624 return (pInstance. IsMaximization()623 return (pInstance.Maximization.Value 625 624 ? absTargets.OrderBy(x => x) : absTargets.OrderByDescending(x => x)).ToArray(); 626 625 } … … 663 662 var problems = groups.SelectMany(x => x.GetCases()).Distinct().ToList(); 664 663 665 foreach (var problem in problems ) {666 if (double.IsNaN(problem.BestKnownQuality) ) continue;664 foreach (var problem in problems.OrderBy(x => x.ProblemName, new NaturalStringComparer())) { 665 if (double.IsNaN(problem.BestKnownQuality) || !problem.Maximization.HasValue) continue; 667 666 rowNames.Add(problem.ToString()); 668 var max = problem. IsMaximization();667 var max = problem.Maximization.Value; 669 668 var absTargets = GetAbsoluteTargetsWorstToBest(problem); 670 669 if (targetsAreRelative) { … … 776 775 777 776 private void CalculateHitsForEachBudget(Dictionary<string, SortedList<double, double>> hits, ConvergenceGraph cgraph, ProblemInstance problem, string groupName) { 778 var max = problem. IsMaximization();777 var max = problem.Maximization.Value; 779 778 var prevIndex = 0; 780 779 foreach (var b in budgets) { … … 897 896 updateInProgress = true; 898 897 var pd = (ProblemInstance)problemComboBox.SelectedItem; 899 if (!double.IsNaN(pd.BestKnownQuality) ) {900 var max = pd. IsMaximization();898 if (!double.IsNaN(pd.BestKnownQuality) && pd.Maximization.HasValue) { 899 var max = pd.Maximization.Value; 901 900 if (targetsAreRelative) targets = GetAbsoluteTargets(pd).ToArray(); 902 901 else { … … 957 956 var values = resultsTable.Rows.First().Values; 958 957 var pd = new ProblemInstance(run); 958 if (!pd.Maximization.HasValue) continue; 959 959 pd = problems.Single(x => x.Equals(pd)); 960 960 if (targetsAreRelative && double.IsNaN(pd.BestKnownQuality)) continue; 961 961 962 var max = pd. IsMaximization();962 var max = pd.Maximization.Value; 963 963 var absTargets = GetAbsoluteTargetsWorstToBest(pd); 964 964 var cgraph = new ConvergenceGraph(resultsTable, max); … … 1071 1071 var values = resultsTable.Rows.First().Values; 1072 1072 var pd = new ProblemInstance(run); 1073 if (!pd.Maximization.HasValue) continue; 1073 1074 pd = problems.Single(x => x.Equals(pd)); 1074 var max = pd. IsMaximization();1075 var max = pd.Maximization.Value; 1075 1076 var cgraph = new ConvergenceGraph(resultsTable, max); 1076 1077 var prevIndex = 0; … … 1082 1083 } 1083 1084 var v = values[index]; 1084 var tgt = targetsAreRelative ? CalculateRelativeDifference( pd.IsMaximization(), pd.BestKnownQuality, v.Item2) : v.Item2;1085 var tgt = targetsAreRelative ? CalculateRelativeDifference(max, pd.BestKnownQuality, v.Item2) : v.Item2; 1085 1086 run.Results[table + (targetsAreRelative ? ".CostForRelTarget " : ".CostForAbsTarget ") + b] = new DoubleValue(tgt); 1086 1087 prevIndex = index; … … 1109 1110 var dict = new Dictionary<ProblemInstance, double>(); 1110 1111 foreach (var k in from r in Content where r.Visible let pd = new ProblemInstance(r) group r by pd into g select new { Problem = g.Key, Runs = g.ToList() }) { 1111 var pd = new ProblemInstance(k.Runs[0]); 1112 var pd = k.Problem; 1113 if (!pd.Maximization.HasValue) continue; 1112 1114 var values = GetQualityValues(k.Runs, table).ToList(); 1113 1115 var target = double.NaN; 1114 1116 if (values.Count > 0) { 1115 target = pd. IsMaximization()? values.Max() : values.Min();1117 target = pd.Maximization.Value ? values.Max() : values.Min(); 1116 1118 } 1117 1119 dict[pd] = target; … … 1133 1135 var last = dt.Rows.First().Values.Last().Item2; 1134 1136 if (!double.IsNaN(last)) 1135 yield return last;1137 yield return Math.Round(last, 10); 1136 1138 } 1137 1139 } … … 1296 1298 performanceData = new Dictionary<ProblemInstance, List<ConvergenceGraph>>(); 1297 1299 foreach (var t in trials) { 1298 if (double.IsNaN(t.Key.BestKnownQuality)) continue; 1299 var max = t.Key.IsMaximization(); 1300 performanceData[t.Key] = t.Select(c => new ConvergenceGraph(c, max)).ToList(); 1300 if (double.IsNaN(t.Key.BestKnownQuality) || !t.Key.Maximization.HasValue) continue; 1301 performanceData[t.Key] = t.Select(c => new ConvergenceGraph(c, t.Key.Maximization.Value)).ToList(); 1301 1302 } 1302 1303 } … … 1329 1330 ProblemName = string.Empty; 1330 1331 Evaluator = string.Empty; 1331 Maximization = string.Empty;1332 Maximization = null; 1332 1333 DisplayProblemType = false; 1333 1334 DisplayProblemName = false; … … 1342 1343 ProblemName = GetStringValueOrEmpty(run, "Problem Name"); 1343 1344 Evaluator = GetStringValueOrEmpty(run, "Evaluator"); 1344 Maximization = Get MaximizationValueOrEmpty(run, "Maximization");1345 Maximization = GetBoolValueOrEmpty(run, "Maximization"); 1345 1346 DisplayProblemType = !string.IsNullOrEmpty(ProblemType); 1346 1347 DisplayProblemName = !string.IsNullOrEmpty(ProblemName); 1347 1348 DisplayEvaluator = !string.IsNullOrEmpty(Evaluator); 1348 DisplayMaximization = !string.IsNullOrEmpty(Maximization);1349 DisplayMaximization = Maximization.HasValue; 1349 1350 matchAll = false; 1350 1351 BestKnownQuality = GetDoubleValueOrNaN(run, "BestKnownQuality"); … … 1414 1415 } 1415 1416 } 1416 private stringmaximization;1417 public stringMaximization {1417 private bool? maximization; 1418 public bool? Maximization { 1418 1419 get { return maximization; } 1419 1420 set { … … 1433 1434 } 1434 1435 1435 public bool IsMaximization() {1436 return Maximization == "MAX";1437 }1438 1439 1436 public bool Match(IRun run) { 1440 1437 return matchAll || 1441 GetStringValueOrEmpty(run, "Problem Type") == ProblemType1438 (GetStringValueOrEmpty(run, "Problem Type") == ProblemType 1442 1439 && GetStringValueOrEmpty(run, "Problem Name") == ProblemName 1443 1440 && GetStringValueOrEmpty(run, "Evaluator") == Evaluator 1444 && Get MaximizationValueOrEmpty(run, "Maximization") == Maximization;1441 && GetBoolValueOrEmpty(run, "Maximization") == Maximization); 1445 1442 } 1446 1443 … … 1463 1460 } 1464 1461 1465 private string GetMaximizationValueOrEmpty(IRun run, string key) {1462 private bool? GetBoolValueOrEmpty(IRun run, string key) { 1466 1463 IItem param; 1467 1464 if (run.Parameters.TryGetValue(key, out param)) { 1468 1465 var bv = param as BoolValue; 1469 return bv != null ? (bv.Value ? "MAX" : "MIN") : string.Empty;1470 } 1471 return string.Empty;1466 if (bv != null) return bv.Value; 1467 } 1468 return null; 1472 1469 } 1473 1470 … … 1490 1487 (DisplayProblemName ? ProblemName : string.Empty), 1491 1488 (DisplayEvaluator ? Evaluator : string.Empty), 1492 (DisplayMaximization ? Maximization: string.Empty),1489 (DisplayMaximization && Maximization.HasValue ? (Maximization.Value ? "MAX" : "MIN") : string.Empty), 1493 1490 !double.IsNaN(BestKnownQuality) ? BestKnownQuality.ToString(CultureInfo.CurrentCulture.NumberFormat) : string.Empty }.Where(x => !string.IsNullOrEmpty(x))); 1494 1491 } -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/CPLEX/CplexSolver.cs
r15713 r15718 63 63 cplex.Use(new LogCallback(this, cancellationToken)); 64 64 cplex.SetParam(Cplex.DoubleParam.TiLim, MaximumRuntime.TotalSeconds); 65 cplex.SetParam(Cplex.IntParam.Threads, 1); 65 66 var dataSource = new GQAPDataSource(factory, Problem.ProblemInstance); 66 67 using (var settings = factory.CreateOplSettings(factory.CreateOplErrorHandler())) -
branches/1614_GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/Infrastructure/Algorithms/ContextAlgorithm.cs
r15704 r15718 205 205 firstHitGraph.Values[firstHitGraph.Values.Count - 1] = Tuple.Create(elapsed.TotalSeconds, Context.BestQuality); 206 206 } 207 context = null; 207 208 // base call must be done last as the results will be cloned and a run is created 208 209 base.OnStopped();
Note: See TracChangeset
for help on using the changeset viewer.