Changeset 12045 for branches/ALPS
- Timestamp:
- 02/20/15 11:52:08 (10 years ago)
- Location:
- branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs
r12040 r12045 90 90 get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; } 91 91 } 92 private IValueParameter<PercentValue> MatingPoolSelectionPercentageParameter { 93 get { return (IValueLookupParameter<PercentValue>)Parameters["MatingPoolSelectionPercentage"]; } 94 } 92 95 public IConstrainedValueParameter<ISelector> SelectorParameter { 93 96 get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; } … … 159 162 get { return MatingPoolRangeParameter.Value; } 160 163 set { MatingPoolRangeParameter.Value = value; } 164 } 165 public PercentValue MatingPoolSelectionPercentage { 166 get { return MatingPoolSelectionPercentageParameter.Value; } 167 set { MatingPoolSelectionPercentageParameter.Value = value; } 161 168 } 162 169 public ISelector Selector { … … 230 237 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 }); 231 238 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 }); 239 Parameters.Add(new ValueParameter<PercentValue>("MatingPoolSelectionPercentage", "Percentage of the previous layers used for creating a mating pool.", new PercentValue(1.0, restrictToUnitInterval: true)) { Hidden = true }); 232 240 Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction.")); 233 241 Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions.")); … … 421 429 } 422 430 private void ParameterizeMainLoop() { 431 MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; 432 MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName; 423 433 MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 424 434 MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name; … … 429 439 } 430 440 private void ParameterizeSelectors() { 431 432 441 foreach (var selector in SelectorParameter.ValidValues) { 433 442 selector.CopySelected = new BoolValue(true); -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs
r12035 r12045 38 38 public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator { 39 39 #region Parameter Properties 40 public ValueLookupParameter<BoolValue> MaximizationParameter { 41 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 42 } 43 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 44 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 45 } 40 46 public ILookupParameter<IntValue> MaximumGenerationsParameter { 41 47 get { return (ILookupParameter<IntValue>)Parameters["MaximumGenerations"]; } … … 69 75 public AlpsGeneticAlgorithmMainLoop() 70 76 : base() { 77 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 78 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 71 79 Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process.")); 72 80 Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals.")); … … 79 87 var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" }; 80 88 var resultsCollector = new ResultsCollector(); 89 var matingPoolPreProcessor = new UniformSubScopesProcessor() { Name = "MatingPoolPreProcessor" }; 90 var matingPoolPreSorter = new SubScopesSorter() { Name = "MatingPoolPreSorter" }; 81 91 var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" }; 82 92 var matingPoolProcessor = new LayerUniformSubScopesProcessor(); … … 116 126 resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers")); 117 127 resultsCollector.CopyValue = new BoolValue(false); 118 resultsCollector.Successor = matingPoolCreator; 128 resultsCollector.Successor = matingPoolPreProcessor; 129 130 matingPoolPreProcessor.Operator = matingPoolPreSorter; 131 matingPoolPreProcessor.Successor = matingPoolCreator; 132 133 matingPoolPreSorter.ValueParameter.ActualName = QualityParameter.Name; 134 matingPoolPreSorter.DescendingParameter.ActualName = MaximizationParameter.Name; 119 135 120 136 matingPoolCreator.Successor = matingPoolProcessor; … … 157 173 158 174 terminateBranch.ConditionParameter.ActualName = "TerminateGenerations"; 159 terminateBranch.FalseBranch = matingPool Creator;175 terminateBranch.FalseBranch = matingPoolPreProcessor; 160 176 } 161 177 -
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs
r12040 r12045 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 33 34 public sealed class MatingPoolCreator : SingleSuccessorOperator { 34 35 35 p rivateILookupParameter<IntValue> MatingPoolRangeParameter {36 public ILookupParameter<IntValue> MatingPoolRangeParameter { 36 37 get { return (ILookupParameter<IntValue>)Parameters["MatingPoolRange"]; } 38 } 39 public ILookupParameter<PercentValue> MatingPoolSelectionPercentageParameter { 40 get { return (ILookupParameter<PercentValue>)Parameters["MatingPoolSelectionPercentage"]; } 37 41 } 38 42 … … 48 52 : base() { 49 53 Parameters.Add(new LookupParameter<IntValue>("MatingPoolRange")); 54 Parameters.Add(new LookupParameter<PercentValue>("MatingPoolSelectionPercentage")); 50 55 } 51 56 … … 53 58 var layers = ExecutionContext.Scope.SubScopes; 54 59 int range = MatingPoolRangeParameter.ActualValue.Value; 60 double percentage = MatingPoolSelectionPercentageParameter.ActualValue.Value; 55 61 56 62 for (int layer = layers.Count - 1; layer > 0; layer--) { … … 58 64 for (int n = 1; (n <= range) && (layer - n >= 0); n++) { 59 65 var prevLayerScope = layers[layer - n]; 60 foreach (var individual in prevLayerScope.SubScopes) { 66 var individuals = prevLayerScope.SubScopes; 67 foreach (var individual in individuals.Take((int)(individuals.Count * percentage))) { 61 68 layerScope.SubScopes.Add((IScope)individual.Clone(new Cloner())); 62 69 }
Note: See TracChangeset
for help on using the changeset viewer.