Changeset 3023 for trunk/sources/HeuristicLab.Optimization.Operators
- Timestamp:
- 03/14/10 23:32:27 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Optimization.Operators/3.3
- Files:
-
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
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.