Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Evolutionary/3.3/SASEGASAReunificator.cs @ 2567

Last change on this file since 2567 was 1529, checked in by gkronber, 16 years ago

Moved source files of plugins AdvancedOptimizationFrontEnd ... Grid into version-specific sub-folders. #576

File size: 3.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 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;
23using System.Collections.Generic;
24using System.Text;
25using HeuristicLab.Core;
26using HeuristicLab.Data;
27
28namespace HeuristicLab.Evolutionary {
29  /// <summary>
30  /// Joins all sub sub scopes of a specified scope, reduces the number of sub
31  /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order.
32  /// </summary>
33  public class SASEGASAReunificator : OperatorBase {
34    /// <inheritdoc select="summary"/>
35    public override string Description {
36      get { return @"TODO\r\nOperator description still missing ..."; }
37    }
38
39    /// <summary>
40    /// Joins all sub sub scopes of the given <paramref name="scope"/>, reduces the number of sub
41    /// scopes by 1 and uniformly partitions the sub sub scopes again, maintaining the order.
42    /// </summary>
43    /// <exception cref="InvalidOperationException">Thrown when only 0 or 1 sub scope is available.</exception>
44    /// <param name="scope">The current scope whose sub scopes to reduce.</param>
45    /// <returns><c>null</c>.</returns>
46    public override IOperation Apply(IScope scope) {
47      int subScopes = scope.SubScopes.Count;
48      if (subScopes <= 1)
49        throw new InvalidOperationException("SASEGASA reunification requires 2 or more sub-scopes");
50
51      // get all sub-sub-scopes
52      IList<IScope> subSubScopes = new List<IScope>();
53      for (int i = 0; i < scope.SubScopes.Count; i++) {
54        while (scope.SubScopes[i].SubScopes.Count > 0) {
55          subSubScopes.Add(scope.SubScopes[i].SubScopes[0]);
56          scope.SubScopes[i].RemoveSubScope(scope.SubScopes[i].SubScopes[0]);
57        }
58      }
59
60      // reduce number of sub-scopes by 1 and partition sub-sub-scopes again
61      scope.RemoveSubScope(scope.SubScopes[scope.SubScopes.Count - 1]);
62      subScopes--;
63      int subSubScopesCount = subSubScopes.Count / subScopes;
64      for (int i = 0; i < subScopes; i++) {
65        for (int j = 0; j < subSubScopesCount; j++) {
66          scope.SubScopes[i].AddSubScope(subSubScopes[0]);
67          subSubScopes.RemoveAt(0);
68        }
69      }
70
71      // add remaining sub-sub-scopes to last sub-scope
72      while (subSubScopes.Count > 0) {
73        scope.SubScopes[scope.SubScopes.Count - 1].AddSubScope(subSubScopes[0]);
74        subSubScopes.RemoveAt(0);
75      }
76
77      return null;
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.