[2] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[17181] | 3 | * Copyright (C) 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;
|
---|
[4722] | 23 | using HeuristicLab.Common;
|
---|
[2] | 24 | using HeuristicLab.Core;
|
---|
[3404] | 25 | using HeuristicLab.Optimization;
|
---|
[17097] | 26 | using HEAL.Attic;
|
---|
[2] | 27 |
|
---|
| 28 | namespace HeuristicLab.Selection {
|
---|
[817] | 29 | /// <summary>
|
---|
[3404] | 30 | /// Reduces the sub-scopes, so that the selected sub-scope contains all selected leaves (1) and (2)
|
---|
| 31 | /// and the remaining sub-scope contains the sub-scopes of the bottom-most remaining scope (3).
|
---|
[850] | 32 | /// <pre>
|
---|
[3404] | 33 | /// scope scope
|
---|
| 34 | /// / \ / \
|
---|
| 35 | /// R S(1) => R S
|
---|
| 36 | /// / \ \ /|\ /|\
|
---|
| 37 | /// R(3) S(2) C ABCDEF CDEF
|
---|
| 38 | /// /|\ /|\
|
---|
| 39 | /// ABCDEF DEF
|
---|
[850] | 40 | /// </pre>
|
---|
[817] | 41 | /// </summary>
|
---|
[3404] | 42 | [Item("RightChildReducer", "Merges all sub-scopes generated by successively selecting sub-scopes of the remaining part.")]
|
---|
[17097] | 43 | [StorableType("D1857728-A661-46BE-AA08-CDF830DD81A8")]
|
---|
[3404] | 44 | public class RightChildReducer : Reducer, IReducer {
|
---|
[4722] | 45 | [StorableConstructor]
|
---|
[17097] | 46 | protected RightChildReducer(StorableConstructorFlag _) : base(_) { }
|
---|
[4722] | 47 | protected RightChildReducer(RightChildReducer original, Cloner cloner) : base(original, cloner) { }
|
---|
| 48 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 49 | return new RightChildReducer(this, cloner);
|
---|
| 50 | }
|
---|
| 51 | public RightChildReducer() : base() { }
|
---|
[817] | 52 | /// <summary>
|
---|
[3404] | 53 | /// Reduces the sub-scopes, so that the selected sub-scope contains all selected leaves
|
---|
| 54 | /// and the remaining sub-scope contains the sub-scopes of the bottom-most remaining scope.
|
---|
[817] | 55 | /// </summary>
|
---|
| 56 | /// <param name="scope">The current scope to reduce.</param>
|
---|
| 57 | /// <returns>A list of the new reduced sub scopes.</returns>
|
---|
[3404] | 58 | protected override List<IScope> Reduce(List<IScope> scopes) {
|
---|
| 59 | IScope rightChild = scopes[scopes.Count - 1];
|
---|
| 60 | IScope leftChild = scopes[0];
|
---|
| 61 | while (leftChild.SubScopes.Count > 1 && leftChild.SubScopes[0].SubScopes.Count > 0) {
|
---|
| 62 | IScope leftRightChild = leftChild.SubScopes[leftChild.SubScopes.Count - 1];
|
---|
[2] | 63 |
|
---|
[3404] | 64 | // merge right children
|
---|
[4489] | 65 | while (leftRightChild.SubScopes.Count > 0) {
|
---|
| 66 | IScope leftRightChildChild = leftRightChild.SubScopes[0];
|
---|
| 67 | leftRightChild.SubScopes.RemoveAt(0);
|
---|
| 68 | rightChild.SubScopes.Add(leftRightChildChild);
|
---|
| 69 | }
|
---|
[2] | 70 |
|
---|
[3404] | 71 | leftChild = leftChild.SubScopes[0];
|
---|
| 72 | }
|
---|
[2] | 73 | List<IScope> subScopes = new List<IScope>();
|
---|
| 74 | subScopes.Add(leftChild);
|
---|
| 75 | subScopes.Add(rightChild);
|
---|
| 76 | return subScopes;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|