- Timestamp:
- 03/26/15 13:35:56 (10 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsGeneticAlgorithmMainOperator.cs
r12150 r12259 48 48 var mutator = new Placeholder() { Name = "Mutator (Placeholder)" }; 49 49 var ageReducer = new DataReducer() { Name = "Calculate EvalsCreated" }; 50 var lastMoveReducer = new DataReducer() { Name = "Calculate LastMove" }; 50 51 var subScopesRemover = new SubScopesRemover(); 51 52 var evaluator = new Placeholder() { Name = "Evaluator (Placeholder)" }; 52 53 53 54 54 55 OperatorGraph.InitialOperator = selector; … … 74 75 ageReducer.TargetParameter.ActualName = "EvalsCreated"; 75 76 ageReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 77 ageReducer.Successor = lastMoveReducer; 76 78 77 ageReducer.Successor = subScopesRemover; 79 lastMoveReducer.ParameterToReduce.ActualName = "LastMove"; 80 lastMoveReducer.ReductionOperation.ActualName = "AgeInheritance"; 81 lastMoveReducer.ReductionOperation.Value = null; 82 lastMoveReducer.TargetParameter.ActualName = "LastMove"; 83 lastMoveReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 84 lastMoveReducer.Successor = subScopesRemover; 78 85 79 86 subScopesRemover.Successor = evaluator; -
branches/ALPS/HeuristicLab.Algorithms.ALPS.SteadyState/3.3/AlpsSsMover.cs
r12224 r12259 142 142 var currentLayer = layers.SubScopes[i]; 143 143 var currentIndividual = currentLayer.SubScopes[j]; 144 ((IntValue)currentIndividual.Variables["LastMove"].Value).Value = evals; 145 144 146 if (i < n - 1) { 145 147 var nextLayer = layers.SubScopes[i + 1]; … … 152 154 } 153 155 } 154 private int? FindReplaceable(IScope layer, IScope individualToReplace) {156 private int? FindReplaceable(IScope layer, IScope replacingCandidate) { 155 157 int layerNumber = ((IntValue)layer.Variables["Layer"].Value).Value; 156 158 … … 159 161 let quality = ((DoubleValue)individual.Variables[qualityVariableName].Value).Value 160 162 let evalsCreated = ((IntValue)individual.Variables["EvalsCreated"].Value).Value 163 let lastMove = ((IntValue)individual.Variables["LastMove"].Value).Value 161 164 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 }) 164 167 .ToList(); 165 168 166 169 var ageLimit = layerNumber < n - 1 ? ageLimits[layerNumber] : int.MaxValue; 167 170 171 // Individuals which are too old are first priority to be replaced 168 172 var toOldIndividual = individuals.FirstOrDefault(x => x.age >= ageLimit); 169 173 if (toOldIndividual != null) 170 174 return toOldIndividual.index; 171 175 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) 176 190 return worstIndividual.index; 177 191 178 return rand.Next(elites, layer.SubScopes.Count); 192 // No individual found for replacement 193 return null; 179 194 } 180 195 }
Note: See TracChangeset
for help on using the changeset viewer.