Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs @ 17764

Last change on this file since 17764 was 17180, checked in by swagner, 5 years ago

#2875: Removed years in copyrights

File size: 3.3 KB
RevLine 
[11583]1#region License Information
2/* HeuristicLab
[17180]3 * Copyright (C) Heuristic and Evolutionary Algorithms Laboratory (HEAL)
[11583]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 HeuristicLab.Common;
23using HeuristicLab.Core;
[12040]24using HeuristicLab.Data;
[11583]25using HeuristicLab.Operators;
[12040]26using HeuristicLab.Parameters;
[16565]27using HEAL.Attic;
[11583]28
29namespace HeuristicLab.Algorithms.ALPS {
[13206]30  [Item("MatingPoolCreator", "An operator which creates mating pools based on a set of sub-populations. For each sub-population, the individuals from the previous sub-population are copied into the current sub-population.")]
[16565]31  [StorableType("F8B8EAF4-84FC-4E38-B3CB-82EEDBAFE083")]
[11583]32  public sealed class MatingPoolCreator : SingleSuccessorOperator {
[13124]33    public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
34      get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
[12040]35    }
36
[11583]37    [StorableConstructor]
[16565]38    private MatingPoolCreator(StorableConstructorFlag _) : base(_) { }
[11583]39    private MatingPoolCreator(MatingPoolCreator original, Cloner cloner)
40      : base(original, cloner) { }
41    public override IDeepCloneable Clone(Cloner cloner) {
42      return new MatingPoolCreator(this, cloner);
43    }
44    public MatingPoolCreator()
45      : base() {
[13206]46      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub-populations used for creating a mating pool. (1 = current + previous sub-population)", new IntValue(1)));
[11583]47    }
48
[13124]49    /// <summary>
[13206]50    /// Copies the subscopes of the n previous scopes into the current scope. (default n = 1)
[13124]51    /// <pre>
52    ///          __ scope __              __ scope __
53    ///         /     |     \            /     |     \
54    ///       Pop1   Pop2   Pop3  =>   Pop1   Pop2   Pop3
[13127]55    ///       /|\    /|\    /|\         /|\   /|\    /|\
56    ///       ABC    DEF    GHI         ABC   DEF    GHI
57    ///                                       ABC    DEF
[13124]58    /// </pre>
59    /// </summary>
60    /// <returns>The next operation.</returns>
[11583]61    public override IOperation Apply() {
[13124]62      var subScopes = ExecutionContext.Scope.SubScopes;
[12040]63      int range = MatingPoolRangeParameter.ActualValue.Value;
[11583]64
[13124]65      for (int targetIndex = subScopes.Count - 1; targetIndex > 0; targetIndex--) {
66        var targetScope = subScopes[targetIndex];
67        for (int n = 1; (n <= range) && (targetIndex - n >= 0); n++) {
68          var prevScope = subScopes[targetIndex - n];
69          var individuals = prevScope.SubScopes;
[12999]70          foreach (var individual in individuals) {
[13128]71            targetScope.SubScopes.Add((IScope)individual.Clone());
[12040]72          }
73        }
[11583]74      }
[11586]75
[11583]76      return base.Apply();
77    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.