Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/29/12 20:15:48 (12 years ago)
Author:
sforsten
Message:

#1980: implemented covering and changed SinglePointCrossover for CombinedIntegerVectorEncoding

Location:
branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3

    • Property svn:ignore
      •  

        old new  
        11*.user
        22Plugin.cs
         3obj
  • branches/LearningClassifierSystems/HeuristicLab.Encodings.CombinedIntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs

    r9089 r9090  
    3838    }
    3939
     40    public static CombinedIntegerVector Apply(IRandom random, CombinedIntegerVector parent1, CombinedIntegerVector parent2) {
     41      if (parent1.Length != parent2.Length && parent1.ActionLength != parent2.ActionLength && parent1.Bounds.Equals(parent2.Bounds))
     42        throw new ArgumentException("SinglePointCrossover: The parents are of different length.");
     43
     44      int length = parent1.Length;
     45      int actionLength = parent1.ActionLength;
     46      int conditionLength = length - actionLength;
     47      int[] result = new int[length];
     48      int breakPoint = random.Next(1, conditionLength);
     49
     50      for (int i = 0; i < breakPoint; i++) {
     51        result[i] = parent1[i];
     52      }
     53      for (int i = breakPoint; i < conditionLength; i++) {
     54        result[i] = parent2[i];
     55      }
     56
     57      CombinedIntegerVector actionParent = random.Next(2) == 1 ? parent1 : parent2;
     58      for (int i = conditionLength; i < length; i++) {
     59        result[i] = actionParent[i];
     60      }
     61
     62      return new CombinedIntegerVector(result, actionLength, parent1.Bounds);
     63    }
     64
    4065    protected override CombinedIntegerVector Cross(IRandom random, ItemArray<CombinedIntegerVector> parents) {
    4166      if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2");
    42       return new CombinedIntegerVector(HeuristicLab.Encodings.IntegerVectorEncoding.SinglePointCrossover.Apply(random, parents[0], parents[1]), parents[0].ActionLength, parents[0].Bounds);
     67      return Apply(random, parents[0], parents[1]);
    4368    }
    4469  }
Note: See TracChangeset for help on using the changeset viewer.