Changeset 3451


Ignore:
Timestamp:
04/20/10 19:17:14 (11 years ago)
Author:
abeham
Message:

Added commented version of SASEGASAReunificator #839

Location:
trunk/sources/HeuristicLab.Optimization.Operators/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj

    r3425 r3451  
    8383    <Compile Include="ProbabilisticQualityComparator.cs" />
    8484    <Compile Include="ResultsCollector.cs" />
     85    <Compile Include="SASEGASAReunificator.cs" />
    8586    <Compile Include="SquareRootDiscreteDoubleValueModifier.cs" />
    8687    <Compile Include="DiscreteDoubleValueModifier.cs" />
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/SASEGASAReunificator.cs

    r1529 r3451  
    11#region License Information
    22/* HeuristicLab
    3  * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
     3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
    44 *
    55 * This file is part of HeuristicLab.
     
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Text;
     24using HeuristicLab.Common;
    2525using HeuristicLab.Core;
    26 using HeuristicLab.Data;
     26using HeuristicLab.Operators;
     27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2728
    28 namespace HeuristicLab.Evolutionary {
     29namespace HeuristicLab.Optimization.Operators {
    2930  /// <summary>
    3031  /// Joins all sub sub scopes of a specified scope, reduces the number of sub
    3132  /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order.
    3233  /// </summary>
    33   public class SASEGASAReunificator : OperatorBase {
    34     /// <inheritdoc select="summary"/>
    35     public override string Description {
    36       get { return @"TODO\r\nOperator description still missing ..."; }
    37     }
     34  /*[Item("SASEGASAReunificator", "This operator merges the villages in a migration phase and redistributes the individuals. It is implemented as described in Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications, CRC Press.")]
     35  [StorableClass]
     36  public class SASEGASAReunificator : SingleSuccessorOperator, IMigrator {
    3837
    3938    /// <summary>
     
    4443    /// <param name="scope">The current scope whose sub scopes to reduce.</param>
    4544    /// <returns><c>null</c>.</returns>
    46     public override IOperation Apply(IScope scope) {
    47       int subScopes = scope.SubScopes.Count;
    48       if (subScopes <= 1)
     45    public override IOperation Apply() {
     46      IScope scope = ExecutionContext.Scope;
     47      int villageCount = scope.SubScopes.Count;
     48      if (villageCount <= 1)
    4949        throw new InvalidOperationException("SASEGASA reunification requires 2 or more sub-scopes");
    5050
    51       // get all sub-sub-scopes
    52       IList<IScope> subSubScopes = new List<IScope>();
    53       for (int i = 0; i < scope.SubScopes.Count; i++) {
    54         while (scope.SubScopes[i].SubScopes.Count > 0) {
    55           subSubScopes.Add(scope.SubScopes[i].SubScopes[0]);
    56           scope.SubScopes[i].RemoveSubScope(scope.SubScopes[i].SubScopes[0]);
     51      // get all villages
     52      IList<IScope> population = new List<IScope>();
     53      for (int i = 0; i < villageCount; i++) {
     54        while (scope.SubScopes[i].SubScopes[0].SubScopes.Count > 0) {
     55          population.Add(scope.SubScopes[i].SubScopes[0].SubScopes[0]);
     56          scope.SubScopes[i].SubScopes.Remove(scope.SubScopes[i].SubScopes[0].SubScopes[0]);
    5757        }
     58        scope.SubScopes[i].SubScopes.Clear();
    5859      }
    5960
    60       // reduce number of sub-scopes by 1 and partition sub-sub-scopes again
    61       scope.RemoveSubScope(scope.SubScopes[scope.SubScopes.Count - 1]);
    62       subScopes--;
    63       int subSubScopesCount = subSubScopes.Count / subScopes;
    64       for (int i = 0; i < subScopes; i++) {
    65         for (int j = 0; j < subSubScopesCount; j++) {
    66           scope.SubScopes[i].AddSubScope(subSubScopes[0]);
    67           subSubScopes.RemoveAt(0);
     61      // reduce number of villages by 1 and partition the population again
     62      scope.SubScopes.Remove(scope.SubScopes[scope.SubScopes.Count - 1]);
     63      villageCount--;
     64      int populationPerVillage = population.Count / villageCount;
     65      for (int i = 0; i < villageCount; i++) {
     66        scope.SubScopes[i].SubScopes.Add(new Scope());
     67        scope.SubScopes[i].SubScopes.Add(new Scope());
     68        for (int j = 0; j < populationPerVillage; j++) {
     69          scope.SubScopes[i].SubScopes[1].SubScopes.Add(population[0]);
     70          population.RemoveAt(0);
    6871        }
    6972      }
    7073
    7174      // add remaining sub-sub-scopes to last sub-scope
    72       while (subSubScopes.Count > 0) {
    73         scope.SubScopes[scope.SubScopes.Count - 1].AddSubScope(subSubScopes[0]);
    74         subSubScopes.RemoveAt(0);
     75      while (population.Count > 0) {
     76        scope.SubScopes[scope.SubScopes.Count - 1].SubScopes[1].SubScopes.Add(population[0]);
     77        population.RemoveAt(0);
    7578      }
    7679
    77       return null;
     80      return base.Apply();
    7881    }
    79   }
     82  }*/
    8083}
Note: See TracChangeset for help on using the changeset viewer.