1 | using HeuristicLab.Common;
|
---|
2 | using HeuristicLab.Core;
|
---|
3 | using HeuristicLab.Operators;
|
---|
4 | using HeuristicLab.Optimization;
|
---|
5 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
6 |
|
---|
7 | namespace HeuristicLab.Algorithms.IslandALPS {
|
---|
8 |
|
---|
9 | /// <summary>
|
---|
10 | /// <pre>
|
---|
11 | /// __ scope __ __ scope __
|
---|
12 | /// / \ / \
|
---|
13 | /// Island1 Island2 => Island1 Island2
|
---|
14 | /// / \ / \ / \ / \
|
---|
15 | /// L1 L2 L1 L2 L1 L2 L1 L2
|
---|
16 | /// / \ / \ / \ / \ / \ / \ / \ / \
|
---|
17 | /// R S R S R S R S R S R S R S R S
|
---|
18 | /// /|\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|\ | /|\ |
|
---|
19 | /// ABC A DEF D GHI G JKL J ABC J DEF A GHI D JKL G
|
---|
20 | ///
|
---|
21 | /// </pre>
|
---|
22 | /// </summary>
|
---|
23 | [Item("LayerMigrator", "Migrates the selected scopes of each layer to the correspondant layer of the next island (clockwise).")]
|
---|
24 | [StorableClass]
|
---|
25 | public class LayerMigrator : SingleSuccessorOperator, IMigrator {
|
---|
26 |
|
---|
27 | [StorableConstructor]
|
---|
28 | public LayerMigrator(bool deserializing) : base(deserializing) {}
|
---|
29 | public LayerMigrator(LayerMigrator original, Cloner cloner) : base(original, cloner) {}
|
---|
30 | public LayerMigrator() {}
|
---|
31 |
|
---|
32 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
33 | return new LayerMigrator(this,cloner);
|
---|
34 | }
|
---|
35 |
|
---|
36 | public override IOperation Apply() {
|
---|
37 | var globalScope = ExecutionContext.Scope;
|
---|
38 | var openLayer = globalScope.SubScopes[0].SubScopes.Count;
|
---|
39 |
|
---|
40 | for (int layerIndex = 0; layerIndex < openLayer; layerIndex++) {
|
---|
41 | IScope emigrants = null;
|
---|
42 | for (int islandIndex = 0; islandIndex < globalScope.SubScopes.Count; islandIndex++) {
|
---|
43 | var currentLayer = globalScope.SubScopes[islandIndex].SubScopes[layerIndex];
|
---|
44 | if (emigrants != null) {
|
---|
45 | currentLayer.SubScopes.Add(emigrants);
|
---|
46 | }
|
---|
47 | emigrants = currentLayer.SubScopes[1];
|
---|
48 | currentLayer.SubScopes.Remove(emigrants);
|
---|
49 | }
|
---|
50 | //first island gets the individuals from the last island
|
---|
51 | globalScope.SubScopes[0].SubScopes[layerIndex].SubScopes.Add(emigrants);
|
---|
52 | }
|
---|
53 |
|
---|
54 | return base.Apply();
|
---|
55 | }
|
---|
56 | }
|
---|
57 | }
|
---|