Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13078 for trunk/sources


Ignore:
Timestamp:
10/29/15 11:09:31 (9 years ago)
Author:
pfleck
Message:

#2495

  • Added ClockwiseMigrationDirection Parameter.
  • Added backwards compatability hook that use the old counterclockwise migration.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/UnidirectionalRingMigrator.cs

    r12012 r13078  
    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> ClockwiseMigrationDirectionParameter {
     38      get { return (IValueLookupParameter<BoolValue>)Parameters["ClockwiseMigrationDirection"]; }
     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>("ClockwiseMigrationDirection", "True to migrate individuals clockwise, otherwise migrate individuals counterclockwise.", new BoolValue(true)));
     48    }
     49
     50
     51    [StorableHook(HookType.AfterDeserialization)]
     52    private void AfterDeserialization() {
     53      // BackwardsCompatibility3.3
     54      #region Backwards compatible code (remove with 3.4)
     55      if (!Parameters.ContainsKey("ClockwiseMigrationDirection")) {
     56        Parameters.Add(new ValueLookupParameter<BoolValue>("ClockwiseMigrationDirection", "True to migrate individuals clockwise, otherwise migrate individuals counterclockwise.", new BoolValue(false)));
     57      }
     58      #endregion
     59    }
    4060    public override IDeepCloneable Clone(Cloner cloner) {
    4161      return new UnidirectionalRingMigrator(this, cloner);
     
    5676    /// <returns>The next operation.</returns>
    5777    public override IOperation Apply() {
     78      bool clockwise = ClockwiseMigrationDirectionParameter.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.