Last change
on this file since 77 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:
883 bytes
|
Rev | Line | |
---|
[70] | 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 {
|
---|
[74] | 8 | class LocalCrossover : RealVectorCrossoverBase {
|
---|
[70] | 9 | public override string Description {
|
---|
[74] | 10 | get { return "Local crossover for real vectors."; }
|
---|
[70] | 11 | }
|
---|
| 12 |
|
---|
[73] | 13 | public static double[] Apply(IRandom random, double[] parent1, double[] parent2) {
|
---|
[70] | 14 | double factor;
|
---|
| 15 | int length = parent1.Length;
|
---|
| 16 | double[] result = new double[length];
|
---|
| 17 |
|
---|
| 18 | for (int i = 0; i < length; i++) {
|
---|
| 19 | factor = random.NextDouble();
|
---|
| 20 | result[i] = (factor * parent1[i]) + ((1 - factor) * parent2[i]);
|
---|
| 21 | }
|
---|
| 22 | return result;
|
---|
| 23 | }
|
---|
| 24 |
|
---|
| 25 | protected override double[] Cross(IScope scope, IRandom random, double[] parent1, double[] parent2) {
|
---|
[73] | 26 | return Apply(random, parent1, parent2);
|
---|
[70] | 27 | }
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.