Changeset 13134 for stable/HeuristicLab.Optimization.Operators/3.3
- Timestamp:
- 11/10/15 15:51:54 (9 years ago)
- Location:
- stable
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 13078,13094,13109
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Optimization.Operators/3.3/UnidirectionalRingMigrator.cs
r12009 r13134 23 23 using HeuristicLab.Common; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Data; 25 26 using HeuristicLab.Operators; 27 using HeuristicLab.Parameters; 26 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 29 … … 33 35 [StorableClass] 34 36 public class UnidirectionalRingMigrator : SingleSuccessorOperator, IMigrator { 37 public IValueLookupParameter<BoolValue> ClockwiseMigrationParameter { 38 get { return (IValueLookupParameter<BoolValue>)Parameters["ClockwiseMigration"]; } 39 } 40 35 41 [StorableConstructor] 36 42 protected UnidirectionalRingMigrator(bool deserializing) : base(deserializing) { } 37 43 protected UnidirectionalRingMigrator(UnidirectionalRingMigrator original, Cloner cloner) : base(original, cloner) { } 38 public UnidirectionalRingMigrator() : base() { }39 44 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 } 40 59 public override IDeepCloneable Clone(Cloner cloner) { 41 60 return new UnidirectionalRingMigrator(this, cloner); … … 43 62 44 63 /// <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> 47 67 /// __ scope __ __ scope __ 48 68 /// / | \ / | \ … … 56 76 /// <returns>The next operation.</returns> 57 77 public override IOperation Apply() { 78 bool clockwise = ClockwiseMigrationParameter.ActualValue.Value; 58 79 IScope scope = ExecutionContext.Scope; 59 80 List<IScope> emigrantsList = new List<IScope>(); … … 65 86 } 66 87 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 } 70 97 71 98 for (int i = 0; i < scope.SubScopes.Count; i++)
Note: See TracChangeset
for help on using the changeset viewer.