Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
11/10/15 15:51:54 (9 years ago)
Author:
ascheibe
Message:

#2495 merged r13078, r13094 and r13109 into stable

Location:
stable
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Optimization.Operators/3.3/UnidirectionalRingMigrator.cs

    r12009 r13134  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Data;
    2526using HeuristicLab.Operators;
     27using HeuristicLab.Parameters;
    2628using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
     
    3335  [StorableClass]
    3436  public class UnidirectionalRingMigrator : SingleSuccessorOperator, IMigrator {
     37    public IValueLookupParameter<BoolValue> ClockwiseMigrationParameter {
     38      get { return (IValueLookupParameter<BoolValue>)Parameters["ClockwiseMigration"]; }
     39    }
     40
    3541    [StorableConstructor]
    3642    protected UnidirectionalRingMigrator(bool deserializing) : base(deserializing) { }
    3743    protected UnidirectionalRingMigrator(UnidirectionalRingMigrator original, Cloner cloner) : base(original, cloner) { }
    38     public UnidirectionalRingMigrator() : base() { }
    3944
     45    public UnidirectionalRingMigrator()
     46      : base() {
     47      Parameters.Add(new ValueLookupParameter<BoolValue>("ClockwiseMigration", "True to migrate individuals clockwise, false to migrate individuals counterclockwise.", new BoolValue(true)));
     48    }
     49
     50    [StorableHook(HookType.AfterDeserialization)]
     51    private void AfterDeserialization() {
     52      // BackwardsCompatibility3.3
     53      #region Backwards compatible code (remove with 3.4)
     54      if (!Parameters.ContainsKey("ClockwiseMigration")) {
     55        Parameters.Add(new ValueLookupParameter<BoolValue>("ClockwiseMigration", "True to migrate individuals clockwise, false to migrate individuals counterclockwise.", new BoolValue(false)));
     56      }
     57      #endregion
     58    }
    4059    public override IDeepCloneable Clone(Cloner cloner) {
    4160      return new UnidirectionalRingMigrator(this, cloner);
     
    4362
    4463    /// <summary>
    45     /// Migrates every first sub scope of each child to its left neighbour (like a ring).
    46     /// <pre>                                                               
     64    /// Migrates every first sub scope of each child to its right or left neighbour (like a ring).
     65    /// If clockwise migration (default) is used the selected scopes A D G becomes G A D, contrary to counterclockwise where A D G becomes D G A.
     66    /// <pre>
    4767    ///          __ scope __              __ scope __
    4868    ///         /     |     \            /     |     \
     
    5676    /// <returns>The next operation.</returns>
    5777    public override IOperation Apply() {
     78      bool clockwise = ClockwiseMigrationParameter.ActualValue.Value;
    5879      IScope scope = ExecutionContext.Scope;
    5980      List<IScope> emigrantsList = new List<IScope>();
     
    6586      }
    6687
    67       // shift first emigrants to end of list
    68       emigrantsList.Add(emigrantsList[0]);
    69       emigrantsList.RemoveAt(0);
     88      if (clockwise) {
     89        // shift last emigrants to start of list
     90        emigrantsList.Insert(0, emigrantsList[emigrantsList.Count - 1]);
     91        emigrantsList.RemoveAt(emigrantsList.Count - 1);
     92      } else {
     93        // shift first emigrants to end of list
     94        emigrantsList.Add(emigrantsList[0]);
     95        emigrantsList.RemoveAt(0);
     96      }
    7097
    7198      for (int i = 0; i < scope.SubScopes.Count; i++)
Note: See TracChangeset for help on using the changeset viewer.