using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Operators; using HeuristicLab.Optimization; using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; namespace HeuristicLab.Algorithms.IslandALPS { /// ///
 
  ///          __ scope __                    __ scope __         
  ///         /           \                  /           \        
  ///       Island1      Island2     =>    Island1      Island2   
  ///       /    \         / \             /    \         / \     
  ///     L1     L2      L1     L2       L1     L2      L1     L2 
  ///     / \    / \     / \    / \      / \    / \     / \    / \
  ///    R  S   R  S    R  S   R  S     R  S   R  S    R  S   R  S
  ///   /|\ |  /|\ |   /|\ |  /|\ |    /|\ |  /|\ |   /|\ |  /|\ |
  ///   ABC A  DEF D   GHI G  JKL J    ABC J  DEF A   GHI D  JKL G                        
  /// 
  /// 
///
[Item("LayerMigrator", "Migrates the selected scopes of each layer to the correspondant layer of the next island (clockwise).")] [StorableClass] public class LayerMigrator : SingleSuccessorOperator, IMigrator { [StorableConstructor] public LayerMigrator(bool deserializing) : base(deserializing) {} public LayerMigrator(LayerMigrator original, Cloner cloner) : base(original, cloner) {} public LayerMigrator() {} public override IDeepCloneable Clone(Cloner cloner) { return new LayerMigrator(this,cloner); } public override IOperation Apply() { var globalScope = ExecutionContext.Scope; var openLayer = globalScope.SubScopes[0].SubScopes.Count; for (int layerIndex = 0; layerIndex < openLayer; layerIndex++) { IScope emigrants = null; for (int islandIndex = 0; islandIndex < globalScope.SubScopes.Count; islandIndex++) { var currentLayer = globalScope.SubScopes[islandIndex].SubScopes[layerIndex]; if (emigrants != null) { currentLayer.SubScopes.Add(emigrants); } emigrants = currentLayer.SubScopes[1]; currentLayer.SubScopes.Remove(emigrants); } //first island gets the individuals from the last island globalScope.SubScopes[0].SubScopes[layerIndex].SubScopes.Add(emigrants); } return base.Apply(); } } }