Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Hive_Milestone3/sources/HeuristicLab.SimOpt/3.2/SimOptCrossoverPreparator.cs @ 3005

Last change on this file since 3005 was 1706, checked in by abeham, 16 years ago

fixed a bug (#609)

File size: 1.2 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using HeuristicLab.Core;
6using HeuristicLab.Data;
7
8namespace 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[0];
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.