Changeset 1159 for trunk/sources/HeuristicLab.Evolutionary
- Timestamp:
- 01/21/09 15:46:27 (16 years ago)
- Location:
- trunk/sources/HeuristicLab.Evolutionary
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Evolutionary/CrossoverBase.cs
r881 r1159 50 50 IRandom random = GetVariableValue<IRandom>("Random", scope, true); 51 51 52 if ( (scope.SubScopes.Count % 2) != 0)53 throw new InvalidOperationException(" Size of mating pool is not even");52 if (scope.SubScopes.Count != 2) 53 throw new InvalidOperationException("ERROR: Number of parents is != 2"); 54 54 55 int children = scope.SubScopes.Count / 2; 56 for (int i = 0; i < children; i++) { 57 IScope parent1 = scope.SubScopes[0]; 58 IScope parent2 = scope.SubScopes[1]; 59 IScope child = new Scope(i.ToString()); 60 scope.AddSubScope(child); 61 Cross(scope, random, parent1, parent2, child); 62 scope.RemoveSubScope(parent1); 63 scope.RemoveSubScope(parent2); 64 } 55 IScope parent1 = scope.SubScopes[0]; 56 IScope parent2 = scope.SubScopes[1]; 57 IScope child = scope; 58 Cross(scope, random, parent1, parent2, child); 65 59 66 60 return null; -
trunk/sources/HeuristicLab.Evolutionary/HeuristicLab.Evolutionary.csproj
r852 r1159 60 60 </ItemGroup> 61 61 <ItemGroup> 62 <Compile Include="ChildrenInitializer.cs" /> 62 63 <Compile Include="MultiCrossoverBase.cs" /> 63 64 <Compile Include="SASEGASAReunificator.cs" /> -
trunk/sources/HeuristicLab.Evolutionary/MultiCrossoverBase.cs
r881 r1159 38 38 public MultiCrossoverBase() 39 39 : base() { 40 AddVariableInfo(new VariableInfo("Parents", "Number of parents that should be crossed", typeof(IntData), VariableKind.In));41 40 AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In)); 42 41 } … … 53 52 public override IOperation Apply(IScope scope) { 54 53 IRandom random = GetVariableValue<IRandom>("Random", scope, true); 55 int parents = GetVariableValue<IntData>("Parents", scope, true).Data;54 int parents = scope.SubScopes.Count; 56 55 57 if ( (scope.SubScopes.Count % parents) != 0)58 throw new InvalidOperationException(" Size of mating pool and number of parents don't match");56 if (parents < 2) 57 throw new InvalidOperationException("ERROR: Number of parents is < 2"); 59 58 60 int children = scope.SubScopes.Count / parents;61 for (int i = 0; i < children; i++) {62 IScope[] parentScopes = new IScope[parents];63 for (int j = 0; j < parentScopes.Length; j++)64 parentScopes[j] = scope.SubScopes[j];59 IScope[] parentScopes = new IScope[parents]; 60 for (int i = 0; i < parents; i++) 61 parentScopes[i] = scope.SubScopes[i]; 62 IScope child = scope; 63 Cross(scope, random, parentScopes, child); 65 64 66 IScope child = new Scope(i.ToString());67 scope.AddSubScope(child);68 Cross(scope, random, parentScopes, child);69 70 for (int j = 0; j < parentScopes.Length; j++)71 scope.RemoveSubScope(parentScopes[j]);72 }73 65 return null; 74 66 }
Note: See TracChangeset
for help on using the changeset viewer.