Changeset 11583
- Timestamp:
- 11/25/14 13:46:50 (10 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 1 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r11580 r11583 39 39 [Creatable("Algorithms")] 40 40 [StorableClass] 41 public class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {41 public sealed class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent { 42 42 public string Filename { get; set; } 43 43 … … 371 371 } 372 372 private void ParameterizeMainLoop() { 373 MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 374 MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 375 MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 376 MainLoop.BestKnownQualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 373 //MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name; 374 //MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 375 //MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 376 //MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 377 MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 378 MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 379 MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 377 380 } 378 381 private void ParameterizeSelectors() { -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r11580 r11583 20 20 #endregion 21 21 22 using System.Linq; 23 using HeuristicLab.Algorithms.GeneticAlgorithm; 22 24 using HeuristicLab.Common; 23 25 using HeuristicLab.Core; … … 28 30 using HeuristicLab.Parameters; 29 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Selection; 30 33 31 34 namespace HeuristicLab.Algorithms.ALPS { 32 35 33 36 [Item("AlpsGeneticAlgorithmMainLoop", "An ALPS genetic algorithm main loop operator.")] 34 public class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {37 public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator { 35 38 #region Parameter Properties 36 39 public ILookupParameter<IRandom> RandomParameter { 37 40 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 38 41 } 39 public ILookupParameter<BoolValue> MaximizationParameter {42 /*public ILookupParameter<BoolValue> MaximizationParameter { 40 43 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; } 41 44 } … … 46 49 get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; } 47 50 } 51 public ILookupParameter<IOperator> EvaluatorParameter { 52 get { return (ILookupParameter<IOperator>)Parameters["Evaluator"]; } 53 }*/ 48 54 public ILookupParameter<IntValue> PopulationSizeParameter { 49 55 get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; } … … 64 70 get { return (ILookupParameter<IOperator>)Parameters["Mutator"]; } 65 71 } 66 public ILookupParameter<IOperator> EvaluatorParameter {67 get { return (ILookupParameter<IOperator>)Parameters["Evaluator"]; }68 }69 72 public ILookupParameter<IntValue> ElitesParameter { 70 73 get { return (ILookupParameter<IntValue>)Parameters["Elites"]; } … … 83 86 } 84 87 #endregion 88 89 public GeneticAlgorithmMainLoop MainOperator { 90 get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); } 91 } 85 92 86 93 [StorableConstructor] … … 95 102 : base() { 96 103 Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator.")); 97 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));104 /*Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 98 105 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 99 106 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far.")); 107 Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));*/ 100 108 Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population of solutions.")); 101 109 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process.")); … … 104 112 Parameters.Add(new LookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); 105 113 Parameters.Add(new LookupParameter<IOperator>("Mutator", "The operator used to mutate solutions.")); 106 Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));107 114 Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.")); 108 115 Parameters.Add(new LookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)")); … … 111 118 Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer.")); 112 119 113 114 120 var variableCreator = new VariableCreator() { Name = "Initialize" }; 115 121 var resultsCollector = new ResultsCollector(); … … 117 123 var initLayerAnalyzerProcessor = new SubScopesProcessor(); 118 124 var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; 119 var matingPoolCreator = new CombinedOperator() { Name = "Create Mating Pools" };125 var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" }; 120 126 var matingPoolProcessor = new UniformSubScopesProcessor(); 121 var mainOperator = new CombinedOperator() { Name = "Perform Generation" };127 var mainOperator = PrepareGeneticAlgorithmMainLoop(); 122 128 var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; 129 var generationsIcrementor = new IntCounter() { Name = "Increment Generations" }; 130 var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" }; 123 131 var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" }; 124 132 var layerUpdator = new CombinedOperator() { Name = "Update Layers" }; … … 150 158 matingPoolProcessor.Parallel.Value = true; 151 159 matingPoolProcessor.Operator = mainOperator; 152 matingPoolProcessor.Successor = eldersEmigrator; 160 matingPoolProcessor.Successor = generationsIcrementor; 161 162 generationsIcrementor.ValueParameter.ActualName = "Generations"; 163 generationsIcrementor.Increment = new IntValue(1); 164 generationsIcrementor.Successor = evaluatedSolutionsReducer; 165 166 evaluatedSolutionsReducer.ParameterToReduce.ActualName = "EvaluatedSolutions"; 167 evaluatedSolutionsReducer.TargetParameter.ActualName = "EvaluatedSolutions"; 168 evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum); 169 evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum); 170 evaluatedSolutionsReducer.Successor = eldersEmigrator; 153 171 154 172 mainOperator.Successor = layerAnalyzerPlaceholder; … … 170 188 generationsComparator.Successor = terminateBranch; 171 189 172 terminateBranch.ConditionParameter.ActualName = "Terminate generations";190 terminateBranch.ConditionParameter.ActualName = "TerminateGenerations"; 173 191 terminateBranch.FalseBranch = matingPoolCreator; 174 175 } 176 192 } 193 194 private GeneticAlgorithmMainLoop PrepareGeneticAlgorithmMainLoop() { 195 var mainLoop = new GeneticAlgorithmMainLoop(); 196 var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector"); 197 var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover"); 198 var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First(); 199 200 // Operator starts with selector 201 mainLoop.OperatorGraph.InitialOperator = selector; 202 203 // Insert AgeCalculator between crossover and its successor 204 var crossoverSuccessor = crossover.Successor; 205 var ageCalculator = new DataReducer() { Name = "Calculate Age" }; 206 ageCalculator.ParameterToReduce.ActualName = "Age"; 207 ageCalculator.TargetParameter.ActualName = "Age"; 208 ageCalculator.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Max); 209 ageCalculator.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign); 210 crossover.Successor = ageCalculator; 211 ageCalculator.Successor = crossoverSuccessor; 212 213 // Instead of generational loop after merging of elites, increment ages of all individuals 214 var processor = new UniformSubScopesProcessor(); 215 var incrementor = new IntCounter() { Name = "Increment Age" }; 216 processor.Operator = incrementor; 217 processor.Successor = null; 218 incrementor.ValueParameter.ActualName = "Age"; 219 incrementor.Increment = new IntValue(1); 220 incrementor.Successor = null; 221 elitesMerger.Successor = processor; 222 223 // Parameterize 224 foreach (var stochasticOperator in mainLoop.OperatorGraph.Iterate().OfType<IStochasticOperator>()) 225 stochasticOperator.RandomParameter.ActualName = "LocalRandom"; 226 foreach (var stochasticBranch in mainLoop.OperatorGraph.Iterate().OfType<StochasticBranch>()) 227 stochasticBranch.RandomParameter.ActualName = "LocalRandom"; 228 229 // Remove unnessesary subtrees 230 //foreach (var @operator in mainLoop.OperatorGraph.Iterate().OfType<SingleSuccessorOperator>().Where(o => o.Successor == selector)) 231 // @operator.Successor = null; 232 233 return mainLoop; 234 } 177 235 } 178 236 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r11580 r11583 81 81 <Compile Include="AlpsGeneticAlgorithm.cs" /> 82 82 <Compile Include="AlpsGeneticAlgorithmMainLoop.cs" /> 83 <Compile Include="MatingPoolCreator.cs" /> 83 84 <Compile Include="Plugin.cs" /> 84 85 <Compile Include="Properties\AssemblyInfo.cs" /> … … 90 91 </ItemGroup> 91 92 <ItemGroup> 93 <ProjectReference Include="..\..\HeuristicLab.Algorithms.GeneticAlgorithm\3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj"> 94 <Project>{a51da44f-cb35-4f6f-99f5-2a2e904ab93b}</Project> 95 <Name>HeuristicLab.Algorithms.GeneticAlgorithm-3.3</Name> 96 </ProjectReference> 92 97 <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj"> 93 98 <Project>{887425b4-4348-49ed-a457-b7d2c26ddbf9}</Project> -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Plugin.cs.frame
r11567 r11583 40 40 [PluginDependency("HeuristicLab.Random", "3.3")] 41 41 [PluginDependency("HeuristicLab.Selection", "3.3")] 42 [PluginDependency("HeuristicLab.Algorithms.GeneticAlgorithm", "3.3")] 42 43 public class HeuristicLabAlgorithmsALPSPlugin : PluginBase { 43 44 }
Note: See TracChangeset
for help on using the changeset viewer.