Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2258_IslandALPS/IslandALPS/3.3/LayerMigrator.cs @ 16003

Last change on this file since 16003 was 13604, checked in by pkuelzer, 9 years ago

#2558 Include LayerNumber in GroupResults
Added Migration

File size: 2.3 KB
Line 
1using HeuristicLab.Common;
2using HeuristicLab.Core;
3using HeuristicLab.Operators;
4using HeuristicLab.Optimization;
5using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
6
7namespace 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}
Note: See TracBrowser for help on using the repository browser.