- Timestamp:
- 03/18/15 16:48:11 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsMover.cs
r12220 r12224 74 74 get { return (ILookupParameter<IntArray>)Parameters["AgeLimits"]; } 75 75 } 76 private ILookupParameter<IntValue> ElitesParameter { 77 get { return (ILookupParameter<IntValue>)Parameters["Elites"]; } 78 } 76 79 #endregion 77 80 … … 100 103 Parameters.Add(new LookupParameter<IntValue>("EvaluatedSolutions")); 101 104 Parameters.Add(new LookupParameter<IntArray>("AgeLimits")); 105 Parameters.Add(new LookupParameter<IntValue>("Elites")); 102 106 } 103 107 … … 111 115 private IntArray ageLimits; 112 116 private bool maximization; 117 private int elites; 113 118 public override IOperation Apply() { 114 119 int i = LayerParameter.ActualValue.Value; … … 122 127 ageLimits = AgeLimitsParameter.ActualValue; 123 128 maximization = MaximizationParameter.ActualValue.Value; 129 elites = ElitesParameter.ActualValue.Value; 124 130 125 131 layers = LayersScopeParameter.ActualValue; … … 164 170 return toOldIndividual.index; 165 171 172 // Take last, because it is the worst quality (sorted already before choosing TargetIndex) 173 var worstIndividual = individuals.LastOrDefault(); 166 174 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)) 170 176 return worstIndividual.index; 171 177 172 return Enumerable.Range(0, layer.SubScopes.Count).SampleRandom(rand);178 return rand.Next(elites, layer.SubScopes.Count); 173 179 } 174 180 }
Note: See TracChangeset
for help on using the changeset viewer.