Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
09/10/12 17:10:27 (12 years ago)
Author:
jkarder
Message:

#1247:

  • fixed some bugs
  • minor code improvements
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/RAPGA/HeuristicLab.Algorithms.RAPGA/3.3/ProgressiveOffspringPreserver.cs

    r8406 r8622  
    9393
    9494    public override IOperation Apply() {
    95       if (CurrentScope.SubScopes.Any()) {
    96         if (OffspringList.Any()) {
    97           var currentOffspring = new Scope();
    98           currentOffspring.SubScopes.AddRange(OffspringList);
    99           var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScope, currentOffspring);
    100           for (int i = CurrentScope.SubScopes.Count - 1; i >= 0 && OffspringList.Count < MaximumPopulationSize.Value - Elites.Value; i--)
    101             if (similarityMatrix[i].Any(x => x == 1.0)) CurrentScope.SubScopes.RemoveAt(i);
    102             else OffspringList.Add(CurrentScope.SubScopes[i]);
    103         } else OffspringList.AddRange(CurrentScope.SubScopes);
     95      if (CurrentScope.SubScopes.Any()) { // offspring created
     96        if (!OffspringList.Any()) OffspringList.AddRange(CurrentScope.SubScopes);
     97        else { // stored offspring exists
     98          var storedOffspringScope = new Scope();
     99          storedOffspringScope.SubScopes.AddRange(OffspringList);
     100          var similarityMatrix = SimilarityCalculator.CalculateSolutionCrowdSimilarity(CurrentScope, storedOffspringScope);
     101
     102          var createdOffspring = CurrentScope.SubScopes.ToArray();
     103
     104          int i = 0;
     105          // as long as offspring is available and not enough offspring has been preserved
     106          while (i < createdOffspring.Length && OffspringList.Count < MaximumPopulationSize.Value - Elites.Value) {
     107            if (similarityMatrix[i].Any(x => x == 1.0)) createdOffspring[i] = null; // discard duplicates
     108            else OffspringList.Add(createdOffspring[i]);
     109            i++;
     110          }
     111
     112          // discard remaining offspring
     113          while (i < createdOffspring.Length) createdOffspring[i++] = null;
     114
     115          // clean current scope
     116          CurrentScope.SubScopes.Replace(createdOffspring.Where(x => x != null));
     117        }
    104118      }
    105119      return base.Apply();
Note: See TracChangeset for help on using the changeset viewer.