Changeset 8085 for branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers
- Timestamp:
- 06/21/12 18:02:33 (12 years ago)
- Location:
- branches/GP-MoveOperators
- Files:
-
- 5 edited
- 6 copied
Legend:
- Unmodified
- Added
- Removed
-
branches/GP-MoveOperators
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
/trunk/sources/HeuristicLab.Encodings.IntegerVectorEncoding merged eligible /branches/Benchmarking/sources/HeuristicLab.Encodings.IntegerVectorEncoding 6917-7005 /branches/CloningRefactoring/HeuristicLab.Encodings.IntegerVectorEncoding 4656-4721 /branches/DataAnalysis Refactoring/HeuristicLab.Encodings.IntegerVectorEncoding 5471-5808 /branches/DataAnalysis SolutionEnsembles/HeuristicLab.Encodings.IntegerVectorEncoding 5815-6180 /branches/DataAnalysis/HeuristicLab.Encodings.IntegerVectorEncoding 4458-4459,4462,4464 /branches/GP.Grammar.Editor/HeuristicLab.Encodings.IntegerVectorEncoding 6284-6795 /branches/GP.Symbols (TimeLag, Diff, Integral)/HeuristicLab.Encodings.IntegerVectorEncoding 5060 /branches/IntegerVectorEncoding/HeuristicLab.Encodings.IntegerVectorEncoding 7681-8018 /branches/NET40/sources/HeuristicLab.Encodings.IntegerVectorEncoding 5138-5162 /branches/ParallelEngine/HeuristicLab.Encodings.IntegerVectorEncoding 5175-5192 /branches/ProblemInstancesRegressionAndClassification/HeuristicLab.Encodings.IntegerVectorEncoding 7568-7810 /branches/QAPAlgorithms/HeuristicLab.Encodings.IntegerVectorEncoding 6350-6627 /branches/Restructure trunk solution/HeuristicLab.Encodings.IntegerVectorEncoding 6828 /branches/SuccessProgressAnalysis/HeuristicLab.Encodings.IntegerVectorEncoding 5370-5682 /branches/Trunk/HeuristicLab.Encodings.IntegerVectorEncoding 6829-6865 /branches/VNS/HeuristicLab.Encodings.IntegerVectorEncoding 5594-5752 /branches/histogram/HeuristicLab.Encodings.IntegerVectorEncoding 5959-6341
-
Property
svn:mergeinfo
set to
(toggle deleted branches)
-
branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/DiscreteCrossover.cs
r7259 r8085 45 45 46 46 /// <summary> 47 /// Performs a discrete crossover operation of the twogiven parents.47 /// Performs a discrete crossover operation of any number of given parents. 48 48 /// </summary> 49 /// <exception cref="ArgumentException">Thrown when the vectors of the parents are of different length .</exception>49 /// <exception cref="ArgumentException">Thrown when the vectors of the parents are of different length or when there are less than 2 parents.</exception> 50 50 /// <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> 53 52 /// <returns>The newly created integer vector, resulting from the crossover operation.</returns> 54 public static IntegerVector Apply(IRandom random, I ntegerVector parent1, IntegerVector parent2) {55 if (parent 1.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 if (parents.Length < 2) throw new ArgumentException("DiscreteCrossover: There are less than two parents to cross."); 55 int length = parents[0].Length; 57 56 58 int length = parent1.Length; 59 int[] result = new int[length]; 57 for (int i = 0; i < parents.Length; i++) { 58 if (parents[i].Length != length) 59 throw new ArgumentException("DiscreteCrossover: The parents' vectors are of different length.", "parents"); 60 } 60 61 62 var result = new IntegerVector(length); 61 63 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]; 64 result[i] = parents[random.Next(parents.Length)][i]; 66 65 } 67 return new IntegerVector(result); 66 67 return result; 68 68 } 69 69 70 70 /// <summary> 71 /// Performs a discrete crossover operation for twogiven parent integer vectors.71 /// Performs a discrete crossover operation for any number of given parent integer vectors. 72 72 /// </summary> 73 /// <exception cref="ArgumentException">Thrown if there are not exactly two parents.</exception>74 73 /// <param name="random">A random number generator.</param> 75 /// <param name="parents">An array containing the twointeger vectors that should be crossed.</param>74 /// <param name="parents">An array containing integer vectors that should be crossed.</param> 76 75 /// <returns>The newly created integer vector, resulting from the crossover operation.</returns> 77 76 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]); 77 return Apply(random, parents); 80 78 } 81 79 } -
branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/MultiIntegerVectorCrossover.cs
r7259 r8085 25 25 using HeuristicLab.Common; 26 26 using HeuristicLab.Core; 27 using HeuristicLab.Data; 27 28 using HeuristicLab.Operators; 28 29 using HeuristicLab.Optimization; … … 34 35 [Item("MultiIntegerVectorCrossover", "Randomly selects and applies one of its crossovers every time it is called.")] 35 36 [StorableClass] 36 public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator {37 public class MultiIntegerVectorCrossover : StochasticMultiBranch<IIntegerVectorCrossover>, IIntegerVectorCrossover, IStochasticOperator, IBoundedIntegerVectorOperator { 37 38 public override bool CanChangeName { 38 39 get { return false; } … … 40 41 protected override bool CreateChildOperation { 41 42 get { return true; } 43 } 44 45 public IValueLookupParameter<IntMatrix> BoundsParameter { 46 get { return (IValueLookupParameter<IntMatrix>)Parameters["Bounds"]; } 42 47 } 43 48 … … 55 60 public MultiIntegerVectorCrossover() 56 61 : 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.")); 57 63 Parameters.Add(new ScopeTreeLookupParameter<IntegerVector>("Parents", "The parent integer vector which should be crossed.")); 58 64 ParentsParameter.ActualName = "IntegerVector"; … … 88 94 crossover.RandomParameter.ActualName = RandomParameter.Name; 89 95 } 96 foreach (IBoundedIntegerVectorOperator crossover in Operators.OfType<IBoundedIntegerVectorOperator>()) { 97 crossover.BoundsParameter.ActualName = BoundsParameter.Name; 98 } 90 99 } 91 100 -
branches/GP-MoveOperators/HeuristicLab.Encodings.IntegerVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r7259 r8085 54 54 public static IntegerVector Apply(IRandom random, IntegerVector parent1, IntegerVector parent2) { 55 55 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."); 57 57 58 58 int length = parent1.Length;
Note: See TracChangeset
for help on using the changeset viewer.