Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Selection/3.3/RightChildReducer.cs @ 3923

Last change on this file since 3923 was 3404, checked in by abeham, 15 years ago

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

File size: 3.0 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Collections.Generic;
23using HeuristicLab.Core;
24using HeuristicLab.Optimization;
25using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
26
27namespace HeuristicLab.Selection {
28  /// <summary>
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).
31  /// <pre>                                                     
32  ///                  scope            scope 
33  ///                   / \             /   \     
34  ///                  R   S(1)   =>   R     S                 
35  ///                 / \     \       /|\   /|\       
36  ///               R(3) S(2)  C     ABCDEF  CDEF     
37  ///               /|\  /|\                             
38  ///             ABCDEF DEF                             
39  /// </pre>
40  /// </summary>
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 {
44    /// <summary>
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.
47    /// </summary>
48    /// <param name="scope">The current scope to reduce.</param>
49    /// <returns>A list of the new reduced sub scopes.</returns>
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];
55
56        // merge right children
57        while (leftRightChild.SubScopes.Count > 0)
58          rightChild.SubScopes.Add(leftRightChild.SubScopes[0]);
59
60        leftChild = leftChild.SubScopes[0];
61      }
62      List<IScope> subScopes = new List<IScope>();
63      subScopes.Add(leftChild);
64      subScopes.Add(rightChild);
65      return subScopes;
66    }
67  }
68}
Note: See TracBrowser for help on using the repository browser.