[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[3404] | 3 | * Copyright (C) 2002-2010 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[2] | 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 |
|
---|
| 22 | using System.Collections.Generic;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[3404] | 24 | using HeuristicLab.Optimization;
|
---|
| 25 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[2] | 26 |
|
---|
| 27 | namespace HeuristicLab.Selection {
|
---|
[817] | 28 | /// <summary>
|
---|
[3404] | 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).
|
---|
[850] | 31 | /// <pre>
|
---|
[3404] | 32 | /// scope scope
|
---|
| 33 | /// / \ / \
|
---|
| 34 | /// R S(1) => R S
|
---|
| 35 | /// / \ \ /|\ /|\
|
---|
| 36 | /// R(3) S(2) C ABCDEF CDEF
|
---|
| 37 | /// /|\ /|\
|
---|
| 38 | /// ABCDEF DEF
|
---|
[850] | 39 | /// </pre>
|
---|
[817] | 40 | /// </summary>
|
---|
[3404] | 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 {
|
---|
[817] | 44 | /// <summary>
|
---|
[3404] | 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.
|
---|
[817] | 47 | /// </summary>
|
---|
| 48 | /// <param name="scope">The current scope to reduce.</param>
|
---|
| 49 | /// <returns>A list of the new reduced sub scopes.</returns>
|
---|
[3404] | 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];
|
---|
[2] | 55 |
|
---|
[3404] | 56 | // merge right children
|
---|
| 57 | while (leftRightChild.SubScopes.Count > 0)
|
---|
| 58 | rightChild.SubScopes.Add(leftRightChild.SubScopes[0]);
|
---|
[2] | 59 |
|
---|
[3404] | 60 | leftChild = leftChild.SubScopes[0];
|
---|
| 61 | }
|
---|
[2] | 62 | List<IScope> subScopes = new List<IScope>();
|
---|
| 63 | subScopes.Add(leftChild);
|
---|
| 64 | subScopes.Add(rightChild);
|
---|
| 65 | return subScopes;
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | }
|
---|