Free cookie consent management tool by TermsFeed Policy Generator

Changeset 13134


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

#2495 merged r13078, r13094 and r13109 into stable

Location:
stable
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.GeneticAlgorithm/3.3/IslandGeneticAlgorithm.cs

    r12708 r13134  
    339339      ParameterizeSelectors();
    340340
    341       foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
     341      foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name)) {
     342        // BackwardsCompatibility3.3
     343        // Set the migration direction to counterclockwise
     344        var unidirectionalRing = migrator as UnidirectionalRingMigrator;
     345        if (unidirectionalRing != null) unidirectionalRing.ClockwiseMigrationParameter.Value = new BoolValue(false);
    342346        MigratorParameter.ValidValues.Add(migrator);
     347      }
    343348
    344349      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
  • stable/HeuristicLab.Algorithms.OffspringSelectionGeneticAlgorithm/3.3/IslandOffspringSelectionGeneticAlgorithm.cs

    r12708 r13134  
    405405      ParameterizeSelectors();
    406406
    407       foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name))
     407      foreach (IMigrator migrator in ApplicationManager.Manager.GetInstances<IMigrator>().OrderBy(x => x.Name)) {
     408        // BackwardsCompatibility3.3
     409        // Set the migration direction to counterclockwise
     410        var unidirectionalRing = migrator as UnidirectionalRingMigrator;
     411        if (unidirectionalRing != null) unidirectionalRing.ClockwiseMigrationParameter.Value = new BoolValue(false);
    408412        MigratorParameter.ValidValues.Add(migrator);
     413      }
    409414
    410415      foreach (IDiscreteDoubleValueModifier modifier in ApplicationManager.Manager.GetInstances<IDiscreteDoubleValueModifier>().OrderBy(x => x.Name))
  • 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.