Changeset 3023
- Timestamp:
- 03/14/10 23:32:27 (15 years ago)
- Location:
- trunk/sources
- Files:
-
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Algorithms.SGA/3.3/SGA.cs
r3021 r3023 120 120 get { return (RandomCreator)OperatorGraph.InitialOperator; } 121 121 } 122 private PopulationCreator PopulationCreator {123 get { return ( PopulationCreator)RandomCreator.Successor; }122 private SolutionsCreator SolutionsCreator { 123 get { return (SolutionsCreator)RandomCreator.Successor; } 124 124 } 125 125 private SGAMainLoop SGAMainLoop { 126 get { return (SGAMainLoop) PopulationCreator.Successor; }126 get { return (SGAMainLoop)SolutionsCreator.Successor; } 127 127 } 128 128 private List<ISelector> selectors; … … 145 145 146 146 RandomCreator randomCreator = new RandomCreator(); 147 PopulationCreator populationCreator = new PopulationCreator();147 SolutionsCreator solutionsCreator = new SolutionsCreator(); 148 148 SGAMainLoop sgaMainLoop = new SGAMainLoop(); 149 149 OperatorGraph.InitialOperator = randomCreator; … … 154 154 randomCreator.SetSeedRandomlyParameter.ActualName = SetSeedRandomlyParameter.Name; 155 155 randomCreator.SetSeedRandomlyParameter.Value = null; 156 randomCreator.Successor = populationCreator;157 158 populationCreator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;159 populationCreator.Successor = sgaMainLoop;156 randomCreator.Successor = solutionsCreator; 157 158 solutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name; 159 solutionsCreator.Successor = sgaMainLoop; 160 160 161 161 sgaMainLoop.SelectorParameter.ActualName = SelectorParameter.Name; … … 184 184 ParameterizeStochasticOperator(Problem.Evaluator); 185 185 foreach (IOperator op in Problem.Operators) ParameterizeStochasticOperator(op); 186 Parameterize PopulationCreator();186 ParameterizeSolutionsCreator(); 187 187 ParameterizeSGAMainLoop(); 188 188 ParameterizeSelectors(); … … 194 194 protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) { 195 195 ParameterizeStochasticOperator(Problem.SolutionCreator); 196 Parameterize PopulationCreator();196 ParameterizeSolutionsCreator(); 197 197 base.Problem_SolutionCreatorChanged(sender, e); 198 198 } 199 199 protected override void Problem_EvaluatorChanged(object sender, EventArgs e) { 200 200 ParameterizeStochasticOperator(Problem.Evaluator); 201 Parameterize PopulationCreator();201 ParameterizeSolutionsCreator(); 202 202 ParameterizeSGAMainLoop(); 203 203 ParameterizeSelectors(); … … 244 244 } 245 245 246 private void Parameterize PopulationCreator() {247 PopulationCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;248 PopulationCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;246 private void ParameterizeSolutionsCreator() { 247 SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name; 248 SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name; 249 249 } 250 250 private void ParameterizeSGAMainLoop() { -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj
r3021 r3023 82 82 <ItemGroup> 83 83 <Compile Include="HeuristicLabOptimizationOperatorsPlugin.cs" /> 84 <Compile Include="PopulationCreator.cs" />85 84 <Compile Include="Properties\AssemblyInfo.cs" /> 86 85 <Compile Include="ChildrenCreator.cs" /> 86 <Compile Include="SolutionsCreator.cs" /> 87 87 </ItemGroup> 88 88 <ItemGroup> -
trunk/sources/HeuristicLab.Optimization.Operators/3.3/SolutionsCreator.cs
r3021 r3023 29 29 namespace HeuristicLab.Optimization.Operators { 30 30 /// <summary> 31 /// An operator which creates a new population ofsolutions.31 /// An operator which creates new solutions. 32 32 /// </summary> 33 [Item(" PopulationCreator", "An operator which creates a new population ofsolutions.")]33 [Item("SolutionsCreator", "An operator which creates new solutions.")] 34 34 [StorableClass] 35 35 [Creatable("Test")] 36 public sealed class PopulationCreator : SingleSuccessorOperator {37 public ValueLookupParameter<IntData> PopulationSizeParameter {38 get { return (ValueLookupParameter<IntData>)Parameters[" PopulationSize"]; }36 public sealed class SolutionsCreator : SingleSuccessorOperator { 37 public ValueLookupParameter<IntData> NumberOfSolutionsParameter { 38 get { return (ValueLookupParameter<IntData>)Parameters["NumberOfSolutions"]; } 39 39 } 40 40 public ValueLookupParameter<IOperator> SolutionCreatorParameter { … … 51 51 } 52 52 53 public PopulationCreator()53 public SolutionsCreator() 54 54 : base() { 55 Parameters.Add(new ValueLookupParameter<IntData>(" PopulationSize", "The number of individuals that should be created."));55 Parameters.Add(new ValueLookupParameter<IntData>("NumberOfSolutions", "The number of solutions that should be created.")); 56 56 Parameters.Add(new ValueLookupParameter<IOperator>("SolutionCreator", "The operator which is used to create new solutions.")); 57 57 Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator which is used to evaluate new solutions.")); 58 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope which represents the population."));58 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope to which the new solutions are added as sub-scopes.")); 59 59 } 60 60 61 61 public override IOperation Apply() { 62 int size = PopulationSizeParameter.ActualValue.Value;62 int count = NumberOfSolutionsParameter.ActualValue.Value; 63 63 IOperator creator = SolutionCreatorParameter.ActualValue; 64 64 IOperator evaluator = EvaluatorParameter.ActualValue; 65 65 66 if (CurrentScope.SubScopes.Count > 0) throw new InvalidOperationException("Population is not empty. PopulationCreator cannot be applied on scopes which already contain sub-scopes."); 67 68 for (int i = 0; i < size; i++) 69 CurrentScope.SubScopes.Add(new Scope(i.ToString())); 66 int current = CurrentScope.SubScopes.Count; 67 for (int i = 0; i < count; i++) 68 CurrentScope.SubScopes.Add(new Scope((current + i).ToString())); 70 69 71 70 OperationCollection next = new OperationCollection(); 72 for (int i = 0; i < CurrentScope.SubScopes.Count; i++) {73 if (creator != null) next.Add(ExecutionContext.CreateOperation(creator, CurrentScope.SubScopes[ i]));74 if (evaluator != null) next.Add(ExecutionContext.CreateOperation(evaluator, CurrentScope.SubScopes[ i]));71 for (int i = 0; i < count; i++) { 72 if (creator != null) next.Add(ExecutionContext.CreateOperation(creator, CurrentScope.SubScopes[current + i])); 73 if (evaluator != null) next.Add(ExecutionContext.CreateOperation(evaluator, CurrentScope.SubScopes[current + i])); 75 74 } 76 75 next.Add(base.Apply());
Note: See TracChangeset
for help on using the changeset viewer.