Free cookie consent management tool by TermsFeed Policy Generator

source: tags/3.3.1/HeuristicLab.Selection/3.3/RightChildReducer.cs @ 14185

Last change on this file since 14185 was 4489, checked in by gkronber, 14 years ago

Removed code fragments from class Scope which updated the SubScopes list when setting the parent property of a scope. ##1207

File size: 3.1 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          IScope leftRightChildChild = leftRightChild.SubScopes[0];
59          leftRightChild.SubScopes.RemoveAt(0);
60          rightChild.SubScopes.Add(leftRightChildChild);
61        }
62
63        leftChild = leftChild.SubScopes[0];
64      }
65      List<IScope> subScopes = new List<IScope>();
66      subScopes.Add(leftChild);
67      subScopes.Add(rightChild);
68      return subScopes;
69    }
70  }
71}
Note: See TracBrowser for help on using the repository browser.