Last change
on this file since 70 was
70,
checked in by swagner, 17 years ago
|
Worked on ticket #15
- added crossover and manipulation operators implemented by adoppelb
|
File size:
871 bytes
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Text;
|
---|
4 | using HeuristicLab.Core;
|
---|
5 |
|
---|
6 | namespace HeuristicLab.RealVector {
|
---|
7 | class DiscreteCrossover : RealVectorCrossoverBase {
|
---|
8 | public override string Description {
|
---|
9 | get { return "Discrete crossover for real vectors."; }
|
---|
10 | }
|
---|
11 |
|
---|
12 | public static double[] Apply(IRandom random, double[] parent1, double[] parent2) {
|
---|
13 | int length = parent1.Length;
|
---|
14 | double[] result = new double[length];
|
---|
15 |
|
---|
16 | for (int i = 0; i < length; i++) {
|
---|
17 | if (random.NextDouble() < 0.5) {
|
---|
18 | result[i] = parent1[i];
|
---|
19 | } else {
|
---|
20 | result[i] = parent2[i];
|
---|
21 | }
|
---|
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.