Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationUtil.cs @ 5740

Last change on this file since 5740 was 5359, checked in by cneumuel, 14 years ago

#1215

  • renamed RunsAnalyzer to SolutionCacheAnalyzer
  • only most recent results will stay in cache to avoid memory problems
  • some minor tweaks and bugfixes
File size: 2.2 KB
Line 
1using System;
2using System.Linq;
3using System.Threading;
4using HeuristicLab.Common;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7using HeuristicLab.Operators;
8using HeuristicLab.Optimization;
9using HeuristicLab.Parameters;
10using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
11using System.Collections.Generic;
12using HeuristicLab.Algorithms.GeneticAlgorithm;
13using System.Threading.Tasks;
14using System.Diagnostics;
15using System.Reflection;
16
17namespace HeuristicLab.Problems.MetaOptimization {
18  public static class MetaOptimizationUtil {
19    /// <summary>
20    /// Removes those results from the run which are not declared in resultsToKeep
21    /// </summary>
22    public static void ClearResults(IRun run, IEnumerable<string> resultsToKeep) {
23      var resultsToRemove = new List<string>();
24      foreach (var result in run.Results) {
25        if (!resultsToKeep.Contains(result.Key))
26          resultsToRemove.Add(result.Key);
27      }
28      foreach (var result in resultsToRemove)
29        run.Results.Remove(result);
30    }
31
32    /// <summary>
33    /// Removes those parameters from the run which are not declared in parametersToKeep
34    /// </summary>
35    public static void ClearParameters(IRun run, IEnumerable<string> parametersToKeep) {
36      var parametersToRemove = new List<string>();
37      foreach (var parameter in run.Parameters) {
38        if (!parametersToKeep.Contains(parameter.Key))
39          parametersToRemove.Add(parameter.Key);
40      }
41      foreach (var parameter in parametersToRemove)
42        run.Parameters.Remove(parameter);
43    }
44
45    public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] referenceQualities) {
46      double[] qualitiesNormalized = new double[referenceQualities.Length];
47      for (int i = 0; i < referenceQualities.Length; i++) {
48        qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / referenceQualities[i];
49      }
50      parameterConfigurationTree.QualitiesNormalized = new DoubleArray(qualitiesNormalized);
51      parameterConfigurationTree.AverageQualityNormalized = new DoubleValue(qualitiesNormalized.Average());
52      return parameterConfigurationTree.AverageQualityNormalized.Value;
53    }
54  }
55}
Note: See TracBrowser for help on using the repository browser.