Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/16/10 10:46:59 (15 years ago)
Author:
svonolfe
Message:

Updated the RealVector project to use the new solution encodings (#909)

Location:
trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/AverageCrossover.cs

    r3053 r3060  
    4545    /// <param name="parents">The list of parents.</param>
    4646    /// <returns>The child vector (average) of the parents.</returns>
    47     public static DoubleArray Apply(IRandom random, ItemArray<DoubleArray> parents) {
     47    public static RealVector Apply(IRandom random, ItemArray<RealVector> parents) {
    4848      int length = parents[0].Length, parentsCount = parents.Length;
    4949      if (parents.Length < 2) throw new ArgumentException("AverageCrossover: The number of parents is less than 2.", "parents");
    50       DoubleArray result = new DoubleArray(length);
     50      RealVector result = new RealVector(length);
    5151      try {
    5252        double avg;
     
    6565
    6666    /// <summary>
    67     /// Forwards the call to <see cref="Apply(IRandom, ItemArray<DoubleArray>)"/>.
     67    /// Forwards the call to <see cref="Apply(IRandom, ItemArray<RealVector>)"/>.
    6868    /// </summary>
    6969    /// <param name="random">The random number generator.</param>
    7070    /// <param name="parents">The list of parents.</param>
    7171    /// <returns>The child vector (average) of the parents.</returns>
    72     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     72    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    7373      return Apply(random, parents);
    7474    }
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/BlendAlphaBetaCrossover.cs

    r3053 r3060  
    9494    /// <param name="beta">The parameter beta.</param>
    9595    /// <returns>The real vector that results from the crossover.</returns>
    96     public static DoubleArray Apply(IRandom random, DoubleArray betterParent, DoubleArray worseParent, DoubleValue alpha, DoubleValue beta) {
     96    public static RealVector Apply(IRandom random, RealVector betterParent, RealVector worseParent, DoubleValue alpha, DoubleValue beta) {
    9797      if (betterParent.Length != worseParent.Length) throw new ArgumentException("BlendAlphaBetaCrossover: The parents' vectors are of different length.", "betterParent");
    9898      if (alpha.Value < 0) throw new ArgumentException("BlendAlphaBetaCrossover: Parameter alpha must be greater or equal to 0.", "alpha");
     
    100100      int length = betterParent.Length;
    101101      double min, max, d;
    102       DoubleArray result = new DoubleArray(length);
     102      RealVector result = new RealVector(length);
    103103
    104104      for (int i = 0; i < length; i++) {
     
    117117
    118118    /// <summary>
    119     /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, DoubleValue, DoubleValue)"/>.
     119    /// Checks if the number of parents is equal to 2, if all parameters are available and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector, DoubleValue, DoubleValue)"/>.
    120120    /// </summary>
    121121    /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception>
     
    132132    /// <param name="parents">The collection of parents (must be of size 2).</param>
    133133    /// <returns>The real vector that results from the crossover.</returns>
    134     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     134    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    135135      if (parents.Length != 2) throw new ArgumentException("BlendAlphaBetaCrossover: Number of parents is not equal to 2.", "parents");
    136136      if (MaximizationParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaBetaCrossover: Parameter " + MaximizationParameter.ActualName + " could not be found.");
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/BlendAlphaCrossover.cs

    r3053 r3060  
    7070    /// <param name="alpha">The alpha value for the crossover.</param>
    7171    /// <returns>The newly created real vector resulting from the crossover operation.</returns>
    72     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2, DoubleValue alpha) {
     72    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha) {
    7373      if (parent1.Length != parent2.Length) throw new ArgumentException("BlendAlphaCrossover: The parents' vectors are of different length.", "parent1");
    7474      if (alpha.Value < 0) throw new ArgumentException("BlendAlphaCrossover: Paramter alpha must be greater or equal than 0.", "alpha");
    7575      int length = parent1.Length;
    76       DoubleArray result = new DoubleArray(length);
     76      RealVector result = new RealVector(length);
    7777      double max = 0, min = 0, d = 0, resMin = 0, resMax = 0;
    7878
     
    9090
    9191    /// <summary>
    92     /// Checks that the number of parents is equal to 2 and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, DoubleValue)"/>.
     92    /// Checks that the number of parents is equal to 2 and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector, DoubleValue)"/>.
    9393    /// </summary>
    9494    /// <exception cref="ArgumentException">Thrown when the number of parents is not equal to 2.</exception>
     
    9797    /// <param name="parents">The collection of parents (must be of size 2).</param>
    9898    /// <returns>The real vector resulting from the crossover operation.</returns>
    99     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     99    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    100100      if (parents.Length != 2) throw new ArgumentException("BlendAlphaCrossover: The number of parents is not equal to 2", "parents");
    101101      if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("BlendAlphaCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs

    r3053 r3060  
    4545    /// <param name="parents">An array containing the parents that should be crossed.</param>
    4646    /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    47     public static DoubleArray Apply(IRandom random, ItemArray<DoubleArray> parents) {
     47    public static RealVector Apply(IRandom random, ItemArray<RealVector> parents) {
    4848      int length = parents[0].Length;
    4949     
     
    5353      }
    5454     
    55       DoubleArray result = new DoubleArray(length);
     55      RealVector result = new RealVector(length);
    5656      for (int i = 0; i < length; i++) {
    5757        result[i] = parents[random.Next(parents.Length)][i];
     
    6262
    6363    /// <summary>
    64     /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, ItemArray<DoubleArray>)"/>.
     64    /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, ItemArray<RealVector>)"/>.
    6565    /// </summary>
    6666    /// <exception cref="ArgumentException">Thrown when <paramref name="parents"/> contains less than 2 elements.</exception>
     
    6868    /// <param name="parents">The collection of parents (must be of size 2 or greater).</param>
    6969    /// <returns>The real vector resulting from the crossover.</returns>
    70     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     70    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    7171      if (parents.Length < 2) throw new ArgumentException("DiscreteCrossover: The number of parents is less than 2.", "parents");
    7272      return Apply(random, parents);
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/HeuristicCrossover.cs

    r3053 r3060  
    6868    /// <param name="worseParent">The second parent for the crossover operation.</param>
    6969    /// <returns>The newly created real vector, resulting from the heuristic crossover.</returns>
    70     public static DoubleArray Apply(IRandom random, DoubleArray betterParent, DoubleArray worseParent) {
     70    public static RealVector Apply(IRandom random, RealVector betterParent, RealVector worseParent) {
    7171      if (betterParent.Length != worseParent.Length)
    7272        throw new ArgumentException("HeuristicCrossover: the two parents are not of the same length");
     
    7979        result[i] = betterParent[i] + factor * (betterParent[i] - worseParent[i]);
    8080      }
    81       return new DoubleArray(result);
     81      return new RealVector(result);
    8282    }
    8383
     
    9696    /// <param name="parents">An array containing the two real vectors that should be crossed.</param>
    9797    /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    98     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     98    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    9999      if (parents.Length != 2) throw new ArgumentException("HeuristicCrossover: The number of parents is not equal to 2");
    100100
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/LocalCrossover.cs

    r3053 r3060  
    4343    /// <param name="parent2">The second parent for the crossover operation.</param>
    4444    /// <returns>The newly created real vector, resulting from the local crossover.</returns>
    45     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2) {
     45    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) {
    4646      if (parent1.Length != parent2.Length)
    4747        throw new ArgumentException("LocalCrossover: the two parents are not of the same length");
     
    5555        result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]);
    5656      }
    57       return new DoubleArray(result);
     57      return new RealVector(result);
    5858    }
    5959
     
    6565    /// <param name="parents">An array containing the two real vectors that should be crossed.</param>
    6666    /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    67     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     67    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    6868      if (parents.Length != 2) throw new ArgumentException("LocalCrossover: The number of parents is not equal to 2");
    6969      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/RandomConvexCrossover.cs

    r3053 r3060  
    4343    /// <param name="parent2">The second parent vector for the crossover.</param>
    4444    /// <returns>The newly created real vector, resulting from the random convex crossover.</returns>
    45     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2) {
     45    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) {
    4646      if (parent1.Length != parent2.Length)
    4747        throw new ArgumentException("ERROR in RandomConvexCrossover: the two parents are not of the same length");
     
    5353      for (int i = 0; i < length; i++)
    5454        result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]);
    55       return new DoubleArray(result);
     55      return new RealVector(result);
    5656    }
    5757
     
    6363    /// <param name="parents">An array containing the two real vectors that should be crossed.</param>
    6464    /// <returns>The newly created real vector, resulting from the crossover operation.</returns>
    65     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     65    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    6666      if (parents.Length != 2) throw new ArgumentException("ERROR in RandomConvexCrossover: The number of parents is not equal to 2");
    6767      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/SimulatedBinaryCrossover.cs

    r3053 r3060  
    6666    /// <param name="contiguity">The contiguity value that specifies how close a child should be to its parents (larger value means closer). The value must be greater or equal than 0. Typical values are in the range [2;5].</param>
    6767    /// <returns>The vector resulting from the crossover.</returns>
    68     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2, DoubleValue contiguity) {
     68    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue contiguity) {
    6969      if (parent1.Length != parent2.Length) throw new ArgumentException("SimulatedBinaryCrossover: Parents are of unequal length");
    7070      if (contiguity.Value < 0) throw new ArgumentException("SimulatedBinaryCrossover: Contiguity value is smaller than 0", "contiguity");
    7171      int length = parent1.Length;
    72       DoubleArray result = new DoubleArray(length);
     72      RealVector result = new RealVector(length);
    7373      for (int i = 0; i < length; i++) {
    7474        if (length == 1 || random.NextDouble() < 0.5) { // cross this variable
     
    9292
    9393    /// <summary>
    94     /// Checks number of parents, availability of the parameters and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray, DoubleValue)"/>.
     94    /// Checks number of parents, availability of the parameters and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector, DoubleValue)"/>.
    9595    /// </summary>
    9696    /// <exception cref="ArgumentException">Thrown when there are not exactly 2 parents or when the contiguity parameter could not be found.</exception>
     
    9898    /// <param name="parents">The collection of parents (must be of size 2).</param>
    9999    /// <returns>The real vector resulting from the crossover.</returns>
    100     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     100    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    101101      if (parents.Length != 2) throw new ArgumentException("SimulatedBinaryCrossover: The number of parents is not equal to 2");
    102102      if (ContiguityParameter.ActualValue == null) throw new InvalidOperationException("SimulatedBinaryCrossover: Parameter " + ContiguityParameter.ActualName + " could not be found.");
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs

    r3053 r3060  
    4646    /// <param name="parent2">The second parent for crossover.</param>
    4747    /// <returns>The newly created real vector, resulting from the single point crossover.</returns>
    48     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2) {
     48    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2) {
    4949      if (parent1.Length != parent2.Length) throw new ArgumentException("SinglePointCrossover: Parents are of unequal length");
    5050      int length = parent1.Length;
    51       DoubleArray result = new DoubleArray(length);
     51      RealVector result = new RealVector(length);
    5252      int breakPoint = random.Next(1, length - 1);
    5353
     
    6161
    6262    /// <summary>
    63     /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArray)"/>.
     63    /// Checks number of parents and forwards the call to <see cref="Apply(IRandom, RealVector, RealVector)"/>.
    6464    /// </summary>
    6565    /// <exception cref="ArgumentException">Thrown when the parents' vectors are of unequal length or when <paramref name="contiguity"/> is smaller than 0.</exception>
     
    6767    /// <param name="parents">The list of parents.</param>
    6868    /// <returns>A new real vector.</returns>
    69     protected override HeuristicLab.Data.DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     69    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    7070      if (parents.Length != 2) throw new ArgumentException("SinglePointCrossover: The number of parents is not equal to 2");
    7171      return Apply(random, parents[0], parents[1]);
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/UniformAllPositionsArithmeticCrossover.cs

    r3053 r3060  
    6161    /// <param name="alpha">The alpha parameter (<see cref="AlphaParameter"/>).</param>
    6262    /// <returns>The vector resulting from the crossover.</returns>
    63     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2, DoubleValue alpha) {
     63    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha) {
    6464      int length = parent1.Length;
    6565      if (length != parent2.Length) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: The parent vectors are of different length.", "parent1");
    6666      if (alpha.Value < 0 || alpha.Value > 1) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: Parameter alpha must be in the range [0;1]", "alpha");
    67       DoubleArray result = new DoubleArray(length);
     67      RealVector result = new RealVector(length);
    6868      for (int i = 0; i < length; i++) {
    6969        result[i] = alpha.Value * parent1[i] + (1 - alpha.Value) * parent2[i];
     
    7373
    7474    /// <summary>
    75     /// Checks that there are exactly 2 parents, that the alpha parameter is not null and fowards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArrrayData, DoubleValue)"/>.
     75    /// Checks that there are exactly 2 parents, that the alpha parameter is not null and fowards the call to <see cref="Apply(IRandom, RealVector, DoubleArrrayData, DoubleValue)"/>.
    7676    /// </summary>
    7777    /// <exception cref="ArgumentException">Thrown when there are not exactly two parents.</exception>
     
    8080    /// <param name="parents">The collection of parents (must be of size 2).</param>
    8181    /// <returns>The vector resulting from the crossover.</returns>
    82     protected override DoubleArray Cross(IRandom random, ItemArray<DoubleArray> parents) {
     82    protected override RealVector Cross(IRandom random, ItemArray<RealVector> parents) {
    8383      if (parents.Length != 2) throw new ArgumentException("UniformAllPositionsArithmeticCrossover: There must be exactly two parents.", "parents");
    8484      if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("UniformAllPositionsArithmeticCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
  • trunk/sources/HeuristicLab.Encodings.RealVectorEncoding/3.3/Crossovers/UniformSomePositionsArithmeticCrossover.cs

    r3053 r3060  
    6868    /// <param name="probability">The probability parameter (<see cref="ProbabilityParameter"/>).</param>
    6969    /// <returns>The vector resulting from the crossover.</returns>
    70     public static DoubleArray Apply(IRandom random, DoubleArray parent1, DoubleArray parent2, DoubleValue alpha, DoubleValue probability) {
     70    public static RealVector Apply(IRandom random, RealVector parent1, RealVector parent2, DoubleValue alpha, DoubleValue probability) {
    7171      int length = parent1.Length;
    7272      if (length != parent2.Length) throw new ArgumentException("UniformSomePositionsArithmeticCrossover: The parent vectors are of different length.", "parent1");
     
    7474      if (probability.Value < 0 || probability.Value > 1) throw new ArgumentException("UniformSomePositionsArithmeticCrossover: Parameter probability must be in the range [0;1]", "probability");
    7575     
    76       DoubleArray result = new DoubleArray(length);
     76      RealVector result = new RealVector(length);
    7777      for (int i = 0; i < length; i++) {
    7878        if (random.NextDouble() < probability.Value)
     
    8484
    8585    /// <summary>
    86     /// Checks that there are exactly 2 parents, that the alpha and the probability parameter are not null and fowards the call to <see cref="Apply(IRandom, DoubleArray, DoubleArrrayData, DoubleValue)"/>.
     86    /// Checks that there are exactly 2 parents, that the alpha and the probability parameter are not null and fowards the call to <see cref="Apply(IRandom, RealVector, DoubleArrrayData, DoubleValue)"/>.
    8787    /// </summary>
    8888    /// <exception cref="ArgumentException">Thrown when there are not exactly two parents.</exception>
     
    9191    /// <param name="parents">The collection of parents (must be of size 2).</param>
    9292    /// <returns>The vector resulting from the crossover.</returns>
    93     protected override DoubleArray  Cross(IRandom random, ItemArray<DoubleArray> parents) {
     93    protected override RealVector  Cross(IRandom random, ItemArray<RealVector> parents) {
    9494      if (parents.Length != 2) throw new ArgumentException("UniformSomePositionsArithmeticCrossover: There must be exactly two parents.", "parents");
    9595      if (AlphaParameter.ActualValue == null) throw new InvalidOperationException("UniformSomePositionsArithmeticCrossover: Parameter " + AlphaParameter.ActualName + " could not be found.");
Note: See TracChangeset for help on using the changeset viewer.