Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/18/15 16:48:11 (10 years ago)
Author:
pfleck
Message:

#2350 Fixed a bug when selecting an individual for replacement during move-up recursion.

File:
1 edited

Legend:

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

    r12220 r12224  
    7474      get { return (ILookupParameter<IntArray>)Parameters["AgeLimits"]; }
    7575    }
     76    private ILookupParameter<IntValue> ElitesParameter {
     77      get { return (ILookupParameter<IntValue>)Parameters["Elites"]; }
     78    }
    7679    #endregion
    7780
     
    100103      Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions"));
    101104      Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
     105      Parameters.Add(new LookupParameter<IntValue>("Elites"));
    102106    }
    103107
     
    111115    private IntArray ageLimits;
    112116    private bool maximization;
     117    private int elites;
    113118    public override IOperation Apply() {
    114119      int i = LayerParameter.ActualValue.Value;
     
    122127      ageLimits = AgeLimitsParameter.ActualValue;
    123128      maximization = MaximizationParameter.ActualValue.Value;
     129      elites = ElitesParameter.ActualValue.Value;
    124130
    125131      layers = LayersScopeParameter.ActualValue;
     
    164170        return toOldIndividual.index;
    165171
     172      // Take last, because it is the worst quality (sorted already before choosing TargetIndex)
     173      var worstIndividual = individuals.LastOrDefault();
    166174      double replaceQuality = ((DoubleValue)individualToReplace.Variables[qualityVariableName].Value).Value;
    167       var sortedIndividuals = maximization ? individuals.OrderBy(x => x.quality) : individuals.OrderByDescending(x => x.quality);
    168       var worstIndividual = sortedIndividuals.FirstOrDefault(x => maximization ? x.quality < replaceQuality : x.quality > replaceQuality);
    169       if (worstIndividual != null)
     175      if (worstIndividual != null && (maximization ? worstIndividual.quality < replaceQuality : worstIndividual.quality > replaceQuality))
    170176        return worstIndividual.index;
    171177
    172       return Enumerable.Range(0, layer.SubScopes.Count).SampleRandom(rand);
     178      return rand.Next(elites, layer.SubScopes.Count);
    173179    }
    174180  }
Note: See TracChangeset for help on using the changeset viewer.