Last change
on this file since 94 was
74,
checked in by swagner, 17 years ago
|
Worked on ticket #15
- renamed crossover operators for real vectors according to lecture slides of maffenze
|
File size:
918 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 ContinuousCrossover : RealVectorCrossoverBase {
|
---|
9 | public override string Description {
|
---|
10 | get { return "Continuous 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 |
|
---|
17 | for (int i = 0; i < length; i++) {
|
---|
18 | if (random.NextDouble() < 0.5) {
|
---|
19 | result[i] = (parent1[i] + parent2[i]) / 2;
|
---|
20 | } else {
|
---|
21 | result[i] = parent1[i];
|
---|
22 | }
|
---|
23 | }
|
---|
24 | return result;
|
---|
25 | }
|
---|
26 |
|
---|
27 | protected override double[] Cross(IScope scope, IRandom random, double[] parent1, double[] parent2) {
|
---|
28 | return Apply(random, parent1, parent2);
|
---|
29 | }
|
---|
30 | }
|
---|
31 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.