Changeset 13078 for trunk/sources
- Timestamp:
- 10/29/15 11:09:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Optimization.Operators/3.3/UnidirectionalRingMigrator.cs
r12012 r13078 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> ClockwiseMigrationDirectionParameter { 38 get { return (IValueLookupParameter<BoolValue>)Parameters["ClockwiseMigrationDirection"]; } 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>("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 } 40 60 public override IDeepCloneable Clone(Cloner cloner) { 41 61 return new UnidirectionalRingMigrator(this, cloner); … … 56 76 /// <returns>The next operation.</returns> 57 77 public override IOperation Apply() { 78 bool clockwise = ClockwiseMigrationDirectionParameter.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.