Free cookie consent management tool by TermsFeed Policy Generator

Changeset 6018


Ignore:
Timestamp:
04/17/11 18:22:28 (12 years ago)
Author:
cneumuel
Message:

#1215

  • support for maximization problems
  • made base level algorithms stoppable
  • optimization for multiple goals possible (AverageQuality, AverageDeviation, AverageEvaluatedSolutions)
  • lots of fixes
Location:
branches/HeuristicLab.MetaOptimization
Files:
15 edited

Legend:

Unmodified
Added
Removed
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.MetaOptimization.Test/Program.cs

    r6017 r6018  
    4747    //private static int baseAlgorithmMaxGenerations = 1000;
    4848
    49     private static int metaAlgorithmPopulationSize = 20;
    50     private static int metaAlgorithmMaxGenerations = 20;
    51     private static int metaProblemRepetitions = 3;
    52     private static int baseAlgorithmMaxGenerations = 100;
     49    private static int metaAlgorithmPopulationSize = 10;
     50    private static int metaAlgorithmMaxGenerations = 10;
     51    private static int metaProblemRepetitions = 2;
     52    private static int baseAlgorithmMaxGenerations = 10;
    5353    private static double mutationProbability = 0.10;
    5454
     
    8080      MetaOptimizationProblem metaOptimizationProblem = new MetaOptimizationProblem();
    8181      metaOptimizationProblem.Repetitions = new IntValue(metaProblemRepetitions);
    82       //GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
    83       GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
     82      GeneticAlgorithm metaLevelAlgorithm = GetMetaGA(metaOptimizationProblem);
     83      //GeneticAlgorithm metaLevelAlgorithm = GetParallelMetaGA(metaOptimizationProblem);
    8484      //GeneticAlgorithm metaLevelAlgorithm = GetHiveParallelMetaGA(metaOptimizationProblem);
    8585
     
    8888      var algorithmVc = SetupGAAlgorithm(typeof(GeneticAlgorithm), metaOptimizationProblem);
    8989
    90       //TestToString(algorithmVc);
    91 
     90      string info = algorithmVc.ParameterInfoString;
    9291
    9392      //Console.WriteLine("Press enter to start");
     
    116115
    117116      var vc1 = new SymbolicExpressionGrammarValueConfiguration(grammar1);
     117
     118      string info = vc1.ParameterInfoString;
     119
    118120      ConfigureSymbolicExpressionGrammarVc(vc1);
     121
     122      info = vc1.ParameterInfoString;
     123
     124
    119125      var vc2 = new SymbolicExpressionGrammarValueConfiguration(grammar2);
    120126      ConfigureSymbolicExpressionGrammarVc(vc2);
     
    758764          && pc.Name != "StartSymbol") {
    759765          pc.Optimize = true;
    760           var initialFrequencyVc = ((ParameterizedValueConfiguration)pc.ValueConfigurations.First()).ParameterConfigurations.Single(x => x.Name == "InitialFrequency");
    761           initialFrequencyVc.Optimize = true;
    762766        }
    763767      }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/AlgorithmExecutor.cs

    r5653 r6018  
    1010      executor.StartSync();
    1111    }
     12    public static void StartSync(this IAlgorithm algorithm, CancellationToken cancellationToken) {
     13      var executor = new AlgorithmExecutor(algorithm, cancellationToken);
     14      executor.StartSync();
     15    }
    1216  }
    1317
     
    1822    private IAlgorithm algorithm;
    1923    private AutoResetEvent waitHandle = new AutoResetEvent(false);
     24    private CancellationToken cancellationToken;
     25    private bool useCancellationToken = false;
    2026
    2127    public AlgorithmExecutor(IAlgorithm algorithm) {
     
    2329    }
    2430
     31    public AlgorithmExecutor(IAlgorithm algorithm, CancellationToken cancellationToken) {
     32      this.algorithm = algorithm;
     33      this.cancellationToken = cancellationToken;
     34      this.useCancellationToken = true;
     35    }
     36
    2537    public void StartSync() {
    2638      algorithm.Stopped += new EventHandler(algorithm_Stopped);
    2739      algorithm.Paused += new EventHandler(algorithm_Paused);
    28       algorithm.Start();
     40     
     41      if(useCancellationToken && algorithm is EngineAlgorithm && ((EngineAlgorithm)algorithm).Engine is SequentialEngine.SequentialEngine) {
     42        ((SequentialEngine.SequentialEngine)((EngineAlgorithm)algorithm).Engine).Start(cancellationToken);
     43      } else {
     44        algorithm.Start();
     45      }
     46
    2947      waitHandle.WaitOne();
    3048      waitHandle.Dispose();
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/BestParameterConfigurationAnalyzer.cs

    r5576 r6018  
    77using HeuristicLab.Parameters;
    88using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9 using System.Collections.Generic;
    10 using System;
    119
    1210namespace HeuristicLab.Problems.MetaOptimization {
     
    3937      get { return (LookupParameter<RunCollection>)Parameters["Population"]; }
    4038    }
    41     public LookupParameter<DoubleArray> ProblemQualityReferencesParameter {
    42       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
    43     }
    4439    public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter {
    4540      get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
     41    }
     42    public LookupParameter<BoolValue> MaximizationParameter {
     43      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
    4644    }
    4745
     
    5553      Parameters.Add(new LookupParameter<IRun>("BestKnownSolution", ""));
    5654      Parameters.Add(new LookupParameter<RunCollection>("Population", ""));
    57       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
    5855      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName));
     56      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
    5957    }
    6058
     
    7169      DoubleValue bestKnownQuality = BestKnownQualityParameter.ActualValue;
    7270      ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue;
     71      bool maximization = MaximizationParameter.ActualValue.Value;
    7372
    74       int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     73      int idxBest;
     74      if (maximization)
     75        idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index;
     76      else
     77        idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
    7578
    7679      ParameterConfigurationTree best = (ParameterConfigurationTree)parameterTrees[idxBest];
     
    7982      best.CollectParameterValues(bestRun.Parameters);
    8083
    81       if (bestKnownQuality == null || qualities[idxBest].Value < bestKnownQuality.Value) { // todo: respect Maximization:true/false
     84      if (bestKnownQuality == null ||
     85        (!maximization && (qualities[idxBest].Value < bestKnownQuality.Value) ||
     86        (maximization && (qualities[idxBest].Value > bestKnownQuality.Value)))) {
    8287        BestKnownQualityParameter.ActualValue = new DoubleValue(qualities[idxBest].Value);
    8388
     
    96101      int i = 0;
    97102      RunCollection rc = new RunCollection();
    98       foreach (ParameterConfigurationTree pt in parameterTrees.OrderBy(x => x.AverageQualityNormalized)) { // todo: respect Maximization:true/false
     103      foreach (ParameterConfigurationTree pt in (maximization ? parameterTrees.OrderByDescending(x => x.Quality) : parameterTrees.OrderBy(x => x.Quality))) {
    99104        rc.Add(pt.ToRun(string.Format("Individual {0} ({1})", i, pt.ParameterInfoString)));
    100105        i++;
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOBestSolutionHistoryAnalyzer.cs

    r5576 r6018  
    77using HeuristicLab.Parameters;
    88using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9 using System.Collections.Generic;
    10 using System;
    11 using HeuristicLab.Analysis;
    129
    1310namespace HeuristicLab.Problems.MetaOptimization {
     
    3431      get { return (LookupParameter<IntValue>)Parameters["Generations"]; }
    3532    }
     33    public LookupParameter<BoolValue> MaximizationParameter {
     34      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     35    }
    3636
    3737    public PMOBestSolutionHistoryAnalyzer()
     
    4242      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName));
    4343      Parameters.Add(new LookupParameter<IntValue>("Generations", ""));
     44      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
    4445    }
    4546
     
    5657      ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue;
    5758      int currentGeneration = GenerationsParameter.ActualValue.Value;
    58       int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; // todo: respect Min/Max
     59      bool maximization = MaximizationParameter.ActualValue.Value;
     60
     61      int idxBest;
     62      if (maximization)
     63        idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index;
     64      else
     65        idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     66
    5967      ParameterConfigurationTree best = parameterTrees[idxBest];
    6068
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/PMOProblemQualitiesAnalyzer.cs

    r5576 r6018  
    11using System.Linq;
     2using HeuristicLab.Analysis;
    23using HeuristicLab.Common;
    34using HeuristicLab.Core;
     
    78using HeuristicLab.Parameters;
    89using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9 using System.Collections.Generic;
    10 using System;
    11 using HeuristicLab.Analysis;
    1210
    1311namespace HeuristicLab.Problems.MetaOptimization {
     
    3129      get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
    3230    }
     31    public LookupParameter<BoolValue> MaximizationParameter {
     32      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     33    }
    3334
    3435    public PMOProblemQualitiesAnalyzer()
     
    3839      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", ""));
    3940      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName));
     41      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
    4042    }
    4143
     
    5153      ResultCollection results = ResultsParameter.ActualValue;
    5254      ItemArray<ParameterConfigurationTree> parameterTrees = ParameterConfigurationParameter.ActualValue;
    53       int idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index; // todo: respect Min/Max
    54       int idxWorst = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index;
    55      
     55      bool maximization = MaximizationParameter.ActualValue.Value;
     56
     57      int idxBest ;
     58      int idxWorst;
     59      if (maximization) {
     60        idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index;
     61        idxWorst = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     62      } else {
     63        idxBest = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).First().index;
     64        idxWorst = qualities.Select((x, index) => new { index, x.Value }).OrderBy(x => x.Value).Last().index;
     65      }
     66
    5667      int problemCount = ProblemsParameter.ActualValue.Count;
    5768
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/ReferenceQualityAnalyzer.cs

    r5653 r6018  
    77using HeuristicLab.Parameters;
    88using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9 using System.Collections.Generic;
    10 using System;
    119
    1210namespace HeuristicLab.Problems.MetaOptimization {
     
    1715  [StorableClass]
    1816  public sealed class ReferenceQualityAnalyzer : SingleSuccessorOperator, IAnalyzer {
    19    
     17
    2018    public ValueLookupParameter<ResultCollection> ResultsParameter {
    2119      get { return (ValueLookupParameter<ResultCollection>)Parameters["Results"]; }
     
    2725      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    2826    }
    29     public LookupParameter<DoubleArray> ProblemQualityReferenceParameter {
    30       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
     27    public LookupParameter<DoubleArray> ReferenceQualityAveragesParameter {
     28      get { return (LookupParameter<DoubleArray>)Parameters["ReferenceQualityAverages"]; }
     29    }
     30    public LookupParameter<DoubleArray> ReferenceQualityDeviationsParameter {
     31      get { return (LookupParameter<DoubleArray>)Parameters["ReferenceQualityDeviations"]; }
     32    }
     33    public LookupParameter<DoubleArray> ReferenceEvaluatedSolutionAveragesParameter {
     34      get { return (LookupParameter<DoubleArray>)Parameters["ReferenceEvaluatedSolutionAverages"]; }
    3135    }
    3236    public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter {
    3337      get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
     38    }
     39    public LookupParameter<BoolValue> MaximizationParameter {
     40      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
    3441    }
    3542
     
    3946      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", ""));
    4047      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
    41       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
     48      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityAverages", ""));
     49      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityDeviations", ""));
     50      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceEvaluatedSolutionAverages", ""));
    4251      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
     52      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
    4353    }
    4454
     
    5464      ItemArray<ParameterConfigurationTree> solutions = ParameterConfigurationParameter.ActualValue;
    5565      ItemArray<DoubleValue> qualities = QualityParameter.ActualValue;
     66      bool maximization = MaximizationParameter.ActualValue.Value;
    5667
    57       if (ProblemQualityReferenceParameter.ActualValue == null) {
    58         DoubleArray referenceQualities = CalculateReferenceQualities(solutions);
    59         ProblemQualityReferenceParameter.ActualValue = referenceQualities;
    60         NormalizePopulation(solutions, qualities, referenceQualities);
    61         results.Add(new Result("QualityReferences", referenceQualities));
     68      if (ReferenceQualityAveragesParameter.ActualValue == null) {
     69        // this is generation zero. calculate the reference values and apply them on population. in future generations `AlgorithmRunsAnalyzer` will do the nomalization
     70        DoubleArray referenceQualityAverages = CalculateReferenceQualityAverages(solutions, maximization);
     71        DoubleArray referenceQualityDeviations = CalculateReferenceQualityDeviations(solutions, maximization);
     72        DoubleArray referenceEvaluatedSolutionAverages = CalculateReferenceEvaluatedSolutionAverages(solutions, maximization);
     73
     74        ReferenceQualityAveragesParameter.ActualValue = referenceQualityAverages;
     75        ReferenceQualityDeviationsParameter.ActualValue = referenceQualityDeviations;
     76        ReferenceEvaluatedSolutionAveragesParameter.ActualValue = referenceEvaluatedSolutionAverages;
     77
     78        NormalizePopulation(solutions, qualities, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 1, 1, maximization);
     79
     80        results.Add(new Result("ReferenceQualities", referenceQualityAverages));
     81        results.Add(new Result("ReferenceQualityDeviations", referenceQualityDeviations));
     82        results.Add(new Result("ReferenceEvaluatedSolutionAverages", referenceEvaluatedSolutionAverages));
    6283      }
    6384
     
    6586    }
    6687
    67     private DoubleArray CalculateReferenceQualities(ItemArray<ParameterConfigurationTree> solutions) {
    68       DoubleArray referenceQualities = new DoubleArray(ProblemsParameter.ActualValue.Count);
     88    private DoubleArray CalculateReferenceQualityAverages(ItemArray<ParameterConfigurationTree> solutions, bool maximization) {
     89      DoubleArray references = new DoubleArray(ProblemsParameter.ActualValue.Count);
    6990      for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) {
    70         referenceQualities[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Min(); // todo: respect minimization / maximization
     91        if (maximization)
     92          references[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Max();
     93        else
     94          references[pi] = solutions.Where(x => x.AverageQualities != null).Select(x => x.AverageQualities[pi]).Min();
    7195      }
    72       return referenceQualities;
     96      return references;
    7397    }
    7498
    75     private void NormalizePopulation(ItemArray<ParameterConfigurationTree> solutions, ItemArray<DoubleValue> qualities, DoubleArray referenceQualities) {
     99    private DoubleArray CalculateReferenceQualityDeviations(ItemArray<ParameterConfigurationTree> solutions, bool maximization) {
     100      DoubleArray references = new DoubleArray(ProblemsParameter.ActualValue.Count);
     101      for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) {
     102        if (maximization)
     103          references[pi] = solutions.Where(x => x.QualityStandardDeviations != null).Select(x => x.QualityStandardDeviations[pi]).Max();
     104        else
     105          references[pi] = solutions.Where(x => x.QualityStandardDeviations != null).Select(x => x.QualityStandardDeviations[pi]).Min();
     106      }
     107      return references;
     108    }
     109
     110    private DoubleArray CalculateReferenceEvaluatedSolutionAverages(ItemArray<ParameterConfigurationTree> solutions, bool maximization) {
     111      DoubleArray references = new DoubleArray(ProblemsParameter.ActualValue.Count);
     112      for (int pi = 0; pi < ProblemsParameter.ActualValue.Count; pi++) {
     113        if (maximization)
     114          references[pi] = solutions.Where(x => x.AverageEvaluatedSolutions != null).Select(x => x.AverageEvaluatedSolutions[pi]).Max();
     115        else
     116          references[pi] = solutions.Where(x => x.AverageEvaluatedSolutions != null).Select(x => x.AverageEvaluatedSolutions[pi]).Min();
     117      }
     118      return references;
     119    }
     120
     121    private void NormalizePopulation(ItemArray<ParameterConfigurationTree> solutions, ItemArray<DoubleValue> qualities,
     122          DoubleArray referenceQualityAverages,
     123          DoubleArray referenceQualityDeviations,
     124          DoubleArray referenceEvaluatedSolutionAverages,
     125          double qualityAveragesWeight,
     126          double qualityDeviationsWeight,
     127          double evaluatedSolutionsWeight,
     128          bool maximization) {
    76129      for (int i = 0; i < solutions.Length; i++) {
    77         qualities[i].Value = MetaOptimizationUtil.NormalizeQualities(solutions[i], referenceQualities.ToArray());
     130        if (solutions[i].AverageQualities == null || solutions[i].QualityStandardDeviations == null || solutions[i].AverageEvaluatedSolutions == null) {
     131          // this parameterConfigurationTree has not been evaluated correctly (due to a faulty configuration, which led to an exception)
     132          // since we are in generation zero, there is no WorstQuality available for a penalty value
     133          double penaltyValue = maximization ? double.MinValue : double.MaxValue;
     134          qualities[i].Value = penaltyValue;
     135        } else {
     136          qualities[i].Value = MetaOptimizationUtil.Normalize(solutions[i],
     137            referenceQualityAverages.ToArray(),
     138            referenceQualityDeviations.ToArray(),
     139            referenceEvaluatedSolutionAverages.ToArray(),
     140            qualityAveragesWeight,
     141            qualityDeviationsWeight,
     142            evaluatedSolutionsWeight,
     143            maximization);
     144        }
    78145      }
    79146    }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Analyzers/SolutionCacheAnalyzer.cs

    r5359 r6018  
    77using HeuristicLab.Parameters;
    88using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9 using System.Collections.Generic;
    10 using System;
    119
    1210namespace HeuristicLab.Problems.MetaOptimization {
     
    2725      get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    2826    }
    29     public LookupParameter<DoubleArray> ProblemQualityReferenceParameter {
    30       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
    31     }
    3227    public LookupParameter<ConstrainedItemList<IProblem>> ProblemsParameter {
    3328      get { return (LookupParameter<ConstrainedItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
     
    4540      Parameters.Add(new ValueLookupParameter<ResultCollection>("Results", ""));
    4641      Parameters.Add(new ScopeTreeLookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
    47       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
    4842      Parameters.Add(new LookupParameter<ConstrainedItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
    4943      Parameters.Add(new LookupParameter<IntValue>("Generations", ""));
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurationTree.cs

    r5927 r6018  
    1616
    1717    [Storable]
    18     private DoubleValue averageQualityNormalized;
    19     public DoubleValue AverageQualityNormalized {
    20       get { return averageQualityNormalized; }
    21       set {
    22         if (averageQualityNormalized != value) {
    23           averageQualityNormalized = value;
     18    private DoubleValue quality;
     19    public DoubleValue Quality {
     20      get { return quality; }
     21      set {
     22        if (quality != value) {
     23          quality = value;
    2424          OnQualityChanged();
    2525        }
     
    2828
    2929    [Storable]
    30     private DoubleArray qualitiesNormalized;
    31     public DoubleArray QualitiesNormalized {
    32       get { return qualitiesNormalized; }
    33       set {
    34         if (qualitiesNormalized != value) {
    35           qualitiesNormalized = value;
    36         }
    37       }
    38     }
    39 
     30    private DoubleArray normalizedQualityAverages;
     31    public DoubleArray NormalizedQualityAverages {
     32      get { return normalizedQualityAverages; }
     33      set {
     34        if (normalizedQualityAverages != value) {
     35          normalizedQualityAverages = value;
     36        }
     37      }
     38    }
     39
     40    [Storable]
     41    private DoubleArray normalizedQualityDeviations;
     42    public DoubleArray NormalizedQualityDeviations {
     43      get { return normalizedQualityDeviations; }
     44      set {
     45        if (normalizedQualityDeviations != value) {
     46          normalizedQualityDeviations = value;
     47        }
     48      }
     49    }
     50
     51    [Storable]
     52    private DoubleArray normalizedEvaluatedSolutions;
     53    public DoubleArray NormalizedEvaluatedSolutions {
     54      get { return normalizedEvaluatedSolutions; }
     55      set {
     56        if (normalizedEvaluatedSolutions != value) {
     57          normalizedEvaluatedSolutions = value;
     58        }
     59      }
     60    }
     61   
    4062    [Storable]
    4163    private DoubleArray bestQualities;
     
    85107
    86108    [Storable]
     109    private DoubleArray averageEvaluatedSolutions;
     110    public DoubleArray AverageEvaluatedSolutions {
     111      get { return averageEvaluatedSolutions; }
     112      set { averageEvaluatedSolutions = value; }
     113    }
     114
     115    [Storable]
    87116    private IntValue repetitions;
    88117    public IntValue Repetitions {
     
    116145      }
    117146    }
    118 
    119     //[Storable]
    120     //protected string name;
    121     //public string Name {
    122     //  get { return name; }
    123     //  set { name = value; }
    124     //}
    125147
    126148    #region constructors and cloning
     
    136158      algproblemitem.ProblemParameter.Value = problem;
    137159      this.discoverValidValues = false;
    138      
     160
    139161      this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Algorithm", algproblemitem.AlgorithmParameter));
    140162      this.parameterConfigurations.Add(new SingleValuedParameterConfiguration("Problem", algproblemitem.ProblemParameter));
     
    145167    protected ParameterConfigurationTree(ParameterConfigurationTree original, Cloner cloner)
    146168      : base(original, cloner) {
    147       this.averageQualityNormalized = cloner.Clone(original.averageQualityNormalized);
    148       this.qualitiesNormalized = cloner.Clone(original.qualitiesNormalized);
     169      this.quality = cloner.Clone(original.quality);
     170      this.normalizedQualityAverages = cloner.Clone(original.normalizedQualityAverages);
     171      this.normalizedQualityDeviations = cloner.Clone(original.normalizedQualityDeviations);
     172      this.normalizedEvaluatedSolutions = cloner.Clone(original.normalizedEvaluatedSolutions);
    149173      this.bestQualities = cloner.Clone(original.BestQualities);
    150174      this.averageQualities = cloner.Clone(original.averageQualities);
     
    153177      this.qualityVariances = cloner.Clone(original.qualityVariances);
    154178      this.averageExecutionTimes = cloner.Clone(original.averageExecutionTimes);
     179      this.averageEvaluatedSolutions = cloner.Clone(original.averageEvaluatedSolutions);
    155180      this.repetitions = cloner.Clone(original.repetitions);
    156181      this.runs = cloner.Clone(original.runs);
     
    171196    public virtual void CollectResultValues(IDictionary<string, IItem> values) {
    172197      values.Add("RunsAverageExecutionTimes", AverageExecutionTimes);
     198      values.Add("RunsAverageEvaluatedSolutions", AverageEvaluatedSolutions);
    173199      values.Add("Repetitions", Repetitions);
    174200      values.Add("RunsBestQualities", BestQualities);
     
    177203      values.Add("RunsQualityVariances", QualityVariances);
    178204      values.Add("RunsQualityStandardDeviations", QualityStandardDeviations);
    179       values.Add("QualitiesNormalized", QualitiesNormalized);
    180       values.Add("AverageQualityNormalized", AverageQualityNormalized);
     205      values.Add("QualitiesNormalized", NormalizedQualityAverages);
     206      values.Add("AverageQualityNormalized", Quality);
    181207      values.Add("Runs", Runs);
    182208    }
     
    209235
    210236      algorithm.CollectParameterValues(this.Parameters);
    211       //((IProblem)ProblemConfiguration.ActualValue.Value).CollectParameterValues(this.Parameters);
    212       //CollectAlgorithmParameterValues((IAlgorithm)AlgorithmConfiguration.ActualValue.Value, parameters);
    213     }
    214 
    215     //protected virtual void CollectAlgorithmParameterValues(IAlgorithm algorithm, IDictionary<string, IItem> values) {
    216     //  var algorithmValues = new Dictionary<string, IItem>();
    217     //  algorithm.CollectParameterValues(algorithmValues);
    218     //  foreach (var value in algorithmValues) {
    219     //    values.Add("Algorithm." + value.Key, value.Value);
    220     //  }
    221     //}
     237    }
    222238
    223239    public Experiment GenerateExperiment(IAlgorithm algorithm, bool createBatchRuns, int repetitions) {
     
    294310        var sb = new StringBuilder();
    295311        if (!string.IsNullOrEmpty(algorithmInfo)) {
    296           sb.Append("Algorithm: ");
     312          sb.Append("Algorithm (");
    297313          sb.Append(algorithmInfo);
     314          sb.Append(")");
    298315        }
    299316        if (!string.IsNullOrEmpty(problemInfo)) {
    300317          if (sb.Length > 0)
    301318            sb.Append(", ");
    302           sb.Append("Problem: ");
     319          sb.Append("Problem( ");
    303320          sb.Append(problemInfo);
     321          sb.Append(")");
    304322        }
    305323        return sb.ToString();
     
    311329      ProblemConfiguration.CollectOptimizedParameterNames(parameterNames, string.Empty);
    312330    }
    313 
    314    
    315331  }
    316332}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/ParameterConfiguration.cs

    r6017 r6018  
    9292          if (this.valueConfigurations != null) DeregisterValueConfigurationEvents();
    9393          this.valueConfigurations = value;
     94          KeepActualValueConfigurationIndexConsistent();
    9495          if (this.valueConfigurations != null) RegisterValueConfigurationEvents();
    9596        }
     
    144145      set { autoPopulateValueConfigurations = value; }
    145146    }
    146    
     147
    147148
    148149    #region Constructors and Cloning
     
    258259        } else {
    259260          IItem val;
    260           if (ActualValue.Value != null && ActualValue.ValueDataType == t) {
     261          if (ActualValue.Value != null && ActualValue.Value.GetType() == t) {
    261262            val = (IItem)ActualValue.Value.Clone(); // use existing value for that type (if available)
    262263          } else {
     
    363364    void ValueConfigurations_CheckedItemsChanged(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    364365      OnToStringChanged();
    365     }
     366      KeepActualValueConfigurationIndexConsistent();
     367    }
     368
    366369    void ValueConfigurations_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    367370      OnToStringChanged();
     371      KeepActualValueConfigurationIndexConsistent();
    368372    }
    369373    void ValueConfigurations_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IndexedItem<IValueConfiguration>> e) {
    370374      OnToStringChanged();
     375      KeepActualValueConfigurationIndexConsistent();
    371376    }
    372377
     
    440445    }
    441446
    442     public string ParameterInfoString {
     447    public virtual string ParameterInfoString {
    443448      get {
    444449        StringBuilder sb = new StringBuilder();
     
    455460          }
    456461
    457           if (this.ActualValue.Value is IParameterizedItem) {
     462          if (this.ValueConfigurations[actualValueConfigurationIndex] is ParameterizedValueConfiguration) {
    458463            string subParams = this.ValueConfigurations[actualValueConfigurationIndex].ParameterInfoString;
    459464            if (!string.IsNullOrEmpty(subParams)) {
     
    583588      }
    584589    }
     590
     591    /// <summary>
     592    /// Ensures that the ActualValueConfigurationIndex has a valid value
     593    /// Only indices of items which are checked are allowed
     594    /// </summary>
     595    private void KeepActualValueConfigurationIndexConsistent() {
     596      if (this.valueConfigurations != null && this.valueConfigurations.CheckedItems.Count() > 0) {
     597        if(this.valueConfigurations.Count <= this.actualValueConfigurationIndex &&
     598           this.valueConfigurations.CheckedItems.Count(x => x.Index == this.actualValueConfigurationIndex) == 1) {
     599          // everything is ok; do nothing
     600        } else {
     601          // current index is invalid, set new one
     602          this.ActualValueConfigurationIndex = this.valueConfigurations.CheckedItems.First().Index;
     603        }
     604      } else {
     605        // no checked valueConfiguration is available; cannot be used
     606        this.ActualValueConfigurationIndex = -1;
     607      }
     608    }
    585609  }
    586610}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Encoding/ParameterConfigurations/SingleValuedParameterConfiguration.cs

    r5927 r6018  
    2424      this.discoverValidValues = false;
    2525      this.validValues = new ItemSet<IItem> { valueConfiguration.ActualValue.Value };
    26       this.validTypes = new Type[] {valueConfiguration.ActualValue.ValueDataType};
     26      this.validTypes = new Type[] { valueConfiguration.ActualValue.ValueDataType };
    2727      this.IsNullable = false;
    2828      this.itemImage = valueConfiguration.ItemImage;
     
    6969      OnToStringChanged();
    7070    }
     71
     72    public override string ParameterInfoString {
     73      get {
     74        if (this.Optimize) {
     75          return string.Format("{0} ({1})", this.Name, this.ValueConfigurations.Single().ParameterInfoString);
     76        } else {
     77          return string.Empty;
     78        }
     79      }
     80    }
    7181  }
    7282}
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmEvaluator.cs

    r6017 r6018  
    6464      var sw = new Stopwatch();
    6565      sw.Start();
    66       algorithm.StartSync();
     66      algorithm.StartSync(CancellationToken);
    6767      sw.Stop();
    6868      Console.WriteLine("{0},{1}: {2} (Grammar: {3})", ProblemIndexParameter.ActualValue.Value, RepetitionIndexParameter.ActualValue.Value, sw.Elapsed, PrintGrammar(srp.SymbolicExpressionTreeGrammar));
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmRunsAnalyzer.cs

    r5653 r6018  
    22using System.Collections.Generic;
    33using System.Linq;
    4 using System.Text;
     4using HeuristicLab.Common;
     5using HeuristicLab.Core;
     6using HeuristicLab.Data;
    57using HeuristicLab.Operators;
     8using HeuristicLab.Optimization;
     9using HeuristicLab.Parameters;
    610using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    7 using HeuristicLab.Core;
    8 using HeuristicLab.Common;
    9 using HeuristicLab.Parameters;
    10 using HeuristicLab.Data;
    11 using HeuristicLab.Optimization;
    1211
    1312namespace HeuristicLab.Problems.MetaOptimization {
     
    3231      get { return (ILookupParameter<IItemList<IProblem>>)Parameters[MetaOptimizationProblem.ProblemsParameterName]; }
    3332    }
    34     public LookupParameter<DoubleArray> ProblemQualityReferencesParameter {
    35       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
     33    public LookupParameter<DoubleArray> ReferenceQualityAveragesParameter {
     34      get { return (LookupParameter<DoubleArray>)Parameters["ReferenceQualityAverages"]; }
     35    }
     36    public LookupParameter<DoubleArray> ReferenceQualityDeviationsParameter {
     37      get { return (LookupParameter<DoubleArray>)Parameters["ReferenceQualityDeviations"]; }
     38    }
     39    public LookupParameter<DoubleArray> ReferenceEvaluatedSolutionAveragesParameter {
     40      get { return (LookupParameter<DoubleArray>)Parameters["ReferenceEvaluatedSolutionAverages"]; }
    3641    }
    3742    public LookupParameter<ResultCollection> ResultsParameter {
     
    4752      get { return (ScopeTreeLookupParameter<IntValue>)Parameters["RepetitionIndex"]; }
    4853    }
     54    public LookupParameter<BoolValue> MaximizationParameter {
     55      get { return (LookupParameter<BoolValue>)Parameters["Maximization"]; }
     56    }
    4957    #endregion
    5058
     
    5866      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
    5967      Parameters.Add(new LookupParameter<IItemList<IProblem>>(MetaOptimizationProblem.ProblemsParameterName, ""));
    60       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
     68      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityAverages", ""));
     69      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceQualityDeviations", ""));
     70      Parameters.Add(new LookupParameter<DoubleArray>("ReferenceEvaluatedSolutionAverages", ""));
    6171      Parameters.Add(new LookupParameter<ResultCollection>("Results", ""));
    6272      Parameters.Add(new ScopeTreeLookupParameter<IAlgorithm>("Algorithm", "The finished algorithms containing Runs."));
    6373      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("ProblemIndex", "The index of the problem an algorithm was executed with."));
    6474      Parameters.Add(new ScopeTreeLookupParameter<IntValue>("RepetitionIndex", "The index of the repetition"));
     75      Parameters.Add(new LookupParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized."));
    6576    }
    6677    protected AlgorithmRunsAnalyzer(AlgorithmRunsAnalyzer original, Cloner cloner)
     
    7889      IEnumerable<string> parameterNames = parameterConfiguration.GetOptimizedParameterNames();
    7990      IItemList<IProblem> problems = ProblemsParameter.ActualValue;
     91      bool maximization = MaximizationParameter.ActualValue.Value;
    8092      int repetitions = RepetitionsParameter.ActualValue.Value;
    81       var resultNames = new List<string> { "BestQuality", "Execution Time" };
     93      var resultNames = new List<string> { "BestQuality", "Execution Time", "EvaluatedSolutions" };
    8294      int currentGeneration = GenerationsParameter.ActualValue != null ? GenerationsParameter.ActualValue.Value : 0;
    83       double[] referenceQualities = GetReferenceQualities(problems.Count);
     95      double[] referenceQualityAverages;
     96      double[] referenceQualityDeviations;
     97      double[] referenceEvaluatedSolutionAverages;
     98      GetReferenceValues(problems.Count, out referenceQualityAverages, out referenceQualityDeviations, out referenceEvaluatedSolutionAverages);
     99
    84100      ResultCollection results = ResultsParameter.ActualValue;
    85101
     
    88104        var qualities = new double[problems.Count][];
    89105        var executionTimes = new TimeSpan[problems.Count][];
     106        var evaluatedSolutions = new int[problems.Count][];
    90107
    91108        for (int i = 0; i < problems.Count; i++) {
    92109          qualities[i] = new double[repetitions];
     110          evaluatedSolutions[i] = new int[repetitions];
    93111          executionTimes[i] = new TimeSpan[repetitions];
    94112        }
     
    98116          int repetitionIndex = repetitionIndices[i].Value;
    99117
    100           IRun run = algorithms[i].Runs.First();
     118          IRun run = algorithms[i].Runs.Single();
    101119          MetaOptimizationUtil.ClearResults(run, resultNames);
    102120          MetaOptimizationUtil.ClearParameters(run, parameterNames);
     
    107125          qualities[problemIndex][repetitionIndex] = (((DoubleValue)run.Results["BestQuality"]).Value);
    108126          executionTimes[problemIndex][repetitionIndex] = (((TimeSpanValue)run.Results["Execution Time"]).Value);
     127          evaluatedSolutions[problemIndex][repetitionIndex] = (((IntValue)run.Results["EvaluatedSolutions"]).Value);
    109128          runs.Add((IRun)run.Clone());
    110129        }
    111130
    112131        parameterConfiguration.AverageExecutionTimes = new ItemList<TimeSpanValue>(executionTimes.Select(t => new TimeSpanValue(TimeSpan.FromMilliseconds(t.Average(ts => ts.TotalMilliseconds)))));
     132        parameterConfiguration.AverageEvaluatedSolutions = new DoubleArray(evaluatedSolutions.Select(x => x.Average()).ToArray());
    113133        parameterConfiguration.Repetitions = new IntValue(repetitions);
    114         parameterConfiguration.BestQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray()); // todo: respect Maximization:true/false
    115134        parameterConfiguration.AverageQualities = new DoubleArray(qualities.Select(q => q.Average()).ToArray());
    116         parameterConfiguration.WorstQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray()); // todo: respect Maximization:true/false
     135
     136        if(maximization)
     137          parameterConfiguration.BestQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray());
     138        else
     139          parameterConfiguration.BestQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray());
     140       
     141        if (maximization)
     142          parameterConfiguration.WorstQualities = new DoubleArray(qualities.Select(q => q.Min()).ToArray());
     143        else
     144          parameterConfiguration.WorstQualities = new DoubleArray(qualities.Select(q => q.Max()).ToArray());
     145
    117146        parameterConfiguration.QualityVariances = new DoubleArray(qualities.Select(q => q.Variance()).ToArray());
    118147        parameterConfiguration.QualityStandardDeviations = new DoubleArray(qualities.Select(q => q.StandardDeviation()).ToArray());
    119148        parameterConfiguration.Runs = runs;
    120149
    121         this.QualityParameter.ActualValue = new DoubleValue(MetaOptimizationUtil.NormalizeQualities(parameterConfiguration, referenceQualities));
     150        this.QualityParameter.ActualValue = new DoubleValue(MetaOptimizationUtil.Normalize(parameterConfiguration, referenceQualityAverages, referenceQualityDeviations, referenceEvaluatedSolutionAverages, 1, 1, 1, maximization));
    122151      } else {
    123152        // something terrible happened -> most probably due to invalid parameters.
    124153        // penalty with worst quality from latest generation!
    125154
    126         double penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"]).Value : referenceQualities.Max(); // todo: respect min/max
     155        double penaltyValue = results.ContainsKey("CurrentWorstQuality") ? ((DoubleValue)results["CurrentWorstQuality"]).Value : referenceQualityAverages.Max(); // todo: respect min/max
    127156        this.QualityParameter.ActualValue = new DoubleValue(penaltyValue);
    128157      }
     
    131160    }
    132161
    133     private double[] GetReferenceQualities(int problemsCount) {
    134       double[] referenceQualities;
    135       if (ProblemQualityReferencesParameter.ActualValue == null) {
     162    private void GetReferenceValues(int problemsCount, out double[] referenceQualityAverages, out double[] referenceQualityDeviations, out double[] referenceEvaluatedSolutionAverages) {
     163      if (ReferenceQualityAveragesParameter.ActualValue == null) {
    136164        // this is generation zero. no reference qualities for normalization have been calculated yet. in this special case the ReferenceQualityAnalyzer will do the normalization
    137         referenceQualities = new double[problemsCount];
    138         for (int i = 0; i < referenceQualities.Length; i++) {
    139           referenceQualities[i] = 1;
     165        referenceQualityAverages = new double[problemsCount];
     166        referenceQualityDeviations = new double[problemsCount];
     167        referenceEvaluatedSolutionAverages = new double[problemsCount];
     168        for (int i = 0; i < referenceQualityAverages.Length; i++) {
     169          referenceQualityAverages[i] = 1;
     170          referenceQualityDeviations[i] = 1;
     171          referenceEvaluatedSolutionAverages[i] = 1;
    140172        }
    141173      } else {
    142         referenceQualities = ProblemQualityReferencesParameter.ActualValue.ToArray();
     174        referenceQualityAverages = ReferenceQualityAveragesParameter.ActualValue.ToArray();
     175        referenceQualityDeviations = ReferenceQualityDeviationsParameter.ActualValue.ToArray();
     176        referenceEvaluatedSolutionAverages = ReferenceEvaluatedSolutionAveragesParameter.ActualValue.ToArray();
    143177      }
    144       return referenceQualities;
    145178    }
    146179  }
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/AlgorithmSubScopesCreator.cs

    r5927 r6018  
    99
    1010namespace HeuristicLab.Problems.MetaOptimization {
    11   [Item("ChildrenCreator", "An operator which is used to prepare crossover. The sub-scopes of the current scope the operator is applied on represent the parents. The operator creates new and empty scopes for each child, adds the scopes that represent the child's parents as sub-scopes to the child and adds the child as sub-scope to the current scope.")]
     11  [Item("AlgorithmSubScopesCreator", "An operator which ...")]
    1212  [StorableClass]
    1313  public class AlgorithmSubScopesCreator : SingleSuccessorOperator {
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/Evaluators/PMOEvaluator.cs

    r5653 r6018  
    1 using System;
    2 using System.Collections.Generic;
    3 using System.Linq;
    4 using System.Text;
     1using HeuristicLab.Common;
     2using HeuristicLab.Core;
     3using HeuristicLab.Data;
    54using HeuristicLab.Operators;
    6 using HeuristicLab.Common;
    7 using HeuristicLab.Core;
     5using HeuristicLab.Optimization;
     6using HeuristicLab.Parameters;
    87using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    9 using HeuristicLab.Parameters;
    10 using HeuristicLab.Data;
    11 using HeuristicLab.Optimization;
    128
    139namespace HeuristicLab.Problems.MetaOptimization {
     
    3430    public LookupParameter<IntValue> RepetitionsParameter {
    3531      get { return (LookupParameter<IntValue>)Parameters[MetaOptimizationProblem.RepetitionsParameterName]; }
    36     }
    37     public LookupParameter<DoubleArray> ProblemQualityReferencesParameter {
    38       get { return (LookupParameter<DoubleArray>)Parameters["ProblemQualityReferences"]; }
    3932    }
    4033    public LookupParameter<IntValue> GenerationsParameter {
     
    7063      Parameters.Add(new LookupParameter<ParameterConfigurationTree>("ParameterConfigurationTree", ""));
    7164      Parameters.Add(new LookupParameter<IntValue>(MetaOptimizationProblem.RepetitionsParameterName, "Number of evaluations on one problem."));
    72       Parameters.Add(new LookupParameter<DoubleArray>("ProblemQualityReferences", ""));
    7365      Parameters.Add(new LookupParameter<IntValue>("Generations", ""));
    7466      Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents a population of solutions on which the genetic algorithm should be applied."));
  • branches/HeuristicLab.MetaOptimization/HeuristicLab.Problems.MetaOptimization/3.3/MetaOptimizationUtil.cs

    r5927 r6018  
    3434    }
    3535
    36     public static double NormalizeQualities(ParameterConfigurationTree parameterConfigurationTree, double[] referenceQualities) {
    37       double[] qualitiesNormalized = new double[referenceQualities.Length];
    38       for (int i = 0; i < referenceQualities.Length; i++) {
    39         qualitiesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / referenceQualities[i];
     36    public static double Normalize(
     37          ParameterConfigurationTree parameterConfigurationTree,
     38          double[] referenceQualityAverages,
     39          double[] referenceQualityDeviations,
     40          double[] referenceEvaluatedSolutionAverages,
     41          double qualityAveragesWeight,
     42          double qualityDeviationsWeight,
     43          double evaluatedSolutionsWeight,
     44          bool maximization) {
     45
     46      double[] qualityAveragesNormalized = new double[referenceQualityAverages.Length];
     47      double[] qualityDeviationsNormalized = new double[referenceQualityDeviations.Length];
     48      double[] evaluatedSolutionAveragesNormalized = new double[referenceEvaluatedSolutionAverages.Length];
     49
     50      for (int i = 0; i < referenceQualityAverages.Length; i++) {
     51        qualityAveragesNormalized[i] = parameterConfigurationTree.AverageQualities[i] / referenceQualityAverages[i];
     52        qualityDeviationsNormalized[i] = parameterConfigurationTree.QualityStandardDeviations[i] / referenceQualityDeviations[i];
     53        evaluatedSolutionAveragesNormalized[i] = parameterConfigurationTree.AverageEvaluatedSolutions[i] / referenceEvaluatedSolutionAverages[i];
    4054      }
    41       parameterConfigurationTree.QualitiesNormalized = new DoubleArray(qualitiesNormalized);
    42       parameterConfigurationTree.AverageQualityNormalized = new DoubleValue(qualitiesNormalized.Average());
    43       return parameterConfigurationTree.AverageQualityNormalized.Value;
     55      parameterConfigurationTree.NormalizedQualityAverages = new DoubleArray(qualityAveragesNormalized);
     56      parameterConfigurationTree.NormalizedQualityDeviations = new DoubleArray(qualityDeviationsNormalized);
     57      parameterConfigurationTree.NormalizedEvaluatedSolutions = new DoubleArray(evaluatedSolutionAveragesNormalized);
     58
     59      double qualityAveragesNormalizedValue = qualityAveragesNormalized.Average() * qualityAveragesWeight;
     60      double qualityDeviationsNormalizedValue = qualityDeviationsNormalized.Average() * qualityDeviationsWeight;
     61      double evaluatedSolutionAveragesNormalizedValue = evaluatedSolutionAveragesNormalized.Average() * evaluatedSolutionsWeight;
     62
     63      if (maximization) {
     64        // deviation and evaluatedSolutions are always minimization problems. so if maximization=true, flip the values around 1.0 (e.g. 1.15 -> 0.85)
     65        qualityDeviationsNormalizedValue -= (qualityDeviationsNormalizedValue - 1) * 2;
     66        evaluatedSolutionAveragesNormalizedValue -= (evaluatedSolutionAveragesNormalizedValue - 1) * 2;
     67      }
     68
     69      qualityAveragesNormalizedValue *= qualityAveragesWeight;
     70      qualityDeviationsNormalizedValue *= qualityDeviationsWeight;
     71      evaluatedSolutionAveragesNormalizedValue *= evaluatedSolutionsWeight;
     72
     73      parameterConfigurationTree.Quality = new DoubleValue(new double[] {qualityAveragesNormalizedValue, qualityDeviationsNormalizedValue, evaluatedSolutionAveragesNormalizedValue}.Average());
     74     
     75      return parameterConfigurationTree.Quality.Value;
    4476    }
    4577
     
    5183      algorithm.Problem = problem;
    5284      ((EngineAlgorithm)algorithm).Engine = new SequentialEngine.SequentialEngine();
    53       if(randomize) parameterConfigurationTree.Randomize(random);
     85      if (randomize) parameterConfigurationTree.Randomize(random);
    5486      parameterConfigurationTree.Parameterize(algorithm);
    5587      return algorithm;
Note: See TracChangeset for help on using the changeset viewer.