Last change
on this file since 77 was
73,
checked in by swagner, 17 years ago
|
Worked on ticket #15
- adapted interfaces of static Apply methods
- added missing variable info Maximization in HeuristicCrossover
- simplified code
|
File size:
870 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 | using HeuristicLab.Data;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.RealVector {
|
---|
8 | class RandomConvexCrossover : RealVectorCrossoverBase {
|
---|
9 | public override string Description {
|
---|
10 | get { return "Random convex crossover for real vectors."; }
|
---|
11 | }
|
---|
12 |
|
---|
13 | public static double[] Apply(IRandom random, double[] parent1, double[] parent2) {
|
---|
14 | int length = parent1.Length;
|
---|
15 | double[] result = new double[length];
|
---|
16 | double factor = random.NextDouble();
|
---|
17 |
|
---|
18 | for (int i = 0; i < length; i++)
|
---|
19 | result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]);
|
---|
20 | return result;
|
---|
21 | }
|
---|
22 |
|
---|
23 | protected override double[] Cross(IScope scope, IRandom random, double[] parent1, double[] parent2) {
|
---|
24 | return Apply(random, parent1, parent2);
|
---|
25 | }
|
---|
26 | }
|
---|
27 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.