Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/23/08 19:25:20 (16 years ago)
Author:
gkronber
Message:

implemented #386 (OffspringAnalyser should support m children for n parents)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Selection.OffspringSelection/OffspringAnalyzer.cs

    r77 r806  
    7373        return next;
    7474      } else {
    75         // analyze offspring
    76         for (int i = 0; i < scope.SubScopes.Count; i++) {
    77           double parent1 = double.MaxValue; // lowest quality parent
    78           double parent2 = double.MinValue; // highest quality parent
    79           for (int y = 0 ; y < parentsCount ; y++) {
    80             if (qualities.Data[parentsCount * i + y] < parent1) parent1 = qualities.Data[parentsCount * i + y];
    81             if (qualities.Data[parentsCount * i + y] > parent2) parent2 = qualities.Data[parentsCount * i + y];
     75        int crossoverEvents = qualities.Data.Length / parentsCount;
     76        int childrenPerCrossoverEvent = scope.SubScopes.Count / crossoverEvents;
     77        if (scope.SubScopes.Count % crossoverEvents != 0 ||
     78          childrenPerCrossoverEvent < 1) throw new InvalidOperationException("OffspringAnalyzer: The number of children per crossover event has to be constant and >= 1");
     79        // analyze offspring of all crossoverEvents
     80        for (int i = 0; i < crossoverEvents; i++) {
     81          double worstParent = double.MaxValue; // lowest quality parent
     82          double bestParent = double.MinValue; // highest quality parent
     83          for (int y = 0; y < parentsCount; y++) {
     84            if (qualities.Data[i * parentsCount + y] < worstParent) worstParent = qualities.Data[i * parentsCount + y];
     85            if (qualities.Data[i * parentsCount + y] > bestParent) bestParent = qualities.Data[i * parentsCount + y];
    8286          }
    83           IVariableInfo qualityInfo = GetVariableInfo("Quality");
    84           double child = scope.SubScopes[i].GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
    85           double threshold;
     87          for (int j = 0; j < childrenPerCrossoverEvent; j++) {
     88            IVariableInfo qualityInfo = GetVariableInfo("Quality");
     89            double child = scope.SubScopes[i * childrenPerCrossoverEvent + j].GetVariableValue<DoubleData>(qualityInfo.FormalName, false).Data;
     90            double threshold;
    8691
    87           if (!maximize)
    88             threshold = parent2 + (parent1 - parent2) * compFact;
    89           else
    90             threshold = parent1 + (parent2 - parent1) * compFact;
     92            if (!maximize)
     93              threshold = bestParent + (worstParent - bestParent) * compFact;
     94            else
     95              threshold = worstParent + (bestParent - worstParent) * compFact;
    9196
    92           IVariableInfo successfulInfo = GetVariableInfo("SuccessfulChild");
    93           BoolData successful;
    94           if (((!maximize) && (child < threshold)) ||
    95               ((maximize) && (child > threshold)))
    96             successful = new BoolData(true);
    97           else
    98             successful = new BoolData(false);
    99           scope.SubScopes[i].AddVariable(new Variable(scope.TranslateName(successfulInfo.FormalName), successful));
     97            IVariableInfo successfulInfo = GetVariableInfo("SuccessfulChild");
     98            BoolData successful;
     99            if (((!maximize) && (child < threshold)) ||
     100                ((maximize) && (child > threshold)))
     101              successful = new BoolData(true);
     102            else
     103              successful = new BoolData(false);
     104            scope.SubScopes[i * childrenPerCrossoverEvent + j].AddVariable(new Variable(scope.TranslateName(successfulInfo.FormalName), successful));
     105          }
    100106        }
    101107
Note: See TracChangeset for help on using the changeset viewer.