Changeset 11586
- Timestamp:
- 11/26/14 11:06:38 (10 years ago)
- Location:
- branches/ALPS
- Files:
-
- 5 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r11585 r11586 217 217 Parameters.Add(new ValueParameter<AgingScheme>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new AgingScheme(AgingSchemes.Polynomial))); 218 218 Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(5))); 219 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 1, 20, 45, 80, 125 })) { Hidden = true });219 Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 5, 20, 45, 80, 125 })) { Hidden = true }); 220 220 Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new ReductionOperation(ReductionOperations.Max)) { Hidden = true }); 221 221 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); … … 373 373 SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 374 374 SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 375 MainLoop.EldersEmigrator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 376 MainLoop.EldersEmigrator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 377 375 378 } 376 379 private void ParameterizeMainLoop() { … … 382 385 MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 383 386 MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 387 MainLoop.EldersEmigrator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 388 MainLoop.EldersEmigrator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 384 389 } 385 390 private void ParameterizeSelectors() { -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r11585 r11586 38 38 public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator { 39 39 #region Parameter Properties 40 public ILookupParameter<IRandom> RandomParameter {41 get { return (ILookupParameter<IRandom>)Parameters["Random"]; }42 }43 /*public ILookupParameter<BoolValue> MaximizationParameter {44 get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }45 }46 public IScopeTreeLookupParameter<DoubleValue> QualityParameter {47 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }48 }49 public ILookupParameter<DoubleValue> BestKnownQualityParameter {50 get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }51 }52 public ILookupParameter<IOperator> EvaluatorParameter {53 get { return (ILookupParameter<IOperator>)Parameters["Evaluator"]; }54 }*/55 public ILookupParameter<IntValue> PopulationSizeParameter {56 get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; }57 }58 40 public ILookupParameter<IntValue> MaximumGenerationsParameter { 59 41 get { return (ILookupParameter<IntValue>)Parameters["MaximumGenerations"]; } 60 }61 public ILookupParameter<IOperator> SelectorParameter {62 get { return (ILookupParameter<IOperator>)Parameters["Selector"]; }63 }64 public ILookupParameter<IOperator> CrossoverParameter {65 get { return (ILookupParameter<IOperator>)Parameters["Crossover"]; }66 }67 public ILookupParameter<PercentValue> MutationProbabilityParameter {68 get { return (ILookupParameter<PercentValue>)Parameters["MutationProbability"]; }69 }70 public ILookupParameter<IOperator> MutatorParameter {71 get { return (ILookupParameter<IOperator>)Parameters["Mutator"]; }72 }73 public ILookupParameter<IntValue> ElitesParameter {74 get { return (ILookupParameter<IntValue>)Parameters["Elites"]; }75 }76 public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {77 get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }78 }79 public ILookupParameter<ResultCollection> ResultsParameter {80 get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }81 42 } 82 43 public ILookupParameter<IOperator> AnalyzerParameter { … … 91 52 get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); } 92 53 } 54 public EldersEmigrator EldersEmigrator { 55 get { return OperatorGraph.Iterate().OfType<EldersEmigrator>().First(); } 56 } 93 57 94 58 [StorableConstructor] … … 102 66 public AlpsGeneticAlgorithmMainLoop() 103 67 : base() { 104 Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));105 /*Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));106 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));107 Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));108 Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));*/109 Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));110 68 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process.")); 111 Parameters.Add(new LookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));112 Parameters.Add(new LookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));113 Parameters.Add(new LookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));114 Parameters.Add(new LookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));115 Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));116 Parameters.Add(new LookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));117 Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to store the results."));118 69 Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals.")); 119 70 Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer.")); … … 126 77 var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" }; 127 78 var matingPoolProcessor = new UniformSubScopesProcessor(); 128 var mainOperator = PrepareGeneticAlgorithmMainLoop();79 var mainOperator = CreatePreparedGeneticAlgorithmMainLoop(); 129 80 var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" }; 130 81 var generationsIcrementor = new IntCounter() { Name = "Increment Generations" }; 131 82 var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" }; 132 83 var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" }; 133 var layerUpdator = new CombinedOperator() { Name = "Update Layers" };84 var layerUpdator = new LayerUpdator(mainOperator) { Name = "Update Layers" }; 134 85 var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" }; 135 86 var generationsComparator = new Comparator() { Name = "Generations >= MaximumGenerations" }; … … 140 91 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 141 92 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastRefresh", new IntValue(0))); 93 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1))); 142 94 variableCreator.Successor = resultsCollector; 143 95 … … 193 145 } 194 146 195 private GeneticAlgorithmMainLoop PrepareGeneticAlgorithmMainLoop() {147 private GeneticAlgorithmMainLoop CreatePreparedGeneticAlgorithmMainLoop() { 196 148 var mainLoop = new GeneticAlgorithmMainLoop(); 197 149 var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector"); … … 228 180 stochasticBranch.RandomParameter.ActualName = "LocalRandom"; 229 181 230 // Remove unnessesary subtrees231 //foreach (var @operator in mainLoop.OperatorGraph.Operators.OfType<SingleSuccessorOperator>().Where(o => o.Successor == selector))232 // @operator.Successor = null;233 234 182 return mainLoop; 235 183 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersEmigrator.cs
r11585 r11586 20 20 #endregion 21 21 22 using System.Linq; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; … … 32 33 [Item("EldersEmigrator", "Moves Individuals which are too old for its current layer up to the next layer.")] 33 34 [StorableClass] 34 public class EldersEmigrator : AlgorithmOperator { 35 public sealed class EldersEmigrator : AlgorithmOperator { 36 37 public IValueLookupParameter<BoolValue> MaximizationParameter { 38 get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 39 } 40 public IScopeTreeLookupParameter<DoubleValue> QualityParameter { 41 get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 42 } 43 44 public SolutionsCreator SolutionsCreator { 45 get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); } 46 } 35 47 36 48 [StorableConstructor] … … 44 56 public EldersEmigrator() 45 57 : base() { 58 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 59 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 60 46 61 var selectorProsessor = new UniformSubScopesProcessor(); 47 62 var eldersSelector = new EldersSelector(); … … 50 65 var mergingReducer = new MergingReducer(); 51 66 var subScopesCounter = new SubScopesCounter(); 52 var countCalculator = new ExpressionCalculator() { Name = "Count = Min(NumSubScopes, PopulationSize)" }; 67 // TODO: if expression calculator supports int, use expression calculator 68 var countCalculator = new MergingReducerCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" }; 69 //var countCalculator = new ExpressionCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" }; 53 70 var bestSelector = new BestSelector(); 54 71 var rightReducer = new RightReducer(); … … 73 90 subScopesCounter.Successor = countCalculator; 74 91 75 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));76 countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumSubScopes"));77 countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes < PopulationSizeif");78 countCalculator.ExpressionResultParameter.ActualName = "Count";92 //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize")); 93 //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumSubScopes")); 94 //countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes PopulationSize < if"); 95 //countCalculator.ExpressionResultParameter.ActualName = "NumSubScopes"; 79 96 countCalculator.Successor = bestSelector; 80 97 81 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Count"; 98 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "NumSubScopes"; 99 bestSelector.QualityParameter.ActualName = QualityParameter.Name; 100 bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name; 82 101 bestSelector.Successor = rightReducer; 83 102 -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersSelector.cs
r11585 r11586 33 33 [Item("EldersSelector", "Select all individuals which are to old for their current layer.")] 34 34 [StorableClass] 35 public class EldersSelector : SingleObjectiveSelector {35 public sealed class EldersSelector : SingleObjectiveSelector { 36 36 37 37 private ILookupParameter<IntArray> AgeLimitsParameter { … … 40 40 private ILookupParameter<IntValue> NumberOfLayersParameter { 41 41 get { return (ILookupParameter<IntValue>)Parameters["NumberOfLayers"]; } 42 } 43 private ILookupParameter<IntValue> LayerParameter { 44 get { return (ILookupParameter<IntValue>)Parameters["Layer"]; } 42 45 } 43 46 … … 53 56 : base() { 54 57 Parameters.Add(new LookupParameter<IntArray>("AgeLimits")); 58 Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers")); 59 Parameters.Add(new LookupParameter<IntValue>("Layer")); 55 60 } 56 61 … … 58 63 var ageLimits = AgeLimitsParameter.ActualValue; 59 64 int numberOfLayers = NumberOfLayersParameter.ActualValue.Value; 65 int layer = LayerParameter.ActualValue.Value; 60 66 61 int layer = ((IntValue)CurrentScope.Variables["Layer"]).Value; 62 63 if (layer >= numberOfLayers) 67 if (layer >= numberOfLayers) // is max layer? 64 68 return new IScope[0]; 65 69 … … 67 71 var elders = 68 72 from scope in scopes 69 let age = ((IntValue)scope.Variables["Age"] ).Value73 let age = ((IntValue)scope.Variables["Age"].Value).Value 70 74 where age > limit 71 75 select scope; -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj
r11585 r11586 83 83 <Compile Include="EldersEmigrator.cs" /> 84 84 <Compile Include="EldersSelector.cs" /> 85 <Compile Include="LayerUpdator.cs" /> 85 86 <Compile Include="MatingPoolCreator.cs" /> 87 <Compile Include="OpenNewLayerCalculator.cs" /> 88 <Compile Include="MergingReducerCalculator.cs" /> 86 89 <Compile Include="Plugin.cs" /> 87 90 <Compile Include="Properties\AssemblyInfo.cs" /> -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs
r11583 r11586 20 20 #endregion 21 21 22 using System.Linq;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; … … 46 45 var subPopulations = ExecutionContext.Scope.SubScopes; 47 46 48 for (int i = subPopulations.Count - 1; i > =0; i++) {47 for (int i = subPopulations.Count - 1; i > 0; i++) { 49 48 var currentSubPopulation = subPopulations[i].SubScopes; 50 var prevSubPopulation = i > 0 ? subPopulations[i - 1].SubScopes : Enumerable.Empty<IScope>();49 var prevSubPopulation = subPopulations[i - 1].SubScopes; 51 50 52 foreach (var individual in prevSubPopulation) {51 foreach (var individual in prevSubPopulation) 53 52 currentSubPopulation.Add(individual); 54 }55 53 } 54 56 55 return base.Apply(); 57 56 } -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/ShiftToRightMigrator.cs
r11585 r11586 29 29 30 30 namespace HeuristicLab.Algorithms.ALPS { 31 [Item("ShiftToRightMigrator", "Migrates the selected sub scopes by shifting itto the next(right) subscope.")]31 [Item("ShiftToRightMigrator", "Migrates the selected sub scopes by shifting them to the next(right) subscope.")] 32 32 [StorableClass] 33 public class ShiftToRightMigrator : SingleSuccessorOperator, IMigrator {33 public sealed class ShiftToRightMigrator : SingleSuccessorOperator, IMigrator { 34 34 35 35 [StorableConstructor] … … 59 59 emigrantsList.RemoveAt(emigrantsList.Count - 1); 60 60 61 for (int i = 0; i < scope.SubScopes.Count; i++) {61 for (int i = 0; i < scope.SubScopes.Count; i++) 62 62 scope.SubScopes[i].SubScopes.Add(emigrantsList[i]); 63 }64 63 65 64 return base.Apply(); -
branches/ALPS/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj
r11558 r11586 113 113 <Compile Include="CheckedMultiOperator.cs" /> 114 114 <Compile Include="CombinedOperator.cs" /> 115 <Compile Include="LastSubScopeProcessor.cs" /> 116 <Compile Include="FirstSubScopeProcessor.cs" /> 115 117 <Compile Include="Operator.InstrumentedOperatorWrapper.cs" /> 116 118 <None Include="Plugin.cs.frame" /> -
branches/ALPS/HeuristicLab.Optimization.Operators/3.3/ExpressionCalculator.cs
r11171 r11586 78 78 predicates: 79 79 ==, <, >, isnull, not 80 array index: 81 [] 80 82 stack manipulation: 81 83 drop swap dup
Note: See TracChangeset
for help on using the changeset viewer.