- Timestamp:
- 10/30/15 17:10:35 (9 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 3 added
- 2 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r13046 r13095 114 114 get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 115 115 } 116 private IValueParameter<BoolValue> ContinuousReseedingParameter { 117 get { return (IValueParameter<BoolValue>)Parameters["ContinuousReseeding"]; } 118 } 116 119 117 120 private IValueParameter<MultiTerminator> TerminatorParameter { … … 195 198 get { return MatingPoolRangeParameter.Value; } 196 199 set { MatingPoolRangeParameter.Value = value; } 200 } 201 public BoolValue ContinuousReseeding { 202 get { return ContinuousReseedingParameter.Value; } 203 set { ContinuousReseedingParameter.Value = value; } 197 204 } 198 205 … … 296 303 297 304 Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true }); 305 Parameters.Add(new ValueParameter<BoolValue>("ContinuousReseeding", "Instead of replacing the lowest layer every AgeGap generations replace 1/AgeGap individuals every generation", new BoolValue(false)) { Hidden = true }); 298 306 299 307 Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria which sould be checked.", new MultiTerminator())); … … 546 554 SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 547 555 SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 548 MainLoop.LayerUpdator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;549 MainLoop.LayerUpdator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;550 556 } 551 557 private void ParameterizeMainLoop() { … … 555 561 MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 556 562 MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 557 MainLoop.LayerUpdator.SolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;558 563 } 559 564 private void ParameterizeAnalyzers() { … … 614 619 int numberOfLayers = NumberOfLayers.Value; 615 620 AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers); 621 AgeLimits[AgeLimits.Length - 1] = int.MaxValue; // last layer infinite age limit 616 622 } 617 623 -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r13046 r13095 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Selection;33 32 34 33 namespace HeuristicLab.Algorithms.ALPS { … … 61 60 get { return OperatorGraph.Iterate().OfType<EldersEmigrator>().First(); } 62 61 } 63 public LayerUpdator LayerUpdator {64 get { return OperatorGraph.Iterate().OfType<LayerUpdator>().First(); }65 }66 62 67 63 [StorableConstructor] … … 90 86 var matingPoolProcessor = new UniformSubScopesProcessor(); 91 87 var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" }; 92 var mainOperator = CreatePreparedGeneticAlgorithmMainLoop();88 var mainOperator = AlpsGeneticAlgorithmMainOperator.Create(); 93 89 var generationsIcrementor = new IntCounter() { Name = "Increment Generations" }; 94 90 var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" }; 95 91 var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" }; 96 var layerUpdator = new LayerUpdator(mainOperator) { Name = "Update Layers" }; 92 var layerOpener = new LayerOpener() { Name = "Open new Layer" }; 93 var layerReseeder = new LayerReseeder() { Name = "Reseed Layer Zero" }; 97 94 var layerAnalyzerProcessor = new UniformSubScopesProcessor(); 98 95 var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; … … 146 143 evaluatedSolutionsReducer.Successor = eldersEmigrator; 147 144 148 eldersEmigrator.Successor = layer Updator;145 eldersEmigrator.Successor = layerOpener; 149 146 150 layerUpdator.Successor = layerAnalyzerProcessor; 147 layerOpener.Successor = layerReseeder; 148 149 layerReseeder.Successor = layerAnalyzerProcessor; 151 150 152 151 layerAnalyzerProcessor.Operator = layerAnalyzerPlaceholder; … … 160 159 termination.ContinueBranch = matingPoolCreator; 161 160 } 162 163 private GeneticAlgorithmMainLoop CreatePreparedGeneticAlgorithmMainLoop() {164 var mainLoop = new GeneticAlgorithmMainLoop();165 166 var oldInitialOp = mainLoop.OperatorGraph.InitialOperator;167 var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector");168 var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover");169 var subScopesCounter = mainLoop.OperatorGraph.Iterate().OfType<SubScopesCounter>().First();170 var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First();171 172 // Operator starts with calculating number of selected scopes base on plus/comma-selection replacement scheme173 var numberOfSubScopesBranch = new ConditionalBranch() { Name = "PlusSelection?" };174 var numberOfSelectedSubScopesPlusCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = PopulationSize * 2" };175 var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = (PopulationSize - Elites) * 2" };176 var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" };177 178 // Set new initial operator179 mainLoop.OperatorGraph.InitialOperator = numberOfSubScopesBranch;180 181 numberOfSubScopesBranch.ConditionParameter.ActualName = "PlusSelection";182 numberOfSubScopesBranch.TrueBranch = numberOfSelectedSubScopesPlusCalculator;183 numberOfSubScopesBranch.FalseBranch = numberOfSelectedSubScopesCalculator;184 numberOfSubScopesBranch.Successor = selector;185 186 numberOfSelectedSubScopesPlusCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));187 numberOfSelectedSubScopesPlusCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";188 numberOfSelectedSubScopesPlusCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 2 * toint");189 190 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));191 numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Elites"));192 numberOfSelectedSubScopesCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";193 numberOfSelectedSubScopesCalculator.ExpressionParameter.Value = new StringValue("PopulationSize Elites - 2 * toint");194 195 // Use Elitism or Plus-Selection as replacement strategy196 var selectedProcessor = (SubScopesProcessor)selector.Successor;197 var elitismReplacement = selectedProcessor.Successor;198 selectedProcessor.Successor = replacementBranch;199 replacementBranch.ConditionParameter.ActualName = "PlusSelection";200 replacementBranch.FalseBranch = elitismReplacement;201 202 // Plus selection replacement203 var replacementMergingReducer = new MergingReducer();204 var replacementBestSelector = new BestSelector();205 var replacementRightReducer = new RightReducer();206 replacementBranch.TrueBranch = replacementMergingReducer;207 208 replacementMergingReducer.Successor = replacementBestSelector;209 210 replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = "PopulationSize";211 replacementBestSelector.CopySelected = new BoolValue(false);212 replacementBestSelector.Successor = replacementRightReducer;213 214 replacementRightReducer.Successor = null;215 216 // Increment ages of all individuals after replacement217 var incrementAgeProcessor = new UniformSubScopesProcessor();218 var ageIncrementor = new DoubleCounter() { Name = "Increment Age" };219 replacementBranch.Successor = incrementAgeProcessor;220 incrementAgeProcessor.Operator = ageIncrementor;221 incrementAgeProcessor.Successor = null;222 ageIncrementor.ValueParameter.ActualName = "Age";223 ageIncrementor.Increment = new DoubleValue(1.0);224 225 // Insert AgeCalculator between crossover and its successor226 var crossoverSuccessor = crossover.Successor;227 var ageCalculator = new WeightingReducer() { Name = "Calculate Age" };228 crossover.Successor = ageCalculator;229 230 ageCalculator.ParameterToReduce.ActualName = "Age";231 ageCalculator.TargetParameter.ActualName = "Age";232 ageCalculator.WeightParameter.ActualName = "AgeInheritance";233 ageCalculator.Successor = crossoverSuccessor;234 235 // When counting the evaluated solutions, write in LayerEvaluatedSolutions236 subScopesCounter.ValueParameter.ActualName = "LayerEvaluatedSolutions";237 subScopesCounter.AccumulateParameter.Value = new BoolValue(false);238 239 // Instead of generational loop after merging of elites, stop240 elitesMerger.Successor = null;241 242 // Parameterize243 foreach (var stochasticOperator in mainLoop.OperatorGraph.Iterate().OfType<IStochasticOperator>())244 stochasticOperator.RandomParameter.ActualName = "LocalRandom";245 foreach (var stochasticBranch in mainLoop.OperatorGraph.Iterate().OfType<StochasticBranch>())246 stochasticBranch.RandomParameter.ActualName = "LocalRandom";247 248 // Remove unused operators249 var usedOperators = mainLoop.OperatorGraph.Iterate();250 var unusedOperators = mainLoop.OperatorGraph.Operators.Except(usedOperators);251 foreach (var op in unusedOperators.ToList())252 mainLoop.OperatorGraph.Operators.Remove(op);253 254 return mainLoop;255 }256 161 } 257 162 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r13079 r13095 132 132 </ItemGroup> 133 133 <ItemGroup> 134 <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" /> 135 <Compile Include="LayerOpener.cs" /> 136 <Compile Include="LayerReseeder.cs" /> 134 137 <Compile Include="WeightingReducer.cs" /> 135 138 <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" /> … … 142 145 <Compile Include="EldersSelector.cs" /> 143 146 <Compile Include="LayerCreator.cs" /> 144 <Compile Include="LayerSorter.cs" />145 <Compile Include="LayerUpdator.cs" />146 147 <Compile Include="MatingPoolCreator.cs" /> 147 148 <Compile Include="Plugin.cs" /> -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LayerCreator.cs
r13046 r13095 38 38 get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; } 39 39 } 40 public OperatorParameter NewLayerOperatorParameter { 41 get { return (OperatorParameter)Parameters["NewLayerOperator"]; } 42 } 43 44 public IOperator NewLayerOperator { 45 get { return NewLayerOperatorParameter.Value; } 46 set { NewLayerOperatorParameter.Value = value; } 47 } 40 48 41 49 [StorableConstructor] … … 48 56 : base() { 49 57 Parameters.Add(new LookupParameter<IntValue>("OpenLayers")); 58 Parameters.Add(new OperatorParameter("NewLayerOperator")); 50 59 } 51 60 … … 55 64 56 65 public override IOperation Apply() { 57 var scopes= ExecutionContext.Scope.SubScopes;58 if ( scopes.Count < 1)59 throw new ArgumentException("At least one sub-scopemust exist.");66 var layersScope = ExecutionContext.Scope.SubScopes; 67 if (layersScope.Count < 1) 68 throw new ArgumentException("At least one layer must exist."); 60 69 61 var lastSubScope = scopes.Last(); 62 var clone = (IScope)lastSubScope.Clone(new Cloner()); 70 var newLayer = (IScope)layersScope.Last().Clone(); 63 71 64 72 int number; 65 if (int.TryParse( clone.Name, out number))66 clone.Name = (number + 1).ToString();73 if (int.TryParse(newLayer.Name, out number)) 74 newLayer.Name = (number + 1).ToString(); 67 75 68 scopes.Add(clone);76 layersScope.Add(newLayer); 69 77 70 // Set new layer number71 clone.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);78 // Set new layer number 79 newLayer.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value); 72 80 73 81 // Decrement ages, because MainOperator is goint to increment it 74 foreach (var solution in clone.SubScopes)82 foreach (var solution in newLayer.SubScopes) 75 83 ((DoubleValue)solution.Variables["Age"].Value).Value -= 1; 76 84 77 85 // Reset existing values in the results to NaN to symbolize that no layer existed during that duration 78 var results = (ResultCollection) clone.Variables["LayerResults"].Value;86 var results = (ResultCollection)newLayer.Variables["LayerResults"].Value; 79 87 ResetResults(results); 80 88 81 return base.Apply(); 89 var next = new OperationCollection(base.Apply()); 90 next.Insert(0, ExecutionContext.CreateChildOperation(NewLayerOperator, newLayer)); 91 return next; 82 92 } 83 93
Note: See TracChangeset
for help on using the changeset viewer.