Ignore:
Timestamp:
01/21/09 15:46:27 (12 years ago)
Author:
abeham
Message:

implemented changes to crossover described in ticket #470

  • added ChildrenInitializer operator
  • modified CrossoverBase and MultiCrossoverBase
  • removed unnecessary operators in HeuristicLab.RealVector
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Evolutionary/MultiCrossoverBase.cs

    r881 r1159  
    3838    public MultiCrossoverBase()
    3939      : base() {
    40       AddVariableInfo(new VariableInfo("Parents", "Number of parents that should be crossed", typeof(IntData), VariableKind.In));
    4140      AddVariableInfo(new VariableInfo("Random", "Pseudo random number generator", typeof(IRandom), VariableKind.In));
    4241    }
     
    5352    public override IOperation Apply(IScope scope) {
    5453      IRandom random = GetVariableValue<IRandom>("Random", scope, true);
    55       int parents = GetVariableValue<IntData>("Parents", scope, true).Data;
     54      int parents = scope.SubScopes.Count;
    5655
    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");
    5958
    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);
    6564
    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       }
    7365      return null;
    7466    }
Note: See TracChangeset for help on using the changeset viewer.