Changeset 12186 for branches/ALPS
- Timestamp:
- 03/11/15 09:33:08 (10 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r12120 r12186 64 64 get { return (IFixedValueParameter<BoolValue>)Parameters["ReevaluateElites"]; } 65 65 } 66 private IValueParameter<BoolValue> PlusSelectionParameter { 67 get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; } 68 } 66 69 #endregion 67 70 … … 99 102 get { return ReevaluateElitesParameter.Value.Value; } 100 103 set { ReevaluateElitesParameter.Value.Value = value; } 104 } 105 public bool PlusSelection { 106 get { return PlusSelectionParameter.Value.Value; } 107 set { PlusSelectionParameter.Value.Value = value; } 101 108 } 102 109 … … 126 133 Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1))); 127 134 Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true }); 135 Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false)) { Hidden = true }); 128 136 129 137 var globalRandomCreator = new RandomCreator(); -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r12094 r12186 178 178 private GeneticAlgorithmMainLoop CreatePreparedGeneticAlgorithmMainLoop() { 179 179 var mainLoop = new GeneticAlgorithmMainLoop(); 180 var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = (PopulationSize - Elites) * 2" }; 180 181 181 var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector"); 182 182 var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover"); … … 184 184 var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First(); 185 185 186 // Operator starts with numberOfSelectedSubScopesCalculator 187 mainLoop.OperatorGraph.InitialOperator = numberOfSelectedSubScopesCalculator; 186 // Operator starts with calculating number of selected scopes base on plus/comma-selection replacement scheme 187 var numberOfSubScopesBranch = new ConditionalBranch() { Name = "PlusSelection?" }; 188 var numberOfSelectedSubScopesPlusCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = PopulationSize * 2" }; 189 var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = (PopulationSize - Elites) * 2" }; 190 var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" }; 191 192 mainLoop.OperatorGraph.InitialOperator = numberOfSubScopesBranch; 193 194 numberOfSubScopesBranch.ConditionParameter.ActualName = "PlusSelection"; 195 numberOfSubScopesBranch.TrueBranch = numberOfSelectedSubScopesPlusCalculator; 196 numberOfSubScopesBranch.FalseBranch = numberOfSelectedSubScopesCalculator; 197 numberOfSubScopesBranch.Successor = selector; 198 199 numberOfSelectedSubScopesPlusCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize")); 200 numberOfSelectedSubScopesPlusCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes"; 201 numberOfSelectedSubScopesPlusCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 2 * toint"); 202 188 203 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize")); 189 204 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Elites")); 190 205 numberOfSelectedSubScopesCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes"; 191 206 numberOfSelectedSubScopesCalculator.ExpressionParameter.Value = new StringValue("PopulationSize Elites - 2 * toint"); 192 numberOfSelectedSubScopesCalculator.Successor = selector; 207 208 // Use Elitism or Plus-Selection as replacement strategy 209 var selectedProcessor = (SubScopesProcessor)selector.Successor; 210 var elitismReplacement = selectedProcessor.Successor; 211 selectedProcessor.Successor = replacementBranch; 212 replacementBranch.ConditionParameter.ActualName = "PlusSelection"; 213 replacementBranch.FalseBranch = elitismReplacement; 214 215 // Plus selection replacement 216 var replacementMergingReducer = new MergingReducer(); 217 var replacementBestSelector = new BestSelector(); 218 var replacementRightReducer = new RightReducer(); 219 replacementBranch.TrueBranch = replacementMergingReducer; 220 221 replacementMergingReducer.Successor = replacementBestSelector; 222 223 replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = "PopulationSize"; 224 replacementBestSelector.CopySelected = new BoolValue(false); 225 replacementBestSelector.Successor = replacementRightReducer; 226 227 replacementRightReducer.Successor = null; 228 229 // Increment ages of all individuals after replacement 230 var incrementAgeProcessor = new UniformSubScopesProcessor(); 231 var ageIncrementor = new IntCounter() { Name = "Increment Age" }; 232 replacementBranch.Successor = incrementAgeProcessor; 233 incrementAgeProcessor.Operator = ageIncrementor; 234 incrementAgeProcessor.Successor = null; 235 ageIncrementor.ValueParameter.ActualName = "Age"; 236 ageIncrementor.Increment = new IntValue(1); 237 //ageIncrementor.Successor = null; 193 238 194 239 // Insert AgeCalculator between crossover and its successor 195 240 var crossoverSuccessor = crossover.Successor; 196 241 var ageCalculator = new DataReducer() { Name = "Calculate Age" }; 242 crossover.Successor = ageCalculator; 243 197 244 ageCalculator.ParameterToReduce.ActualName = "Age"; 198 245 ageCalculator.TargetParameter.ActualName = "Age"; … … 200 247 ageCalculator.ReductionOperation.ActualName = "AgeInheritance"; 201 248 ageCalculator.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 202 crossover.Successor = ageCalculator;203 249 ageCalculator.Successor = crossoverSuccessor; 204 250 … … 207 253 subScopesCounter.AccumulateParameter.Value = new BoolValue(false); 208 254 209 // Instead of generational loop after merging of elites, increment ages of all individuals 210 var processor = new UniformSubScopesProcessor(); 211 var incrementor = new IntCounter() { Name = "Increment Age" }; 212 processor.Operator = incrementor; 213 processor.Successor = null; 214 incrementor.ValueParameter.ActualName = "Age"; 215 incrementor.Increment = new IntValue(1); 216 incrementor.Successor = null; 217 elitesMerger.Successor = processor; 255 // Instead of generational loop after merging of elites, stop 256 elitesMerger.Successor = null; 218 257 219 258 // Parameterize
Note: See TracChangeset
for help on using the changeset viewer.