- Timestamp:
- 11/03/15 17:09:44 (9 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 2 deleted
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r13096 r13111 30 30 using HeuristicLab.Parameters; 31 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Selection; 32 33 33 34 namespace HeuristicLab.Algorithms.ALPS { … … 83 84 var generationsIcrementor = new IntCounter() { Name = "Increment Generations" }; 84 85 var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" }; 85 var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" };86 var layerOpener = new LayerOpener() { Name = "Open new Layer" };87 var layerReseeder = new LayerReseeder() { Name = "Reseed Layer Zero" };86 var eldersEmigrator = CreateEldersEmigrator(); 87 var layerOpener = CreateLayerOpener(); 88 var layerReseeder = CreateReseeder(); 88 89 var layerAnalyzerProcessor = new UniformSubScopesProcessor(); 89 90 var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; … … 153 154 termination.ContinueBranch = matingPoolCreator; 154 155 } 156 157 private static CombinedOperator CreateEldersEmigrator() { 158 var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" }; 159 var selectorProsessor = new UniformSubScopesProcessor(); 160 var eldersSelector = new EldersSelector(); 161 var shiftToRightMigrator = new UnidirectionalRingMigrator(); 162 var mergingProsessor = new UniformSubScopesProcessor(); 163 var mergingReducer = new MergingReducer(); 164 var subScopesCounter = new SubScopesCounter(); 165 var countCalculator = new ExpressionCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" }; 166 var bestSelector = new BestSelector(); 167 var rightReducer = new RightReducer(); 168 169 eldersEmigrator.OperatorGraph.InitialOperator = selectorProsessor; 170 171 selectorProsessor.Operator = eldersSelector; 172 selectorProsessor.Successor = shiftToRightMigrator; 173 174 shiftToRightMigrator.ClockwiseMigrationParameter.Value = new BoolValue(true); 175 shiftToRightMigrator.Successor = mergingProsessor; 176 177 mergingProsessor.Operator = mergingReducer; 178 179 mergingReducer.Successor = subScopesCounter; 180 181 subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize"; 182 subScopesCounter.AccumulateParameter.Value = new BoolValue(false); 183 subScopesCounter.Successor = countCalculator; 184 185 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize")); 186 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("LayerPopulationSize")); 187 countCalculator.ExpressionParameter.Value = new StringValue("LayerPopulationSize PopulationSize LayerPopulationSize PopulationSize < if toint"); 188 countCalculator.ExpressionResultParameter.ActualName = "LayerPopulationSize"; 189 countCalculator.Successor = bestSelector; 190 191 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize"; 192 bestSelector.CopySelected = new BoolValue(false); 193 bestSelector.Successor = rightReducer; 194 195 return eldersEmigrator; 196 } 197 198 private static CombinedOperator CreateLayerOpener() { 199 var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" }; 200 var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" }; 201 var maxLayerReachedBranch = new ConditionalBranch() { Name = "MaxLayersReached?" }; 202 var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" }; 203 var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" }; 204 var layerCreator = new LayerCreator() { Name = "Create Layer" }; 205 var createChildrenViaCrossover = AlpsGeneticAlgorithmMainOperator.Create(); 206 var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 207 var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" }; 208 var newLayerResultsCollector = new ResultsCollector() { Name = "Collect new Layer Results" }; 209 210 layerOpener.OperatorGraph.InitialOperator = maxLayerReached; 211 212 maxLayerReached.LeftSideParameter.ActualName = "OpenLayers"; 213 maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers"; 214 maxLayerReached.ResultParameter.ActualName = "MaxLayerReached"; 215 maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual); 216 maxLayerReached.Successor = maxLayerReachedBranch; 217 218 maxLayerReachedBranch.ConditionParameter.ActualName = "MaxLayerReached"; 219 maxLayerReachedBranch.FalseBranch = openNewLayerCalculator; 220 221 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>("AgeLimits")); 222 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 223 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers")); 224 openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers")); 225 openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer"; 226 openNewLayerCalculator.ExpressionParameter.Value = new StringValue("Generations 1 + AgeLimits OpenLayers 1 - [] >"); 227 openNewLayerCalculator.Successor = openNewLayerBranch; 228 229 openNewLayerBranch.ConditionParameter.ActualName = "OpenNewLayer"; 230 openNewLayerBranch.TrueBranch = layerCreator; 231 232 layerCreator.NewLayerOperator = createChildrenViaCrossover; 233 layerCreator.Successor = incrOpenLayers; 234 235 createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer; 236 237 incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions"; 238 incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true); 239 240 incrOpenLayers.ValueParameter.ActualName = "OpenLayers"; 241 incrOpenLayers.Increment = new IntValue(1); 242 incrOpenLayers.Successor = newLayerResultsCollector; 243 244 newLayerResultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults")); 245 newLayerResultsCollector.CopyValue = new BoolValue(false); 246 newLayerResultsCollector.Successor = null; 247 248 return layerOpener; 249 } 250 251 private static CombinedOperator CreateReseeder() { 252 var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" }; 253 var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" }; 254 var removeIndividuals = new SubScopesRemover(); 255 var createIndividuals = new SolutionsCreator(); 256 var initializeAgeProsessor = new UniformSubScopesProcessor(); 257 var initializeAge = new VariableCreator() { Name = "Initialize Age" }; 258 var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 259 260 reseeder.OperatorGraph.InitialOperator = reseedingController; 261 262 reseedingController.FirstLayerOperator = removeIndividuals; 263 264 removeIndividuals.Successor = createIndividuals; 265 266 createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize"; 267 createIndividuals.Successor = initializeAgeProsessor; 268 269 initializeAgeProsessor.Operator = initializeAge; 270 initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding; 271 272 initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0))); 273 274 incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions"; 275 incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true); 276 277 return reseeder; 278 } 155 279 } 156 280 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r13095 r13111 133 133 <ItemGroup> 134 134 <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" /> 135 <Compile Include="LayerOpener.cs" /> 136 <Compile Include="LayerReseeder.cs" /> 135 <Compile Include="ReseedingController.cs" /> 137 136 <Compile Include="WeightingReducer.cs" /> 138 137 <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" /> … … 142 141 <Compile Include="AlpsGeneticAlgorithmMainLoop.cs" /> 143 142 <Compile Include="Analyzers\OldestAverageYoungestAgeCalculator.cs" /> 144 <Compile Include="EldersEmigrator.cs" />145 143 <Compile Include="EldersSelector.cs" /> 146 144 <Compile Include="LayerCreator.cs" /> -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/ReseedingController.cs
r13110 r13111 20 20 #endregion 21 21 22 using System.Drawing;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 25 24 using HeuristicLab.Data; 26 25 using HeuristicLab.Operators; 27 using HeuristicLab.Optimization.Operators;28 26 using HeuristicLab.Parameters; 29 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 28 31 29 namespace HeuristicLab.Algorithms.ALPS { 32 [Item(" LayerReseeder", "An operator that encapsulates the reseeding of the lowest layer in ALPS.")]30 [Item("ReseedingController", "An operator that controls if reseeding is needed.")] 33 31 [StorableClass] 34 public sealed class LayerReseeder : SingleSuccessorOperator, IOperatorGraphOperator { 35 public static new Image StaticItemImage { 36 get { return HeuristicLab.Common.Resources.VSImageLibrary.Module; } 37 } 38 public override Image ItemImage { 39 get { 40 if (Breakpoint) return HeuristicLab.Common.Resources.VSImageLibrary.BreakpointActive; 41 else return base.ItemImage; 42 } 43 } 44 32 public sealed class ReseedingController : SingleSuccessorOperator { 45 33 private ILookupParameter<IntValue> GenerationsParameter { 46 34 get { return (ILookupParameter<IntValue>)Parameters["Generations"]; } … … 49 37 get { return (ILookupParameter<IntValue>)Parameters["AgeGap"]; } 50 38 } 39 public OperatorParameter FirstLayerOperatorParameter { 40 get { return (OperatorParameter)Parameters["FirstLayerOperator"]; } 41 } 51 42 52 [Storable] 53 private OperatorGraph operatorGraph; 54 public OperatorGraph OperatorGraph { 55 get { return operatorGraph; } 43 public IOperator FirstLayerOperator { 44 get { return FirstLayerOperatorParameter.Value; } 45 set { FirstLayerOperatorParameter.Value = value; } 56 46 } 57 47 58 48 [StorableConstructor] 59 private LayerReseeder(bool deserializing)49 private ReseedingController(bool deserializing) 60 50 : base(deserializing) { } 61 51 62 private LayerReseeder(LayerReseeder original, Cloner cloner)52 private ReseedingController(ReseedingController original, Cloner cloner) 63 53 : base(original, cloner) { 64 operatorGraph = cloner.Clone(original.operatorGraph);65 54 } 66 55 public override IDeepCloneable Clone(Cloner cloner) { 67 return new LayerReseeder(this, cloner);56 return new ReseedingController(this, cloner); 68 57 } 69 58 70 public LayerReseeder()59 public ReseedingController() 71 60 : base() { 72 61 Parameters.Add(new LookupParameter<IntValue>("Generations")); 73 62 Parameters.Add(new LookupParameter<IntValue>("AgeGap")); 74 75 operatorGraph = new OperatorGraph(); 76 77 var removeIndividuals = new SubScopesRemover(); 78 var createIndividuals = new SolutionsCreator(); 79 var initializeAgeProsessor = new UniformSubScopesProcessor(); 80 var initializeAge = new VariableCreator() { Name = "Initialize Age" }; 81 var incrEvaluatedSolutionsAfterReseeding = new SubScopesCounter() { Name = "Update EvaluatedSolutions" }; 82 83 OperatorGraph.InitialOperator = removeIndividuals; 84 85 removeIndividuals.Successor = createIndividuals; 86 87 createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize"; 88 createIndividuals.Successor = initializeAgeProsessor; 89 90 initializeAgeProsessor.Operator = initializeAge; 91 initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding; 92 93 initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0))); 94 initializeAge.Successor = null; 95 96 incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions"; 97 incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true); 98 incrEvaluatedSolutionsAfterReseeding.Successor = null; 63 Parameters.Add(new OperatorParameter("FirstLayerOperator")); 99 64 } 100 65 … … 106 71 if (generations % ageGap == 0) { 107 72 var layerZeroScope = ExecutionContext.Scope.SubScopes[0]; 108 if ( operatorGraph.InitialOperator != null)109 next.Insert(0, ExecutionContext.CreateChildOperation( operatorGraph.InitialOperator, layerZeroScope));73 if (FirstLayerOperator != null) 74 next.Insert(0, ExecutionContext.CreateChildOperation(FirstLayerOperator, layerZeroScope)); 110 75 } 111 76 return next;
Note: See TracChangeset
for help on using the changeset viewer.