Changeset 1159


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
Location:
trunk/sources
Files:
1 added
2 deleted
4 edited

Legend:

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

    r881 r1159  
    5050      IRandom random = GetVariableValue<IRandom>("Random", scope, true);
    5151
    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");
    5454
    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);
    6559
    6660      return null;
  • trunk/sources/HeuristicLab.Evolutionary/HeuristicLab.Evolutionary.csproj

    r852 r1159  
    6060  </ItemGroup>
    6161  <ItemGroup>
     62    <Compile Include="ChildrenInitializer.cs" />
    6263    <Compile Include="MultiCrossoverBase.cs" />
    6364    <Compile Include="SASEGASAReunificator.cs" />
  • 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    }
  • trunk/sources/HeuristicLab.RealVector/HeuristicLab.RealVector.csproj

    r852 r1159  
    7575    <Compile Include="RealVectorSelfAdaptiveMultiCrossoverBase.cs" />
    7676    <Compile Include="SelfAdaptiveDiscreteMultiCrossover.cs" />
    77     <Compile Include="SelfAdaptiveIntermediateMultiCrossover.cs" />
    7877    <Compile Include="SelfAdaptiveNormalAllPositionsManipulator.cs" />
    7978    <Compile Include="UniformAllPositionsManipulator.cs" />
     
    8584    <Compile Include="Properties\AssemblyInfo.cs" />
    8685    <Compile Include="SinglePointCrossover.cs" />
    87     <Compile Include="VariableStrengthNormalAllPositionsManipulator.cs" />
    8886  </ItemGroup>
    8987  <ItemGroup>
Note: See TracChangeset for help on using the changeset viewer.