Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Linq;
|
---|
4 | using System.Text;
|
---|
5 | using HeuristicLab.Core;
|
---|
6 | using HeuristicLab.Data;
|
---|
7 |
|
---|
8 | namespace HeuristicLab.SimOpt {
|
---|
9 | public class SimOptCrossoverPreparator : OperatorBase {
|
---|
10 | public override string Description {
|
---|
11 | get {
|
---|
12 | return @"Prepares the parent parameters for crossing";
|
---|
13 | }
|
---|
14 | }
|
---|
15 |
|
---|
16 | public SimOptCrossoverPreparator()
|
---|
17 | : base() {
|
---|
18 | }
|
---|
19 |
|
---|
20 | public override IOperation Apply(IScope scope) {
|
---|
21 | int parents = scope.SubScopes.Count;
|
---|
22 | int parameters = scope.SubScopes[0].SubScopes.Count;
|
---|
23 | // remove the parents and add them to a temporary list
|
---|
24 | IList<IScope> parentsScopes = new List<IScope>();
|
---|
25 | while (scope.SubScopes.Count > 0) {
|
---|
26 | IScope tmp = scope.SubScopes[0];
|
---|
27 | scope.RemoveSubScope(tmp);
|
---|
28 | parentsScopes.Add(tmp);
|
---|
29 | }
|
---|
30 |
|
---|
31 | for (int i = 0; i < parameters; i++) {
|
---|
32 | scope.AddSubScope(new Scope("Parameters_" + (i + 1).ToString()));
|
---|
33 | for (int k = 0; k < parents; k++) {
|
---|
34 | IScope param = parentsScopes[k].SubScopes[i];
|
---|
35 | parentsScopes[k].RemoveSubScope(param);
|
---|
36 | scope.SubScopes[i].AddSubScope(param);
|
---|
37 | }
|
---|
38 | }
|
---|
39 | return null;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
Note: See
TracBrowser
for help on using the repository browser.