Changeset 16532 for branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3
- Timestamp:
- 01/14/19 22:33:44 (6 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3
- Files:
-
- 5 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/NPointCrossover.cs
r14429 r16532 25 25 using HeuristicLab.Core; 26 26 using HeuristicLab.Data; 27 using HeuristicLab.Optimization;28 27 using HeuristicLab.Parameters; 29 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 71 70 /// <param name="n">Number of crossover points.</param> 72 71 /// <returns>The newly created binary vector, resulting from the N point crossover.</returns> 73 public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, intn) {72 public static BinaryVector Apply(IRandom random, BinaryVector parent1, BinaryVector parent2, IntValue n) { 74 73 if (parent1.Length != parent2.Length) 75 74 throw new ArgumentException("NPointCrossover: The parents are of different length."); 76 75 77 if (n > parent1.Length)76 if (n.Value > parent1.Length) 78 77 throw new ArgumentException("NPointCrossover: There cannot be more breakpoints than the size of the parents."); 79 78 80 if (n < 1)79 if (n.Value < 1) 81 80 throw new ArgumentException("NPointCrossover: N cannot be < 1."); 82 81 83 82 int length = parent1.Length; 84 83 bool[] result = new bool[length]; 85 int[] breakpoints = new int[n ];84 int[] breakpoints = new int[n.Value]; 86 85 87 86 //choose break points … … 91 90 breakpointPool.Add(i); 92 91 93 for (int i = 0; i < n ; i++) {92 for (int i = 0; i < n.Value; i++) { 94 93 int index = random.Next(breakpointPool.Count); 95 94 breakpoints[i] = breakpointPool[index]; … … 138 137 if (NParameter.ActualValue == null) throw new InvalidOperationException("NPointCrossover: Parameter " + NParameter.ActualName + " could not be found."); 139 138 140 return Apply(random, parents[0], parents[1], NParameter.ActualValue.Value); 141 } 142 } 143 144 [Item("N-point Crossover", "", ExcludeGenericTypeInfo = true)] 145 [StorableClass] 146 public sealed class NPointCrossover<TContext> : ParameterizedNamedItem, IBinaryCrossover<TContext> 147 where TContext : IMatingContext<BinaryVector>, IStochasticContext { 148 149 [Storable] 150 private IValueParameter<IntValue> nparameter; 151 public int N { 152 get { return nparameter.Value.Value; } 153 set { 154 if (value < 1) throw new ArgumentException("Cannot set N to less than 1."); 155 nparameter.Value.Value = value; 156 } 157 } 158 159 [StorableConstructor] 160 private NPointCrossover(bool deserializing) : base(deserializing) { } 161 private NPointCrossover(NPointCrossover<TContext> original, Cloner cloner) 162 : base(original, cloner) { 163 nparameter = cloner.Clone(original.nparameter); 164 } 165 public NPointCrossover() { 166 Parameters.Add(nparameter = new ValueParameter<IntValue>("N", "The number of crossover points.", new IntValue(1))); 167 } 168 169 170 public override IDeepCloneable Clone(Cloner cloner) { 171 return new NPointCrossover<TContext>(this, cloner); 172 } 173 174 public void Cross(TContext context) { 175 context.Child.Solution = NPointCrossover.Apply(context.Random, context.Parents.Item1.Solution, context.Parents.Item2.Solution, N); 139 return Apply(random, parents[0], parents[1], NParameter.ActualValue); 176 140 } 177 141 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Crossovers/SinglePointCrossover.cs
r14429 r16532 57 57 if (parents.Length != 2) throw new ArgumentException("ERROR in SinglePointCrossover: The number of parents is not equal to 2"); 58 58 59 return NPointCrossover.Apply(random, parents[0], parents[1], 1);59 return NPointCrossover.Apply(random, parents[0], parents[1], new IntValue(1)); 60 60 } 61 61 } -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/HeuristicLab.Encodings.BinaryVectorEncoding-3.3.csproj
r14429 r16532 126 126 <Compile Include="Crossovers\NPointCrossover.cs" /> 127 127 <Compile Include="BinaryVector.cs" /> 128 <Compile Include="Interfaces\IBinaryLocalSearch.cs" />129 128 <Compile Include="Interfaces\IBinaryVectorMultiNeighborhoodShakingOperator.cs" /> 130 129 <Compile Include="Interfaces\IBinaryVectorSolutionsOperator.cs" /> … … 140 139 <Compile Include="BinaryVectorManipulator.cs" /> 141 140 <Compile Include="Interfaces\IBinaryVectorMoveOperator.cs" /> 142 <Compile Include="LocalSearch\ExhaustiveBitflip.cs" />143 <Compile Include="Manipulators\MultiBitflipManipulator.cs" />144 <Compile Include="Manipulators\SingleBitflipManipulator.cs" />145 <Compile Include="Manipulators\BitflipManipulator.cs" />146 141 <Compile Include="Manipulators\SomePositionsBitflipManipulator.cs" /> 147 142 <Compile Include="Manipulators\SinglePositionBitflipManipulator.cs" /> … … 210 205 <Name>HeuristicLab.PluginInfrastructure-3.3</Name> 211 206 <Private>False</Private> 212 </ProjectReference>213 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">214 <Project>{F4539FB6-4708-40C9-BE64-0A1390AEA197}</Project>215 <Name>HeuristicLab.Random-3.3</Name>216 207 </ProjectReference> 217 208 </ItemGroup> -
branches/2521_ProblemRefactoring/HeuristicLab.Encodings.BinaryVectorEncoding/3.3/Interfaces/IBinaryVectorCrossover.cs
r14429 r16532 22 22 using HeuristicLab.Core; 23 23 using HeuristicLab.Optimization; 24 using HeuristicLab.Optimization.Crossover;25 24 26 25 namespace HeuristicLab.Encodings.BinaryVectorEncoding { … … 32 31 ILookupParameter<BinaryVector> ChildParameter { get; } 33 32 } 34 35 // TODO: probably unecessary36 public interface IBinaryCrossover<TContext> : ICrossover<TContext> { }37 33 }
Note: See TracChangeset
for help on using the changeset viewer.