[11583] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[12018] | 3 | * Copyright (C) 2002-2015 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 |
|
---|
| 22 | using HeuristicLab.Common;
|
---|
| 23 | using HeuristicLab.Core;
|
---|
[12040] | 24 | using HeuristicLab.Data;
|
---|
[11583] | 25 | using HeuristicLab.Operators;
|
---|
[12040] | 26 | using HeuristicLab.Parameters;
|
---|
[11583] | 27 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
| 28 |
|
---|
| 29 | namespace 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.")]
|
---|
[11583] | 31 | [StorableClass]
|
---|
| 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]
|
---|
| 38 | private MatingPoolCreator(bool deserializing)
|
---|
| 39 | : base(deserializing) { }
|
---|
| 40 | private MatingPoolCreator(MatingPoolCreator original, Cloner cloner)
|
---|
| 41 | : base(original, cloner) { }
|
---|
| 42 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
| 43 | return new MatingPoolCreator(this, cloner);
|
---|
| 44 | }
|
---|
| 45 | public MatingPoolCreator()
|
---|
| 46 | : base() {
|
---|
[13206] | 47 | 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] | 48 | }
|
---|
| 49 |
|
---|
[13124] | 50 | /// <summary>
|
---|
[13206] | 51 | /// Copies the subscopes of the n previous scopes into the current scope. (default n = 1)
|
---|
[13124] | 52 | /// <pre>
|
---|
| 53 | /// __ scope __ __ scope __
|
---|
| 54 | /// / | \ / | \
|
---|
| 55 | /// Pop1 Pop2 Pop3 => Pop1 Pop2 Pop3
|
---|
[13127] | 56 | /// /|\ /|\ /|\ /|\ /|\ /|\
|
---|
| 57 | /// ABC DEF GHI ABC DEF GHI
|
---|
| 58 | /// ABC DEF
|
---|
[13124] | 59 | /// </pre>
|
---|
| 60 | /// </summary>
|
---|
| 61 | /// <returns>The next operation.</returns>
|
---|
[11583] | 62 | public override IOperation Apply() {
|
---|
[13124] | 63 | var subScopes = ExecutionContext.Scope.SubScopes;
|
---|
[12040] | 64 | int range = MatingPoolRangeParameter.ActualValue.Value;
|
---|
[11583] | 65 |
|
---|
[13124] | 66 | for (int targetIndex = subScopes.Count - 1; targetIndex > 0; targetIndex--) {
|
---|
| 67 | var targetScope = subScopes[targetIndex];
|
---|
| 68 | for (int n = 1; (n <= range) && (targetIndex - n >= 0); n++) {
|
---|
| 69 | var prevScope = subScopes[targetIndex - n];
|
---|
| 70 | var individuals = prevScope.SubScopes;
|
---|
[12999] | 71 | foreach (var individual in individuals) {
|
---|
[13128] | 72 | targetScope.SubScopes.Add((IScope)individual.Clone());
|
---|
[12040] | 73 | }
|
---|
| 74 | }
|
---|
[11583] | 75 | }
|
---|
[11586] | 76 |
|
---|
[11583] | 77 | return base.Apply();
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 | } |
---|