Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/19/10 01:51:50 (14 years ago)
Author:
abeham
Message:

Added gender specific selection and ported the necessary operators RightChildReducer and SubScopesMixer #976

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs

    r1530 r3404  
    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.
     
    2020#endregion
    2121
    22 using System;
    2322using System.Collections.Generic;
    24 using System.Text;
    2523using HeuristicLab.Core;
    26 using HeuristicLab.Operators;
     24using HeuristicLab.Optimization;
     25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2726
    2827namespace HeuristicLab.Selection {
    2928  /// <summary>
    30   /// Reduces the sub scopes by one level, so that the right sub scope contains also the right child scopes
    31   /// of the left sub scope and the left sub scope represents its left child scope.
     29  /// Reduces the sub-scopes, so that the selected sub-scope contains all selected leaves (1) and (2)
     30  /// and the remaining sub-scope contains the sub-scopes of the bottom-most remaining scope (3).
    3231  /// <pre>                                                     
    33   ///                   scope             scope 
    34   ///                   / | \             /   \     
    35   ///                  L ... R   =>      A     R                 
    36   ///                / | \    \              / /\ \       
    37   ///               A ... LR   C             C D E F     
    38   ///                     /|\                             
    39   ///                    D E F                             
     32  ///                  scope            scope 
     33  ///                   / \             /   \     
     34  ///                  R   S(1)   =>   R     S                 
     35  ///                 / \     \       /|\   /|\       
     36  ///               R(3) S(2)  C     ABCDEF  CDEF     
     37  ///               /|\  /|\                             
     38  ///             ABCDEF DEF                             
    4039  /// </pre>
    4140  /// </summary>
    42   public class RightChildReducer : ReducerBase {
    43     /// <inheritdoc select="summary"/>
    44     public override string Description {
    45       get { return @"TODO\r\nOperator description still missing ..."; }
    46     }
    47 
     41  [Item("RightChildReducer", "Merges all sub-scopes generated by successively selecting sub-scopes of the remaining part.")]
     42  [StorableClass]
     43  public class RightChildReducer : Reducer, IReducer {
    4844    /// <summary>
    49     /// Reduces the right child of the left sub scope and adds its sub scopes to the right sub scope.
    50     /// The left sub scope is also narrowed, which means it represents then its left child.
     45    ///  Reduces the sub-scopes, so that the selected sub-scope contains all selected leaves
     46    /// and the remaining sub-scope contains the sub-scopes of the bottom-most remaining scope.
    5147    /// </summary>
    5248    /// <param name="scope">The current scope to reduce.</param>
    5349    /// <returns>A list of the new reduced sub scopes.</returns>
    54     protected override ICollection<IScope> Reduce(IScope scope) {
    55       IScope rightChild = scope.SubScopes[scope.SubScopes.Count - 1];
    56       IScope leftChild = scope.SubScopes[0];
    57       IScope leftRightChild = leftChild.SubScopes[leftChild.SubScopes.Count - 1];
     50    protected override List<IScope> Reduce(List<IScope> scopes) {
     51      IScope rightChild = scopes[scopes.Count - 1];
     52      IScope leftChild = scopes[0];
     53      while (leftChild.SubScopes.Count > 1 && leftChild.SubScopes[0].SubScopes.Count > 0) {
     54        IScope leftRightChild = leftChild.SubScopes[leftChild.SubScopes.Count - 1];
    5855
    59       // merge right children
    60       for (int i = 0; i < leftRightChild.SubScopes.Count; i++)
    61         rightChild.AddSubScope(leftRightChild.SubScopes[i]);
     56        // merge right children
     57        while (leftRightChild.SubScopes.Count > 0)
     58          rightChild.SubScopes.Add(leftRightChild.SubScopes[0]);
    6259
    63       leftChild = leftChild.SubScopes[0];
    64 
     60        leftChild = leftChild.SubScopes[0];
     61      }
    6562      List<IScope> subScopes = new List<IScope>();
    6663      subScopes.Add(leftChild);
Note: See TracChangeset for help on using the changeset viewer.