Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/26/15 13:35:56 (9 years ago)
Author:
pfleck
Message:

#2350

  • Individuals keep track of their last move.
  • When trying to replace an individual, individuals with their last move long ago are prioritized to be replaced.
  • Elites can now be replaced too if the quality is bad enough.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsMover.cs

    r12224 r12259  
    142142      var currentLayer = layers.SubScopes[i];
    143143      var currentIndividual = currentLayer.SubScopes[j];
     144      ((IntValue)currentIndividual.Variables["LastMove"].Value).Value = evals;
     145
    144146      if (i < n - 1) {
    145147        var nextLayer = layers.SubScopes[i + 1];
     
    152154      }
    153155    }
    154     private int? FindReplaceable(IScope layer, IScope individualToReplace) {
     156    private int? FindReplaceable(IScope layer, IScope replacingCandidate) {
    155157      int layerNumber = ((IntValue)layer.Variables["Layer"].Value).Value;
    156158
     
    159161        let quality = ((DoubleValue)individual.Variables[qualityVariableName].Value).Value
    160162        let evalsCreated = ((IntValue)individual.Variables["EvalsCreated"].Value).Value
     163        let lastMove = ((IntValue)individual.Variables["LastMove"].Value).Value
    161164        let age = (evals - evalsCreated) / popSize
    162         select new { individual, quality, age }
    163         ).Select((x, index) => new { index, x.individual, x.quality, x.age })
     165        select new { individual, quality, age, lastMove }
     166        ).Select((x, index) => new { index, x.individual, x.quality, x.age, x.lastMove })
    164167        .ToList();
    165168
    166169      var ageLimit = layerNumber < n - 1 ? ageLimits[layerNumber] : int.MaxValue;
    167170
     171      // Individuals which are too old are first priority to be replaced
    168172      var toOldIndividual = individuals.FirstOrDefault(x => x.age >= ageLimit);
    169173      if (toOldIndividual != null)
    170174        return toOldIndividual.index;
    171175
    172       // Take last, because it is the worst quality (sorted already before choosing TargetIndex)
    173       var worstIndividual = individuals.LastOrDefault();
    174       double replaceQuality = ((DoubleValue)individualToReplace.Variables[qualityVariableName].Value).Value;
    175       if (worstIndividual != null && (maximization ? worstIndividual.quality < replaceQuality : worstIndividual.quality > replaceQuality))
     176      double replacingCandidateQuality = ((DoubleValue)replacingCandidate.Variables[qualityVariableName].Value).Value;
     177      var worseIndividuals = individuals.Where(individual =>
     178            maximization
     179              ? individual.quality < replacingCandidateQuality
     180              : individual.quality > replacingCandidateQuality)
     181           .ToList();
     182      // Then take the worst individual where the last move happed m * n evaluations ago
     183      int lastMoveLimit = evals - m * n;
     184      var worstIndividual = worseIndividuals.LastOrDefault(individual => individual.lastMove < lastMoveLimit);
     185      if (worstIndividual != null)
     186        return worstIndividual.index;
     187      // If no individual moved n * m evaluations ago, take the worst
     188      worstIndividual = worseIndividuals.LastOrDefault();
     189      if (worstIndividual != null)
    176190        return worstIndividual.index;
    177191
    178       return rand.Next(elites, layer.SubScopes.Count);
     192      // No individual found for replacement
     193      return null;
    179194    }
    180195  }
Note: See TracChangeset for help on using the changeset viewer.