- Timestamp:
- 07/08/10 12:28:06 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.NSGA2/3.3/NSGA2MainLoop.cs
r4012 r4017 23 23 using HeuristicLab.Operators; 24 24 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization.Operators; 28 using HeuristicLab.Selection; 25 29 26 30 namespace HeuristicLab.Algorithms.NSGA2 { … … 31 35 [StorableClass] 32 36 public class NSGA2MainLoop : AlgorithmOperator { 37 #region Parameter properties 38 public ValueLookupParameter<IRandom> RandomParameter { 39 get { return (ValueLookupParameter<IRandom>)Parameters["Random"]; } 40 } 41 public ValueLookupParameter<BoolValue> MaximizationParameter { 42 get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; } 43 } 44 public ScopeTreeLookupParameter<DoubleValue> QualityParameter { 45 get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; } 46 } 47 public ValueLookupParameter<IOperator> SelectorParameter { 48 get { return (ValueLookupParameter<IOperator>)Parameters["Selector"]; } 49 } 50 public ValueLookupParameter<PercentValue> CrossoverProbabilityParameter { 51 get { return (ValueLookupParameter<PercentValue>)Parameters["CrossoverProbability"]; } 52 } 53 public ValueLookupParameter<IOperator> CrossoverParameter { 54 get { return (ValueLookupParameter<IOperator>)Parameters["Crossover"]; } 55 } 56 public ValueLookupParameter<PercentValue> MutationProbabilityParameter { 57 get { return (ValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; } 58 } 59 public ValueLookupParameter<IOperator> MutatorParameter { 60 get { return (ValueLookupParameter<IOperator>)Parameters["Mutator"]; } 61 } 62 public ValueLookupParameter<IOperator> EvaluatorParameter { 63 get { return (ValueLookupParameter<IOperator>)Parameters["Evaluator"]; } 64 } 65 public ValueLookupParameter<IntValue> MaximumGenerationsParameter { 66 get { return (ValueLookupParameter<IntValue>)Parameters["MaximumGenerations"]; } 67 } 68 public ValueLookupParameter<VariableCollection> ResultsParameter { 69 get { return (ValueLookupParameter<VariableCollection>)Parameters["Results"]; } 70 } 71 public ValueLookupParameter<IOperator> AnalyzerParameter { 72 get { return (ValueLookupParameter<IOperator>)Parameters["Analyzer"]; } 73 } 74 #endregion 75 33 76 [StorableConstructor] 34 77 private NSGA2MainLoop(bool deserializing) : base() { } … … 39 82 40 83 private void Initialize() { 41 #region Create Parameters 84 #region Create parameters 85 Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator.")); 86 Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.")); 87 Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution.")); 88 Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction.")); 89 Parameters.Add(new ValueLookupParameter<PercentValue>("CrossoverProbability", "The probability that the crossover operator is applied on a solution.")); 90 Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions.")); 91 Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.")); 92 Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions.")); 93 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions.")); 94 Parameters.Add(new ValueLookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations which should be processed.")); 95 Parameters.Add(new ValueLookupParameter<VariableCollection>("Results", "The variable collection where results should be stored.")); 96 Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze each generation.")); 42 97 #endregion 43 98 44 #region Create Operators 99 #region Create operators 100 VariableCreator variableCreator = new VariableCreator(); 101 ResultsCollector resultsCollector1 = new ResultsCollector(); 102 Placeholder analyzer1 = new Placeholder(); 103 Placeholder selector = new Placeholder(); 104 SubScopesProcessor subScopesProcessor1 = new SubScopesProcessor(); 105 ChildrenCreator childrenCreator = new ChildrenCreator(); 106 UniformSubScopesProcessor uniformSubScopesProcessor = new UniformSubScopesProcessor(); 107 Placeholder crossover = new Placeholder(); 108 StochasticBranch stochasticBranch = new StochasticBranch(); 109 Placeholder mutator = new Placeholder(); 110 Placeholder evaluator = new Placeholder(); 111 SubScopesRemover subScopesRemover = new SubScopesRemover(); 112 SubScopesProcessor subScopesProcessor2 = new SubScopesProcessor(); 113 BestSelector bestSelector = new BestSelector(); 114 RightReducer rightReducer = new RightReducer(); 115 MergingReducer mergingReducer = new MergingReducer(); 116 IntCounter intCounter = new IntCounter(); 117 Comparator comparator = new Comparator(); 118 ResultsCollector resultsCollector2 = new ResultsCollector(); 119 Placeholder analyzer2 = new Placeholder(); 120 ConditionalBranch conditionalBranch = new ConditionalBranch(); 121 122 variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0))); 123 124 resultsCollector1.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 125 resultsCollector1.ResultsParameter.ActualName = "Results"; 126 127 analyzer1.Name = "Analyzer"; 128 analyzer1.OperatorParameter.ActualName = "Analyzer"; 129 130 selector.Name = "Selector"; 131 selector.OperatorParameter.ActualName = "Selector"; 132 133 childrenCreator.ParentsPerChild = new IntValue(2); 134 135 crossover.Name = "Crossover"; 136 crossover.OperatorParameter.ActualName = "Crossover"; 137 138 stochasticBranch.ProbabilityParameter.ActualName = "MutationProbability"; 139 stochasticBranch.RandomParameter.ActualName = "Random"; 140 141 mutator.Name = "Mutator"; 142 mutator.OperatorParameter.ActualName = "Mutator"; 143 144 evaluator.Name = "Evaluator"; 145 evaluator.OperatorParameter.ActualName = "Evaluator"; 146 147 subScopesRemover.RemoveAllSubScopes = true; 148 149 bestSelector.CopySelected = new BoolValue(false); 150 bestSelector.MaximizationParameter.ActualName = "Maximization"; 151 bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Elites"; 152 bestSelector.QualityParameter.ActualName = "Quality"; 153 154 intCounter.Increment = new IntValue(1); 155 intCounter.ValueParameter.ActualName = "Generations"; 156 157 comparator.Comparison = new Comparison(ComparisonType.GreaterOrEqual); 158 comparator.LeftSideParameter.ActualName = "Generations"; 159 comparator.ResultParameter.ActualName = "Terminate"; 160 comparator.RightSideParameter.ActualName = "MaximumGenerations"; 161 162 resultsCollector2.CollectedValues.Add(new LookupParameter<IntValue>("Generations")); 163 resultsCollector2.ResultsParameter.ActualName = "Results"; 164 165 analyzer2.Name = "Analyzer"; 166 analyzer2.OperatorParameter.ActualName = "Analyzer"; 167 168 conditionalBranch.ConditionParameter.ActualName = "Terminate"; 45 169 #endregion 46 170 47 #region Create Operator Graph 171 #region Create operator graph 172 OperatorGraph.InitialOperator = variableCreator; 173 variableCreator.Successor = resultsCollector1; 174 resultsCollector1.Successor = analyzer1; 175 analyzer1.Successor = selector; 176 selector.Successor = subScopesProcessor1; 177 subScopesProcessor1.Operators.Add(new EmptyOperator()); 178 subScopesProcessor1.Operators.Add(childrenCreator); 179 subScopesProcessor1.Successor = subScopesProcessor2; 180 childrenCreator.Successor = uniformSubScopesProcessor; 181 uniformSubScopesProcessor.Operator = crossover; 182 uniformSubScopesProcessor.Successor = null; 183 crossover.Successor = stochasticBranch; 184 stochasticBranch.FirstBranch = mutator; 185 stochasticBranch.SecondBranch = null; 186 stochasticBranch.Successor = evaluator; 187 mutator.Successor = null; 188 evaluator.Successor = subScopesRemover; 189 subScopesRemover.Successor = null; 190 subScopesProcessor2.Operators.Add(bestSelector); 191 subScopesProcessor2.Operators.Add(new EmptyOperator()); 192 subScopesProcessor2.Successor = mergingReducer; 193 bestSelector.Successor = rightReducer; 194 rightReducer.Successor = null; 195 mergingReducer.Successor = intCounter; 196 intCounter.Successor = comparator; 197 comparator.Successor = resultsCollector2; 198 resultsCollector2.Successor = analyzer2; 199 analyzer2.Successor = conditionalBranch; 200 conditionalBranch.FalseBranch = selector; 201 conditionalBranch.TrueBranch = null; 202 conditionalBranch.Successor = null; 48 203 #endregion 204 } 205 206 public override IOperation Apply() { 207 if (CrossoverParameter.ActualValue == null) 208 return null; 209 return base.Apply(); 49 210 } 50 211 }
Note: See TracChangeset
for help on using the changeset viewer.