Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/17/12 15:05:11 (13 years ago)
Author:
abeham
Message:

#1775: reintegrated branch

Location:
trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding
Files:
4 edited
6 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding

  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs

    r7259 r8019  
    4545
    4646    /// <summary>
    47     /// Performs a discrete crossover operation of the two given parents.
     47    /// Performs a discrete crossover operation of any number of given parents.
    4848    /// </summary>
    4949    /// <exception cref="ArgumentException">Thrown when the vectors of the parents are of different length.</exception>
    5050    /// <param name="random">A random number generator.</param>
    51     /// <param name="parent1">The first parent for the crossover operation.</param>
    52     /// <param name="parent2">The second parent for the crossover operation.</param>
     51    /// <param name="parents">The list of parents for the crossover operation.</param>
    5352    /// <returns>The newly created integer vector, resulting from the crossover operation.</returns>
    54     public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) {
    55       if (parent1.Length != parent2.Length)
    56         throw new ArgumentException("DiscreteCrossover: The parents are of different length.");
     53    public static IntegerVector Apply(IRandom random, ItemArray<IntegerVector> parents) {
     54      int length = parents[0].Length;
    5755
    58       int length = parent1.Length;
    59       int[] result = new int[length];
     56      for (int i = 0; i < parents.Length; i++) {
     57        if (parents[i].Length != length)
     58          throw new ArgumentException("DiscreteCrossover: The parents' vectors are of different length.", "parents");
     59      }
    6060
     61      var result = new IntegerVector(length);
    6162      for (int i = 0; i < length; i++) {
    62         if (random.NextDouble() < 0.5)
    63           result[i] = parent1[i];
    64         else
    65           result[i] = parent2[i];
     63        result[i] = parents[random.Next(parents.Length)][i];
    6664      }
    67       return new IntegerVector(result);
     65
     66      return result;
    6867    }
    6968
    7069    /// <summary>
    71     /// Performs a discrete crossover operation for two given parent integer vectors.
     70    /// Performs a discrete crossover operation for any number of given parent integer vectors.
    7271    /// </summary>
    73     /// <exception cref="ArgumentException">Thrown if there are not exactly two parents.</exception>
    7472    /// <param name="random">A random number generator.</param>
    75     /// <param name="parents">An array containing the two integer vectors that should be crossed.</param>
     73    /// <param name="parents">An array containing integer vectors that should be crossed.</param>
    7674    /// <returns>The newly created integer vector, resulting from the crossover operation.</returns>
    7775    protected override IntegerVector Cross(IRandom random, ItemArray<IntegerVector> parents) {
    78       if (parents.Length != 2) throw new ArgumentException("ERROR in DiscreteCrossover: The number of parents is not equal to 2");
    79       return Apply(random, parents[0], parents[1]);
     76      return Apply(random, parents);
    8077    }
    8178  }
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs

    r7259 r8019  
    2525using HeuristicLab.Common;
    2626using HeuristicLab.Core;
     27using HeuristicLab.Data;
    2728using HeuristicLab.Operators;
    2829using HeuristicLab.Optimization;
     
    3435  [Item("MultiIntegerVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")]
    3536  [StorableClass]
    36   public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator {
     37  public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator, IBoundedIntegerVectorOperator {
    3738    public override bool CanChangeName {
    3839      get { return false; }
     
    4041    protected override bool CreateChildOperation {
    4142      get { return true; }
     43    }
     44
     45    public IValueLookupParameter<IntMatrix> BoundsParameter {
     46      get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; }
    4247    }
    4348
     
    5560    public MultiIntegerVectorCrossover()
    5661      : base() {
     62      Parameters.Add(new ValueLookupParameter<IntMatrix>("Bounds", "The bounds matrix can contain one row for each dimension with three columns specifying minimum (inclusive), maximum (exclusive), and step size. If less rows are given the matrix is cycled."));
    5763      Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Parents", "The parent integer vector which should be crossed."));
    5864      ParentsParameter.ActualName = "IntegerVector";
     
    8894        crossover.RandomParameter.ActualName = RandomParameter.Name;
    8995      }
     96      foreach (IBoundedIntegerVectorOperator crossover in Operators.OfType<IBoundedIntegerVectorOperator>()) {
     97        crossover.BoundsParameter.ActualName = BoundsParameter.Name;
     98      }
    9099    }
    91100
  • trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs

    r7259 r8019  
    5454    public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) {
    5555      if (parent1.Length != parent2.Length)
    56         throw new ArgumentException("DiscreteCrossover: The parents are of different length.");
     56        throw new ArgumentException("SinglePointCrossover: The parents are of different length.");
    5757
    5858      int length = parent1.Length;
Note: See TracChangeset for help on using the changeset viewer.